Skip to content

Merge pull request #122 from CS3219-AY2324S1/readme-update #83

Merge pull request #122 from CS3219-AY2324S1/readme-update

Merge pull request #122 from CS3219-AY2324S1/readme-update #83

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: moonlit-order-400013
GAR_LOCATION: us-central1 # TODO: update region of the Artifact Registry
GKE_CLUSTER: microservices # TODO: update to cluster name
GKE_ZONE: us-central1 # TODO: update to cluster zone
DEPLOYMENT_NAME: gke-test # TODO: update to deployment name
REPOSITORY: leetcode-racing # TODO: update to Artifact Registry docker repository
IMAGE: static-site
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: Checkout
uses: actions/checkout@v3
# Configure Workload Identity Federation and generate an access token.
- id: 'auth'
name: 'Authenticate to Google Cloud'
uses: 'google-github-actions/auth@v0'
with:
token_format: 'access_token'
workload_identity_provider: 'projects/660356048486/locations/global/workloadIdentityPools/my-pool/providers/my-provider'
service_account: '[email protected]'
project_id: 'moonlit-order-400013'
# Alternative option - authentication via credentials json
# - id: 'auth'
# uses: 'google-github-actions/auth@v0'
# with:
# credentials_json: '${{ secrets.GCP_CREDENTIALS }}'
- name: Docker configuration
run: |-
echo ${{steps.auth.outputs.access_token}} | docker login -u oauth2accesstoken --password-stdin https://$GAR_LOCATION-docker.pkg.dev
# 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 }}
- name: Build and Push Docker Images
run: |
microservices=("")
for service in "${microservices[@]}"
do
echo "Building image for $service"
docker build -t "$GAR_LOCATION-docker.pkg.dev/$PROJECT_ID/$REPOSITORY/$service:$GITHUB_SHA" $service/
echo "Pushing image for $service"
docker push "$GAR_LOCATION-docker.pkg.dev/$PROJECT_ID/$REPOSITORY/$service:$GITHUB_SHA"
done
shell: bash
# Deploy the Docker image to the GKE cluster
# eval-service has issues
# "collaboration-service" "editor-service" "history-service" "question-service"
- name: Deploy
run: |
# microservices=("")
# for service in "${microservices[@]}"
# do
# echo "Deploying $service"
# # Set the image repository and tag in the values file
# helm upgrade --install $service ./$service/k8 \
# --set image.repository="$GAR_LOCATION-docker.pkg.dev/$PROJECT_ID/$REPOSITORY/$service" \
# --set image.tag="$GITHUB_SHA" \
# --values ./$service/k8/$service-values.yaml \
# --wait
# # Check the rollout status
# kubectl rollout status deployment/$service-deployment
# # List the services
# kubectl get services -o wide
# done
# echo "Deploying frontend-service"
# helm upgrade --install frontend ./frontend/k8 \
# --set image.repository="$GAR_LOCATION-docker.pkg.dev/$PROJECT_ID/$REPOSITORY/frontend" \
# --set image.tag="$GITHUB_SHA" \
# --values ./frontend/k8/frontend-values.yaml \
# --wait
# kubectl rollout status deployment/frontend-service-deployment
# kubectl get services -o wide
shell: bash
# ./kustomize edit set image "$service=$GAR_LOCATION-docker.pkg.dev/$PROJECT_ID/$REPOSITORY/$service:$GITHUB_SHA"
# ./kustomize build "./overlays/$service" | kubectl apply -f -