Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up

Simple Golang and Vue.js SPA demo for deploying to Azure, Docker etc

License

NotificationsYou must be signed in to change notification settings

benc-uk/vuego-demoapp

Repository files navigation

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

  • The Frontend is a SPA written in Vue.js 3. It usesBootstrap 5 andFont Awesome. In additionGauge.js is used for the dials in the monitoring view
  • The Go component is a Go HTTP server based on the std http package and usinggopsutils for monitoring metrics, andGorilla Mux for routing

Features:

  • System status / information view
  • Geolocated weather info (from OpenWeather API)
  • Realtime monitoring and metric view
  • Support for user authentication with Azure AD and MSAL
  • Prometheus metrics
  • API for generating CPU load, and allocating memory

Status

Live instance:

Repo Structure

/├── 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

Server API

The Go server component performs two tasks

  • Serve the Vue.js app to the user. As this is a SPA, this is static content, i.e. HTML, JS & CSS files and any images. Note. The Vue.js app needs to be 'built' before it can be served, this bundles everything up correctly.
  • Provide a simple REST API for data to be displayed & rendered by the Vue.js app. This API is very simple currently has three routes:
    • GET /api/info - Returns system information and various properties as JSON
    • GET /api/monitor - Returns monitoring metrics for CPU, memory, disk and network. This data comes from thegopsutils library
    • GET /api/weather/{lat}/{long} - Returns weather data from OpenWeather API
    • GET /api/gc - Force the garbage collector to run
    • POST /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 service
  • GET /api/health - A health endpoint, returns HTTP 200 when OK
  • GET /api/metrics - Returns low level system and HTTP performance metrics for scraping with Prometheus

Building & Running Locally

Pre-reqs

  • Be using Linux, WSL or MacOS, with bash, make etc
  • Node.jsGo 1.16+ - for running locally, linting, running tests etc
  • cosmtrek/air - if usingmake watch-server
  • Docker - for running as a container, or image build and push
  • Azure CLI - for deployment to Azure

Clone the project to any directory where you do development work

git clone https://github.com/benc-uk/vuego-demoapp.git

Makefile

A standard GNU Make file is provided to help with running and building locally.

help                 💬 This help messagelint                 🔎 Lint & format, will not fix but sets exit code on errorlint-fix             📜 Lint & format, will try to fix errors and modify codeimage                🔨 Build container image from Dockerfilepush                 📤 Push container image to registryrun                  🏃 Run BOTH components locally using Vue CLI and Go server backendwatch-server         👀 Run API server with hot reload file watcher, needs cosmtrek/airwatch-frontend       👀 Run frontend with hot reload file watcherbuild-frontend       🧰 Build and bundle the frontend into distdeploy               🚀 Deploy to Azure Container Appsundeploy             💀 Remove from Azuretest                 🎯 Unit tests for server and frontendtest-report          🎯 Unit tests for server and frontend (with report output)test-snapshot        📷 Update snapshots for frontend teststest-api             🚦  Run integration API tests, server must be runningclean                🧹 Clean up project

Make file variables and default values, pass these in when callingmake, e.g.make image IMAGE_REPO=blah/foo

Makefile VariableDefault
IMAGE_REGghcr.io
IMAGE_REPObenc-uk/vuego-demoapp
IMAGE_TAGlatest
AZURE_RES_GROUPtemp-demoapps
AZURE_REGIONuksouth
  • The server will listen on port 4000 by default, change this by setting the environmental variablePORT
  • The server will ry to serve static content (i.e. bundled frontend) from the same directory as the server binary, change this by setting the environmental variableCONTENT_DIR
  • The frontend will use/api as the API endpoint, when working locallyVUE_APP_API_ENDPOINT is set and overrides this to behttp://localhost:4000/api

Containers

Public container image isavailable 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, usemake image and the above variables to customise the name & tag.

Kubernetes

The app can easily be deployed to Kubernetes using Helm, seedeploy/kubernetes/readme.md for details

Running in Azure App Service (Linux)

If you want to deploy to an Azure Web App as a container (aka Linux Web App), a Bicep template is provided in thedeploy directory

For a super quick deployment, usemake deploy which will deploy to a resource group, temp-demoapps and use the git ref to create a unique site name

make deploy

Config

Environmental variables

  • WEATHER_API_KEY - Enable the weather feature with a OpenWeather API key
  • PORT - 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 feature

Optional User Sign-In Feature

The 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 fromhttps://github.com/benc-uk/msal-graph-vue

If you wish to enable this, carry out the following steps:

  • Register an application with Azure AD,see these steps
  • Set the environmental variableAUTH_CLIENT_ID on the Go server, with the value of the client id. This can be done in the.env file if working locally.
  • Optional when testing/debugging the Vue.js SPA without the Go server, you can place the client-id in.env.development under the valueVUE_APP_AUTH_CLIENT_ID

GitHub Actions CI/CD

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.

Updates

WhenWhat
Nov 2021Rewrite for Vue.js 3, new look & feel, huge refactor
Mar 2021Auth using MSAL.js v2 added
Mar 2021Refresh, makefile, more tests
Nov 2020New pipelines & code/ API robustness
Dec 2019Github Actions and AKS
Sept 2019New release pipelines and config moved to env vars
Sept 2018Updated with weather API and weather view
July 2018Updated Vue CLI config & moved to Golang 1.11
April 2018Project created

[8]ページ先頭

©2009-2025 Movatter.jp