mirror of
https://github.com/spring-projects/spring-petclinic.git
synced 2025-07-19 14:05: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:
|
||||
inputs:
|
||||
environment:
|
||||
|
@ -16,27 +15,31 @@
|
|||
confirm:
|
||||
description: 'Type "delete" to confirm deletion'
|
||||
required: true
|
||||
|
||||
push:
|
||||
branches:
|
||||
- dev
|
||||
|
||||
jobs:
|
||||
jobs:
|
||||
cleanup:
|
||||
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:
|
||||
- uses: actions/checkout@v3
|
||||
|
||||
- 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
|
||||
uses: aws-actions/configure-aws-credentials@v1
|
||||
with:
|
||||
aws-access-key-id: ${{ secrets.AWS_ACCESS_KEY_ID }}
|
||||
aws-secret-access-key: ${{ secrets.AWS_SECRET_ACCESS_KEY }}
|
||||
aws-region: us-east-1
|
||||
aws-region: us-west-2
|
||||
|
||||
- name: Setup Terraform
|
||||
uses: hashicorp/setup-terraform@v2
|
||||
|
@ -74,6 +77,14 @@
|
|||
aws ecs delete-cluster --cluster petclinic-${{ env.ENV_NAME }}
|
||||
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
|
||||
BUCKET_NAME="petclinic-${{ env.ENV_NAME }}-artifacts"
|
||||
if aws s3api head-bucket --bucket $BUCKET_NAME 2>/dev/null; then
|
||||
|
@ -82,10 +93,9 @@
|
|||
aws s3api delete-bucket --bucket $BUCKET_NAME
|
||||
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
|
||||
# Clean up RDS instance if it exists
|
||||
DB_IDENTIFIER="petclinic-${{ env.ENV_NAME }}db"
|
||||
if aws rds describe-db-instances --db-instance-identifier $DB_IDENTIFIER 2>/dev/null; then
|
||||
echo "Cleaning up RDS instance..."
|
||||
aws rds delete-db-instance --db-instance-identifier $DB_IDENTIFIER --skip-final-snapshot
|
||||
fi
|
Loading…
Reference in a new issue