2023-04-17 06:09:33 +00:00
|
|
|
#!/bin/bash
|
|
|
|
|
# Configure the AWS & kubectl environment
|
|
|
|
|
|
2025-06-26 05:34:15 +00:00
|
|
|
mkdir -p ~/.aws
|
|
|
|
|
cat > ~/.aws/config <<EOF
|
|
|
|
|
[default]
|
|
|
|
|
region = ap-south-1
|
2023-09-11 10:54:17 +00:00
|
|
|
output = json
|
2025-06-26 05:34:15 +00:00
|
|
|
EOF
|
|
|
|
|
|
|
|
|
|
aws configure set aws_access_key_id "$AWS_ACCESS_KEY_ID"
|
|
|
|
|
aws configure set aws_secret_access_key "$AWS_SECRET_ACCESS_KEY"
|
2023-04-17 06:09:33 +00:00
|
|
|
|
2025-06-26 05:34:15 +00:00
|
|
|
export region="ap-south-1"
|
|
|
|
|
export cluster_name="uatx-cluster"
|
2023-04-17 06:09:33 +00:00
|
|
|
|
2025-06-26 05:34:15 +00:00
|
|
|
# Update kubeconfig
|
|
|
|
|
aws eks update-kubeconfig --region "$region" --name "$cluster_name"
|
2023-04-17 06:09:33 +00:00
|
|
|
|
|
|
|
|
echo "Set the default namespace"
|
|
|
|
|
kubectl config set-context --current --namespace=default
|
|
|
|
|
|
|
|
|
|
echo "Getting the pods"
|
|
|
|
|
kubectl get pods
|
|
|
|
|
|
|
|
|
|
### Get list of helm charts
|
|
|
|
|
deployed_charts="$(helm ls -A --filter 'ce[0-9]+' --output json | jq -r '.[].namespace')"
|
|
|
|
|
|
|
|
|
|
for i in $deployed_charts
|
|
|
|
|
do
|
|
|
|
|
pr=$(echo $i | cut -c 3-);
|
|
|
|
|
pr_state="$(gh pr view "$pr" --json state --jq .state)"
|
|
|
|
|
echo $pr_state
|
2023-05-05 08:21:25 +00:00
|
|
|
if [[ $pr_state == "MERGED" || $pr_state == "CLOSED" ]]
|
2023-04-17 06:09:33 +00:00
|
|
|
then
|
2023-04-17 10:15:52 +00:00
|
|
|
mongosh "mongodb+srv://$DB_USERNAME:$DB_PASSWORD@$DB_URL/$i?retryWrites=true&minPoolSize=1&maxPoolSize=10&maxIdleTimeMS=900000&authSource=admin" --eval 'db.dropDatabase()'
|
2023-09-11 10:54:17 +00:00
|
|
|
pod_name=$(kubectl get pods -n $i -o json | jq '.items[0].metadata.name' | tr -d '"')
|
|
|
|
|
kubectl exec $pod_name -n $i -- bash -c "rm -rf /appsmith-stacks/*"
|
2023-09-11 11:07:27 +00:00
|
|
|
helm uninstall $i -n $i
|
2023-09-11 10:54:17 +00:00
|
|
|
kubectl delete ns $i || true
|
|
|
|
|
kubectl patch pv $i-appsmith -p '{"metadata":{"finalizers":null}}' || true
|
|
|
|
|
kubectl delete pv $i-appsmith --grace-period=0 --force || true
|
2023-04-17 06:09:33 +00:00
|
|
|
fi
|
|
|
|
|
done
|