Skip to content

Create google.yml

Create google.yml #1

Workflow file for this run

# This workflow will build a docker container, publish it to Google Container Registry, and deploy it to GKE when there is a push to the "master" branch.
#
# To configure this workflow:
#
# 1. Ensure that your repository contains the necessary configuration for your Google Kubernetes Engine cluster, including deployment.yml, kustomization.yml, service.yml, etc.
#
# 2. Create and configure a Workload Identity Provider for GitHub (https://github.com/google-github-actions/auth#setting-up-workload-identity-federation)
#
# 3. Change the values for the GAR_LOCATION, GKE_ZONE, GKE_CLUSTER, IMAGE, REPOSITORY and DEPLOYMENT_NAME environment variables (below).
#
# For more support on how to run the workflow, please visit https://github.com/google-github-actions/setup-gcloud/tree/master/example-workflows/gke-kustomize
name: Build and Deploy to GKE
on:
push:
branches: [ "master" ]
env:
PROJECT_ID: ${{ secrets.GKE_PROJECT }}
GAR_LOCATION: europe-west1 # TODO: update region of the Artifact Registry
GKE_CLUSTER: multi-cluster # TODO: update to cluster name
GKE_ZONE: europe-west1-d # TODO: update to cluster zone
jobs:
setup-build-publish-deploy:
name: Setup, Build, Publish, and Deploy
runs-on: ubuntu-latest
environment: production
permissions:
contents: 'read'
id-token: 'write'
steps:
- name: Docker configuration
run: |-
docker login -u ${{ secrets.DOCKER_USERNAME }} -p ${{ secrets.DOCKER_PASSWORD }}
docker build -t cklat/react-test -f ./client/Dockerfile.dev ./client
docker run -e CI=true cklat/react-test npm test
- name: Checkout
uses: actions/checkout@v3
# Alternative option - authentication via credentials json
- id: 'auth'
uses: 'google-github-actions/auth@v0'
with:
credentials_json: '${{ secrets.GCP_CREDENTIALS }}'
# Get the GKE credentials so we can deploy to the cluster
- name: Set up GKE credentials
uses: google-github-actions/get-gke-credentials@v0
with:
cluster_name: ${{ env.GKE_CLUSTER }}
location: ${{ env.GKE_ZONE }}
# Build the Docker image
- name: Build
run: |-
docker build \
-t cklat/multi-client-k8s:latest\
-t cklat/multi-client-k8s:$GITHUB_SHA\
-f ./client/Dockerfile ./client
docker build \
-t cklat/multi-server-k8s:latest\
-t cklat/multi-server-k8s:$GITHUB_SHA\
-f ./server/Dockerfile ./server
docker build \
-t cklat/multi-worker-k8s:latest\
-t cklat/multi-worker-k8s:$GITHUB_SHA\
-f ./worker/Dockerfile ./worker
# Push the Docker image to Google Artifact Registry
- name: Publish
run: |-
docker push cklat/multi-client-k8s:latest
docker push cklat/multi-server-k8s:latest
docker push cklat/multi-worker-k8s:latest
docker push cklat/multi-client-k8s:$GITHUB_SHA
docker push cklat/multi-server-k8s:$GITHUB_SHA
docker push cklat/multi-worker-k8s:$GITHUB_SHA
# Deploy the Docker image to the GKE cluster
- name: Deploy
run: |-
kubectl apply -f k8s
kubectl set image deployments/server-deployment server=cklat/multi-server-k8s:$GITHUB_SHA
kubectl set image deployments/client-deployment client=cklat/multi-client-k8s:$GITHUB_SHA
kubectl set image deployments/worker-deployment worker=cklat/multi-worker-k8s:$GITHUB_SHA