diff --git a/.github/workflows/cd-dev.yaml b/.github/workflows/cd-dev.yaml index b68d421b3..04249bde5 100644 --- a/.github/workflows/cd-dev.yaml +++ b/.github/workflows/cd-dev.yaml @@ -51,8 +51,13 @@ jobs: username: root key: ${{ secrets.SSH_KEY }} 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 }} ./app --namespace=bt \ --set env=dev \ --set ttl=${{ inputs.ttl }} \ @@ -62,3 +67,7 @@ jobs: --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 \ --set nodeEnv=development + + # 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 diff --git a/.github/workflows/cd-prod.yaml b/.github/workflows/cd-prod.yaml index 19bb245b2..03c61f197 100644 --- a/.github/workflows/cd-prod.yaml +++ b/.github/workflows/cd-prod.yaml @@ -36,11 +36,20 @@ jobs: username: root key: ${{ secrets.SSH_KEY }} script: | + set -e # Exit immediately if a command fails cd ./infra + + # Check if the Helm release exists if helm status bt-prod-app ; then + # Restart deployments if the Helm release exists kubectl rollout restart deployment bt-prod-app-backend kubectl rollout restart deployment bt-prod-app-frontend else + # Install the Helm release if it doesn't exist helm install bt-prod-app ./app --namespace=bt \ --set host=stanfurdtime.com fi + + # Check container status + kubectl rollout status --timeout=180s deployment bt-prod-app-backend + kubectl rollout status --timeout=180s deployment bt-prod-app-frontend diff --git a/.github/workflows/cd-stage.yaml b/.github/workflows/cd-stage.yaml index de5efce44..fc782067b 100644 --- a/.github/workflows/cd-stage.yaml +++ b/.github/workflows/cd-stage.yaml @@ -28,11 +28,16 @@ jobs: username: root key: ${{ secrets.SSH_KEY }} script: | + set -e # Exit immediately if a command fails cd ./infra + + # Check if the Helm release exists if helm status bt-stage-app ; then + # Restart deployments if the Helm release exists kubectl rollout restart deployment bt-stage-app-backend kubectl rollout restart deployment bt-stage-app-frontend else + # Install the Helm release if it doesn't exist helm install bt-stage-app ./app --namespace=bt \ --set env=stage \ --set frontend.image.tag=latest \ @@ -41,3 +46,7 @@ jobs: --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 fi + + # Check container status + kubectl rollout status --timeout=180s deployment bt-stage-app-backend + kubectl rollout status --timeout=180s deployment bt-stage-app-frontend diff --git a/apps/backend/src/bootstrap/index.ts b/apps/backend/src/bootstrap/index.ts index 2113b374a..5cf3e23f7 100644 --- a/apps/backend/src/bootstrap/index.ts +++ b/apps/backend/src/bootstrap/index.ts @@ -7,6 +7,9 @@ import loaders from "./loaders"; export default async (config: Config) => { const app = express(); app.set("trust proxy", 1); + app.get("/healthz", (_, res) => { + res.status(200).send("OK"); + }); await loaders(app); diff --git a/infra/app/templates/backend.yaml b/infra/app/templates/backend.yaml index e2c74cf71..7f0a2c422 100644 --- a/infra/app/templates/backend.yaml +++ b/infra/app/templates/backend.yaml @@ -43,12 +43,22 @@ spec: value: "_" - name: SIS_COURSE_APP_KEY value: "_" + - name: SIS_TERM_APP_ID + value: "_" + - name: SIS_TERM_APP_KEY + value: "_" - name: GOOGLE_CLIENT_ID value: "_" - name: GOOGLE_CLIENT_SECRET value: "_" - name: SESSION_SECRET value: "_" + readinessProbe: + httpGet: + path: /healthz + port: {{ .Values.backend.port }} + initialDelaySeconds: 15 + periodSeconds: 3 --- diff --git a/infra/app/templates/cleanup.yaml b/infra/app/templates/cleanup.yaml index c5f85eba3..ea25b4512 100644 --- a/infra/app/templates/cleanup.yaml +++ b/infra/app/templates/cleanup.yaml @@ -11,6 +11,12 @@ spec: containers: - name: cleanup image: alpine/helm - command: ['sh', '-c', 'sleep $(( {{ .Values.ttl }} * 60 * 60 )); helm uninstall {{ .Release.Name }}'] + command: + - sh + - -c + - | + echo "Cleaning up {{ .Release.Name }} in {{ .Values.ttl }} hours" + sleep {{ .Values.ttl }}h + helm uninstall {{ .Release.Name }} restartPolicy: Never {{ end }} diff --git a/infra/app/templates/frontend.yaml b/infra/app/templates/frontend.yaml index 7c661567c..27263fa80 100644 --- a/infra/app/templates/frontend.yaml +++ b/infra/app/templates/frontend.yaml @@ -20,6 +20,12 @@ spec: imagePullPolicy: Always ports: - containerPort: {{ .Values.frontend.port }} + readinessProbe: + httpGet: + path: / + port: {{ .Values.frontend.port }} + initialDelaySeconds: 15 + periodSeconds: 3 --- diff --git a/infra/app/templates/updater.yaml b/infra/app/templates/updater.yaml index d52bb5280..d3f6149ec 100644 --- a/infra/app/templates/updater.yaml +++ b/infra/app/templates/updater.yaml @@ -43,6 +43,10 @@ spec: value: "_" - name: SIS_COURSE_APP_KEY value: "_" + - name: SIS_TERM_APP_ID + value: "_" + - name: SIS_TERM_APP_KEY + value: "_" - name: GOOGLE_CLIENT_ID value: "_" - name: GOOGLE_CLIENT_SECRET