Skip to content

Latest commit

Β 

History

History
94 lines (64 loc) Β· 3.16 KB

File metadata and controls

94 lines (64 loc) Β· 3.16 KB

Vue Frontend with GCP Image Build & Deployment

This repository contains a frontend application built with Vue.js. It includes a GitHub Actions workflow that builds a Docker image and automatically deploys it to a Google Kubernetes Engine (GKE) cluster whenever there is a push to the main branch, which is protected to prevent direct commits and enforce pull requests.


πŸš€ CI/CD Workflow

The .github/workflows/build.yml file defines a GitHub Action that performs the following steps:

  1. Checkout the code: Retrieves the source code from the main branch.
  2. Authenticate with GCP: Uses a service account (GCP_SA_CREDENTIALS) to authenticate with Google Cloud.
  3. Set up GCP SDK: Installs and configures the gcloud CLI.
  4. Configure Docker with Artifact Registry: Allows Docker to push images to GCP’s container registry.
  5. Get GKE credentials: Connects to the GKE cluster to run kubectl commands.
  6. Set image tag: Generates a unique image tag per commit using the branch name and timestamp.
  7. Build Docker image: Builds and tags the Docker image with both the generated tag and latest.
  8. Push the image: Pushes both latest and timestamped tags to GCP's Artifact Registry.
  9. Update deployment on GKE: If a deployment named frontend exists, it updates the container image for frontend-container.

πŸ“ Project Structure

.
β”œβ”€β”€ src/                 # Frontend source code (Vue.js)
β”œβ”€β”€ build/               # Webpack config and build utilities
β”œβ”€β”€ config/              # Environment configurations (dev/prod)
β”œβ”€β”€ Dockerfile           # Docker image used in the pipeline
└── .github/workflows/   # GitHub Actions workflows

πŸ› οΈ Requirements

To make the workflow run successfully, you need to set up the following in your GitHub repository:

πŸ” Secrets

  • GCP_SA_CREDENTIALS: JSON with credentials for a service account that has permissions for:
    • Artifact Registry
    • GKE (get-credentials and set image)
  • GCP_PROJECT: Google Cloud project ID
  • GKE_CLUSTER: Name of your GKE cluster

βš™οΈ Variables

  • GCP_ZONE: Zone where the cluster is located (e.g. us-central1)
  • REGISTRY: Artifact Registry repository name (e.g. my-registry)
  • IMAGE_NAME: Name of the image to be built (e.g. frontend)

🐳 Docker

This project includes a Dockerfile that packages the Vue.js app for production. Make sure the Dockerfile is properly configured for your production environment.


πŸ–₯️ Local Development

UI for sample distributed TODO application.

Configuration

  • PORT - a port the application binds to
  • AUTH_API_ADDRESS - address of auth-api for authentication
  • TODOS_API_ADDRESS - address of todos-api for TODO CRUD

Building

# install dependencies
npm install

# build application
npm run build

Running

PORT=8080 AUTH_API_ADDRESS=http://127.0.0.1:8000 TODOS_API_ADDRESS=http://127.0.0.1:8082 npm start

Dependencies

Here you can find the software required to run this microservice, as well as the version we have tested.

Dependency Version
Node 8.17.0
NPM 6.13.4