From ff9ec1e6ce240a7ba58a25ebb34c054c51894a4c Mon Sep 17 00:00:00 2001 From: maxmwang Date: Mon, 18 Nov 2024 15:05:00 -0800 Subject: [PATCH] refactor deploy step --- .github/workflows/cd-dev.yaml | 36 +++++++++++++-------------------- .github/workflows/cd-prod.yaml | 19 +++++------------ .github/workflows/cd-stage.yaml | 33 +++++++++++++----------------- .github/workflows/deploy.yaml | 23 ++++++++++++++++++--- 4 files changed, 53 insertions(+), 58 deletions(-) diff --git a/.github/workflows/cd-dev.yaml b/.github/workflows/cd-dev.yaml index 41ae2ac5b..0f5afc70b 100644 --- a/.github/workflows/cd-dev.yaml +++ b/.github/workflows/cd-dev.yaml @@ -44,26 +44,18 @@ jobs: uses: ./.github/workflows/deploy.yaml with: environment: development - script: | - set -e # Exit immediately if a command fails - cd ./infra - - # Uninstall the old helm chart if it exists - helm uninstall bt-dev-app-${{ needs.compute-sha.outputs.sha_short }} || true - - # Install new chart - helm install bt-dev-app-${{ needs.compute-sha.outputs.sha_short }} oci://registry-1.docker.io/octoberkeleytime/bt-app \ - --version=0.1.0-dev.${{ needs.compute-sha.outputs.sha_short }} \ - --namespace=bt \ - --set env=dev \ - --set ttl=${{ inputs.ttl }} \ - --set-string frontend.image.tag=${{ needs.compute-sha.outputs.sha_short }} \ - --set-string backend.image.tag=${{ needs.compute-sha.outputs.sha_short }} \ - --set host=${{ needs.compute-sha.outputs.sha_short }}.dev.stanfurdtime.com \ - --set mongoUri=mongodb://bt-dev-mongo-mongodb.bt.svc.cluster.local:27017/bt \ - --set redisUri=redis://bt-dev-redis-master.bt.svc.cluster.local:6379 \ - - # Check container status - kubectl rollout status --timeout=180s deployment bt-dev-app-${{ needs.compute-sha.outputs.sha_short }}-backend - kubectl rollout status --timeout=180s deployment bt-dev-app-${{ needs.compute-sha.outputs.sha_short }}-frontend + name: bt-dev-app-${{ needs.compute-sha.outputs.sha_short }} + version: 0.1.0-dev.${{ needs.compute-sha.outputs.sha_short }} + values: | + env: dev + ttl: ${{ inputs.ttl }} + frontend: + image: + tag: ${{ needs.compute-sha.outputs.sha_short }} + backend: + image: + tag: ${{ needs.compute-sha.outputs.sha_short }} + host: ${{ needs.compute-sha.outputs.sha_short }}.dev.stanfurdtime.com + mongoUri: mongodb://bt-dev-mongo-mongodb.bt.svc.cluster.local:27017/bt + redisUri: redis://bt-dev-redis-master.bt.svc.cluster.local:6379 secrets: inherit diff --git a/.github/workflows/cd-prod.yaml b/.github/workflows/cd-prod.yaml index 10a893ae8..eeb8a3ea5 100644 --- a/.github/workflows/cd-prod.yaml +++ b/.github/workflows/cd-prod.yaml @@ -30,17 +30,8 @@ jobs: uses: ./.github/workflows/deploy.yaml with: environment: production - script: | - set -e # Exit immediately if a command fails - cd ./infra - - # Upgrade helm chart, or install if not exists - helm upgrade bt-prod-app oci://registry-1.docker.io/octoberkeleytime/bt-app \ - --install \ - --version="1.0.0" \ - --namespace=bt \ - --set host=stanfurdtime.com - - # Check container status - kubectl rollout status --timeout=180s deployment bt-prod-app-backend - kubectl rollout status --timeout=180s deployment bt-prod-app-frontend + name: bt-prod-app + version: "1.0.0" + values: | + host: stanfurdtime.com + secrets: inherit diff --git a/.github/workflows/cd-stage.yaml b/.github/workflows/cd-stage.yaml index 8751eea04..63ab1762e 100644 --- a/.github/workflows/cd-stage.yaml +++ b/.github/workflows/cd-stage.yaml @@ -21,22 +21,17 @@ jobs: uses: ./.github/workflows/deploy.yaml with: environment: staging - script: | - set -e # Exit immediately if a command fails - cd ./infra - - # Upgrade helm chart, or install if not exists - helm upgrade bt-stage-app oci://registry-1.docker.io/octoberkeleytime/bt-app \ - --install \ - --version=0.1.0-stage \ - --namespace=bt \ - --set env=stage \ - --set frontend.image.tag=latest \ - --set backend.image.tag=latest \ - --set host=staging.stanfurdtime.com \ - --set mongoUri=mongodb://bt-stage-mongo-mongodb.bt.svc.cluster.local:27017/bt \ - --set redisUri=redis://bt-stage-redis-master.bt.svc.cluster.local:6379 - - # Check container status - kubectl rollout status --timeout=180s deployment bt-stage-app-backend - kubectl rollout status --timeout=180s deployment bt-stage-app-frontend + name: bt-stage-app + version: 0.1.0-stage + values: | + env: stage + frontend: + image: + tag: latest + backend: + image: + tag: latest + host: staging.stanfurdtime.com + mongoUri: mongodb://bt-stage-mongo-mongodb.bt.svc.cluster.local:27017/bt + redisUri: redis://bt-stage-redis-master.bt.svc.cluster.local:6379 + secrets: inherit diff --git a/.github/workflows/deploy.yaml b/.github/workflows/deploy.yaml index 97852ecf6..d817fdf33 100644 --- a/.github/workflows/deploy.yaml +++ b/.github/workflows/deploy.yaml @@ -7,8 +7,16 @@ on: description: "Github action environment to deploy within" required: true type: string - script: - description: "Script to run on remote server" + name: + description: "Helm chart installation name" + required: true + type: string + version: + description: "Helm chart version" + required: true + type: string + values: + description: "Helm chart override values (yaml)" required: true type: string @@ -28,4 +36,13 @@ jobs: script: | set -e # Exit immediately if a command fails - ${{ inputs.script }} + # Upgrade helm chart, or install if not exists + helm upgrade ${{ inputs.name }} oci://registry-1.docker.io/octoberkeleytime/bt-app \ + --install \ + --version=${{ inputs.version }} \ + --namespace=bt \ + --values <(echo "${{ inputs.values }}") + + # Check container status + kubectl rollout status --timeout=180s deployment ${{ inputs.name }}-backend + kubectl rollout status --timeout=180s deployment ${{ inputs.name }}-frontend