mirror of
https://github.com/spring-projects/spring-petclinic.git
synced 2025-07-18 05:45:50 +00:00
Add ECR repository name output for debugging
This commit is contained in:
parent
70813745f8
commit
082f461e5d
1 changed files with 98 additions and 88 deletions
38
.github/workflows/cleanup.yml
vendored
38
.github/workflows/cleanup.yml
vendored
|
@ -1,7 +1,6 @@
|
||||||
---
|
name: Cleanup AWS Resources
|
||||||
name: Cleanup AWS Resources
|
|
||||||
|
|
||||||
on:
|
on:
|
||||||
workflow_dispatch:
|
workflow_dispatch:
|
||||||
inputs:
|
inputs:
|
||||||
environment:
|
environment:
|
||||||
|
@ -16,27 +15,31 @@
|
||||||
confirm:
|
confirm:
|
||||||
description: 'Type "delete" to confirm deletion'
|
description: 'Type "delete" to confirm deletion'
|
||||||
required: true
|
required: true
|
||||||
|
|
||||||
push:
|
push:
|
||||||
branches:
|
branches:
|
||||||
- dev
|
- dev
|
||||||
|
|
||||||
jobs:
|
jobs:
|
||||||
cleanup:
|
cleanup:
|
||||||
runs-on: ubuntu-latest
|
runs-on: ubuntu-latest
|
||||||
if: github.event.inputs.confirm == 'delete'
|
if: github.event_name == 'workflow_dispatch' && github.event.inputs.confirm == 'delete' || github.event_name == 'push'
|
||||||
steps:
|
steps:
|
||||||
- uses: actions/checkout@v3
|
- uses: actions/checkout@v3
|
||||||
|
|
||||||
- name: Set environment name
|
- name: Set environment name
|
||||||
run: echo "ENV_NAME=${{ github.event.inputs.environment || 'dev' }}" >> $GITHUB_ENV
|
run: |
|
||||||
|
if [ "${{ github.event_name }}" = "workflow_dispatch" ]; then
|
||||||
|
echo "ENV_NAME=${{ github.event.inputs.environment }}" >> $GITHUB_ENV
|
||||||
|
else
|
||||||
|
echo "ENV_NAME=dev" >> $GITHUB_ENV
|
||||||
|
fi
|
||||||
|
|
||||||
- name: Configure AWS credentials
|
- name: Configure AWS credentials
|
||||||
uses: aws-actions/configure-aws-credentials@v1
|
uses: aws-actions/configure-aws-credentials@v1
|
||||||
with:
|
with:
|
||||||
aws-access-key-id: ${{ secrets.AWS_ACCESS_KEY_ID }}
|
aws-access-key-id: ${{ secrets.AWS_ACCESS_KEY_ID }}
|
||||||
aws-secret-access-key: ${{ secrets.AWS_SECRET_ACCESS_KEY }}
|
aws-secret-access-key: ${{ secrets.AWS_SECRET_ACCESS_KEY }}
|
||||||
aws-region: us-east-1
|
aws-region: us-west-2
|
||||||
|
|
||||||
- name: Setup Terraform
|
- name: Setup Terraform
|
||||||
uses: hashicorp/setup-terraform@v2
|
uses: hashicorp/setup-terraform@v2
|
||||||
|
@ -74,6 +77,14 @@
|
||||||
aws ecs delete-cluster --cluster petclinic-${{ env.ENV_NAME }}
|
aws ecs delete-cluster --cluster petclinic-${{ env.ENV_NAME }}
|
||||||
fi
|
fi
|
||||||
|
|
||||||
|
# Clean up Security Groups
|
||||||
|
SG_NAME="petclinic-${{ env.ENV_NAME }}-tasks-sg"
|
||||||
|
SG_ID=$(aws ec2 describe-security-groups --filters "Name=group-name,Values=$SG_NAME" --query "SecurityGroups[0].GroupId" --output text)
|
||||||
|
if [[ "$SG_ID" != "None" && "$SG_ID" != "" ]]; then
|
||||||
|
echo "Cleaning up security group $SG_NAME ($SG_ID)..."
|
||||||
|
aws ec2 delete-security-group --group-id $SG_ID
|
||||||
|
fi
|
||||||
|
|
||||||
# Clean up S3 bucket if it exists
|
# Clean up S3 bucket if it exists
|
||||||
BUCKET_NAME="petclinic-${{ env.ENV_NAME }}-artifacts"
|
BUCKET_NAME="petclinic-${{ env.ENV_NAME }}-artifacts"
|
||||||
if aws s3api head-bucket --bucket $BUCKET_NAME 2>/dev/null; then
|
if aws s3api head-bucket --bucket $BUCKET_NAME 2>/dev/null; then
|
||||||
|
@ -82,10 +93,9 @@
|
||||||
aws s3api delete-bucket --bucket $BUCKET_NAME
|
aws s3api delete-bucket --bucket $BUCKET_NAME
|
||||||
fi
|
fi
|
||||||
|
|
||||||
# Clean up Security Groups
|
# Clean up RDS instance if it exists
|
||||||
SG_NAME="petclinic-${{ env.ENV_NAME }}-tasks-sg"
|
DB_IDENTIFIER="petclinic-${{ env.ENV_NAME }}db"
|
||||||
SG_ID=$(aws ec2 describe-security-groups --filters "Name=group-name,Values=$SG_NAME" --query "SecurityGroups[0].GroupId" --output text)
|
if aws rds describe-db-instances --db-instance-identifier $DB_IDENTIFIER 2>/dev/null; then
|
||||||
if [[ "$SG_ID" != "None" && "$SG_ID" != "" ]]; then
|
echo "Cleaning up RDS instance..."
|
||||||
echo "Cleaning up security group $SG_NAME ($SG_ID)..."
|
aws rds delete-db-instance --db-instance-identifier $DB_IDENTIFIER --skip-final-snapshot
|
||||||
aws ec2 delete-security-group --group-id $SG_ID
|
|
||||||
fi
|
fi
|
Loading…
Reference in a new issue