From ee4afe711ad523999f336de1c5c122fe317297e8 Mon Sep 17 00:00:00 2001 From: Leo Huang Date: Wed, 20 Nov 2024 15:41:56 -0800 Subject: [PATCH] Update to use helm list and helm uninstall --- .github/workflows/cd-dev.yaml | 63 +++++++++++++++++------------------ 1 file changed, 31 insertions(+), 32 deletions(-) diff --git a/.github/workflows/cd-dev.yaml b/.github/workflows/cd-dev.yaml index 0c6429295..80a781883 100644 --- a/.github/workflows/cd-dev.yaml +++ b/.github/workflows/cd-dev.yaml @@ -37,9 +37,32 @@ jobs: image_tag: ${{ needs.compute-sha.outputs.sha_short }} chart_ver: 0.1.0-dev.${{ needs.compute-sha.outputs.sha_short }} secrets: inherit + + deploy: + name: SSH and Deploy + needs: [compute-sha, build-push] + uses: ./.github/workflows/deploy.yaml + with: + environment: development + 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 limit-deploy: name: SSH and Limit Deployments + needs: [deploy] runs-on: ubuntu-latest steps: - name: SSH and Check Deployments @@ -52,44 +75,20 @@ jobs: set -e # Exit immediately if a command fails # Get bt-dev-app- deployments sorted by creation timestamp - deployments=$(kubectl get deployments \ + deployments=$(helm list -d \ --namespace=bt \ - --sort-by='.metadata.creationTimestamp' \ - -o custom-columns=":metadata.name,:metadata.creationTimestamp" | grep '^bt-dev-app') || true + -o json | jq -r '.[] | [.name, .updated] | @tsv' | grep '^bt-dev-app') || true deployment_count=$(echo "$deployments" | wc -l) - - # Check if deployment count > 16 (2 per deployment) - if [ "$deployment_count" -gt 16 ]; then + + # Check if deployment count > 8 + if [ "$deployment_count" -gt 8 ]; then echo "Too many deployments. Deleting the oldest deployment." # Get oldest deployment from first line of deployments oldest_deployment=$(echo "$deployments" | head -n 1 | grep -o '^bt-dev-app-[a-f0-9]\{7\}') - # Delete deployment - kubectl delete deployment "${oldest_deployment}-frontend" --namespace=bt - kubectl delete deployment "${oldest_deployment}-backend" --namespace=bt + # Uninstall deployment + helm uninstall "${oldest_deployment}" else - echo "Deployment count is <= 16." + echo "Deployment count is <= 8." fi - - deploy: - name: SSH and Deploy - needs: [compute-sha, build-push] - uses: ./.github/workflows/deploy.yaml - with: - environment: development - 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