Simple Golang and Vue.js SPA demo for deploying to Azure, Docker etc
This is a simple web application with a Go server/backend and a Vue.js SPA (Single Page Application) frontend.
The app has been designed with cloud native demos & containers in mind, in order to provide a real working application for deployment, something more than "hello-world" but with the minimum of pre-reqs. It is not intended as a complete example of a fully functioning architecture or complex software design.
Typical uses would be deployment to Kubernetes, demos of Docker, CI/CD (build pipelines are provided), deployment to cloud (Azure) monitoring, auto-scaling
Features:
Live instance:
/
├── frontend Root of the Vue.js project
│ └── src Vue.js source code
│ └── tests Unit tests
├── deploy Supporting files for Azure deployment etc
│ └── kubernetes Instructions for Kubernetes deployment with Helm
├── server Go backend server
│ └── cmd Server main / exec
│ └── pkg Supporting packages
├── build Supporting build scripts and Dockerfile
└── test API / integration tests
The Go server component performs two tasks
GET /api/info
- Returns system information and various properties as JSONGET /api/monitor
- Returns monitoring metrics for CPU, memory, disk and network. This data comes from the gopsutils libraryGET /api/weather/{lat}/{long}
- Returns weather data from OpenWeather APIGET /api/gc
- Force the garbage collector to runPOST /api/alloc
- Allocate a lump of memory, payload {"size":int}
POST /api/cpu
- Force CPU load, payload {"seconds":int}
In addition to these application specific endpoints, the following REST operations are supported:
GET /api/status
- Status and information about the serviceGET /api/health
- A health endpoint, returns HTTP 200 when OKGET /api/metrics
- Returns low level system and HTTP performance metrics for scraping with Prometheusmake watch-server
Clone the project to any directory where you do development work
git clone https://github.com/benc-uk/vuego-demoapp.git
A standard GNU Make file is provided to help with running and building locally.
help 💬 This help message
lint 🔎 Lint & format, will not fix but sets exit code on error
lint-fix 📜 Lint & format, will try to fix errors and modify code
image 🔨 Build container image from Dockerfile
push 📤 Push container image to registry
run 🏃 Run BOTH components locally using Vue CLI and Go server backend
watch-server 👀 Run API server with hot reload file watcher, needs cosmtrek/air
watch-frontend 👀 Run frontend with hot reload file watcher
build-frontend 🧰 Build and bundle the frontend into dist
deploy 🚀 Deploy to Azure Container Apps
undeploy 💀 Remove from Azure
test 🎯 Unit tests for server and frontend
test-report 🎯 Unit tests for server and frontend (with report output)
test-snapshot 📷 Update snapshots for frontend tests
test-api 🚦 Run integration API tests, server must be running
clean 🧹 Clean up project
Make file variables and default values, pass these in when calling make
, e.g. make image IMAGE_REPO=blah/foo
Makefile Variable | Default |
---|---|
IMAGE_REG | ghcr.io |
IMAGE_REPO | benc-uk/vuego-demoapp |
IMAGE_TAG | latest |
AZURE_RES_GROUP | temp-demoapps |
AZURE_REGION | uksouth |
PORT
CONTENT_DIR
/api
as the API endpoint, when working locally VUE_APP_API_ENDPOINT
is set and overrides this to be http://localhost:4000/api
Public container image is available on GitHub Container Registry
Run in a container with:
docker run --rm -it -p 4000:4000 ghcr.io/benc-uk/vuego-demoapp:latest
Should you want to build your own container, use make image
and the above variables to customise the name & tag.
The app can easily be deployed to Kubernetes using Helm, see deploy/kubernetes/readme.md for details
If you want to deploy to an Azure Web App as a container (aka Linux Web App), a Bicep template is provided in the deploy directory
For a super quick deployment, use make deploy
which will deploy to a resource group, temp-demoapps and use the git ref to create a unique site name
make deploy
Environmental variables
WEATHER_API_KEY
- Enable the weather feature with a OpenWeather API keyPORT
- Port to listen on (default: 4000
)CONTENT_DIR
- Directory to serve static content from (default: .
)AUTH_CLIENT_ID
- Set to a Azure AD registered app if you wish to enable the optional user sign-in featureThe application can be configured with an optional user sign-in feature which uses Azure Active Directory as an identity platform. This uses wrapper & helper libraries from https://github.com/benc-uk/msal-graph-vue
If you wish to enable this, carry out the following steps:
AUTH_CLIENT_ID
on the Go server, with the value of the client id. This can be done in the .env
file if working locally..env.development
under the value VUE_APP_AUTH_CLIENT_ID
A set of GitHub Actions workflows are included for CI / CD. Automated builds for PRs are run in GitHub hosted runners validating the code (linting and tests) and building dev images. When code is merged into master, then automated deployment to AKS is done using Helm.
When | What |
---|---|
Nov 2021 | Rewrite for Vue.js 3, new look & feel, huge refactor |
Mar 2021 | Auth using MSAL.js v2 added |
Mar 2021 | Refresh, makefile, more tests |
Nov 2020 | New pipelines & code/ API robustness |
Dec 2019 | Github Actions and AKS |
Sept 2019 | New release pipelines and config moved to env vars |
Sept 2018 | Updated with weather API and weather view |
July 2018 | Updated Vue CLI config & moved to Golang 1.11 |
April 2018 | Project created |