Update README.md #6
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# .github/workflows/cd-workflow.yaml | |
name: GKE Deployment Workflow | |
on: | |
workflow_call: | |
inputs: | |
# GKE_CLUSTER: | |
# description: 'GKE Cluster Name' | |
# type: string | |
# required: true | |
# GKE_REGION: | |
# description: 'GKE Region' | |
# type: string | |
# required: true | |
# IMAGE_TAG: | |
# description: 'Image Tag' | |
# type: string | |
# required: true | |
# GITHUB_SHA: | |
# description: 'Github SHA' | |
# type: string | |
# required: true | |
ENV: | |
description: 'Environment' | |
type: string | |
required: true | |
# GKE_NAMESPACE: | |
# description: 'GKE Namespace' | |
# type: string | |
# required: true | |
# REPO_NAME: | |
# description: 'Repository Name' | |
# type: string | |
# required: true | |
# SERVICE_NAME: | |
# description: 'K8s service name for the repository' | |
# type: string | |
# required: true | |
jobs: | |
deploy: | |
runs-on: ubuntu-latest | |
environment: | |
name: ${{ github.event.inputs.ENV }} | |
steps: | |
- name: "Echo all the variables" | |
uses: echo "${{ github.event.inputs.ENV }} ${{ vars.GKE_CLUSTER }}" | |
- name: "Set up Cloud SDK" | |
uses: "google-github-actions/setup-gcloud@v2" | |
- name: "Use gcloud CLI" | |
run: 'gcloud auth list --filter=status:ACTIVE --format="value(account)"' | |
- name: "Info Google cloud" | |
run: "gcloud info" | |
- name: Install the kubectl and GCP plugin for GKE | |
run: gcloud components install kubectl gke-gcloud-auth-plugin | |
- name: Check the config kubectl | |
run: kubectl config view | |
- name: Setup the GKE Cluster Credentials | |
uses: google-github-actions/get-gke-credentials@v2 | |
with: | |
cluster_name: ${{ vars.GKE_CLUSTER }} | |
location: ${{ vars.GKE_REGION }} | |
- name: Replace service image for the env in Deployment YAML | |
run: | | |
sed -i "s, APP_IMAGE, ${{ vars.GCR_HOSTNAME }}/${{ vars.GCR_PROJECT_ID }}/${{ vars.GAR_REPO }}/${{ vars.SERVICE_IMAGE_NAME}}:"$GITHUB_SHA"," k8s/deployments/${{ vars.ENV }}.deployment.yml | |
- name: Apply configmaps | |
run: kubectl apply -f k8s/configs/${{ vars.ENV }}.configmap.yml --namespace ${{ vars.GKE_NAMESPACE }} | |
- name: Apply deployment | |
run: kubectl apply -f k8s/deployments/${{ vars.ENV }}.deployment.yml --namespace ${{ vars.GKE_NAMESPACE }} | |
- name: Apply Service | |
run: kubectl apply -f k8s/service/${{ vars.ENV }}.service.yml --namespace ${{ vars.GKE_NAMESPACE }} | |
- name: Apply Horizontal pod scalar | |
run: kubectl apply -f k8s/hpa/${{ vars.ENV }}.hpa.yml --namespace ${{ vars.GKE_NAMESPACE }} | |
- name: Check if deployments are stable | |
run: | | |
while [[ "$(kubectl get pods --namespace ${{ vars.GKE_NAMESPACE }} | tail -n +2 | awk '{print $3}' | grep -v 'Running\|Completed\|Terminating' | wc -l)" -gt 0 ]]; do | |
echo "Waiting for pods to stabilize..." | |
sleep 10 | |
done | |
- name: Check if the deployment is stable | |
run: kubectl rollout status deployment ${{ vars.SERVICE_NAME }} | |
- name: Deployment Message | |
run: echo "Deployment successful" |