Skip to content

Merge pull request #41 from xenosf/test-cases #13

Merge pull request #41 from xenosf/test-cases

Merge pull request #41 from xenosf/test-cases #13

name: Build and Deploy question-service to GKE
on:
push:
branches:
- main
paths:
- server/question-service/**
workflow_dispatch:
env:
PROJECT_ID: ${{ secrets.GKE_PROJECT }}
GKE_CLUSTER: peerprep-cluster-1
GKE_ZONE: asia-southeast1
REPOSITORY_NAME: peerprep
K8_DIR: qn-service
SERVICE: question-service
IMAGE: questions
jobs:
setup-build-publish-deploy:
name: Setup, Build, Publish, and Deploy
runs-on: ubuntu-latest
environment: production
steps:
- name: Checkout
uses: actions/checkout@v4
- id: 'auth'
name: 'Authenticate to Google Cloud'
uses: 'google-github-actions/auth@v2'
with:
credentials_json: ${{ secrets.GKE_SA_KEY }}
# Setup gcloud CLI
- uses: google-github-actions/setup-gcloud@1bee7de035d65ec5da40a31f8589e240eba8fde5
with:
project_id: ${{ env.PROJECT_ID }}
# Configure Docker to use the gcloud command-line tool as a credential
# helper for authentication
- run: |-
gcloud auth configure-docker ${GKE_ZONE}-docker.pkg.dev --quiet
# Get the GKE credentials so we can deploy to the cluster
- uses: google-github-actions/get-gke-credentials@db150f2cc60d1716e61922b832eae71d2a45938f
with:
cluster_name: ${{ env.GKE_CLUSTER }}
location: ${{ env.GKE_ZONE }}
project_id: ${{ env.PROJECT_ID }}
# Build the Docker image
- name: 'Build and push Docker container'
run: |-
DOCKER_TAG="${GKE_ZONE}-docker.pkg.dev/${PROJECT_ID}/${REPOSITORY_NAME}/${IMAGE}:${GITHUB_SHA}"
DOCKER_TAG_LATEST="${GKE_ZONE}-docker.pkg.dev/${PROJECT_ID}/${REPOSITORY_NAME}/${IMAGE}:latest"
docker build \
--tag "${DOCKER_TAG}" \
--tag "${DOCKER_TAG_LATEST}" \
--build-arg GITHUB_SHA="${GITHUB_SHA}" \
--build-arg GITHUB_REF="${GITHUB_REF}" \
./server/${SERVICE}
docker push "${DOCKER_TAG}"
docker push "${DOCKER_TAG_LATEST}"
# Deploy the Docker image to the GKE cluster
- name: Deploy
run: |-
kubectl apply -f kubernetes/${K8_DIR}
kubectl rollout status deployment/${K8_DIR}
kubectl get services -o wide