Skip to content

Commit

Permalink
Update to use helm list and helm uninstall
Browse files Browse the repository at this point in the history
  • Loading branch information
klhftco authored Nov 20, 2024
1 parent 82ec4e6 commit ee4afe7
Showing 1 changed file with 31 additions and 32 deletions.
63 changes: 31 additions & 32 deletions .github/workflows/cd-dev.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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

0 comments on commit ee4afe7

Please sign in to comment.