Change-Id: I75c3a03bc3b1b487e780bd2b66e8fb1f2b2e115d
This commit is contained in:
@@ -0,0 +1,64 @@
|
||||
|
||||
name: destroy
|
||||
|
||||
on:
|
||||
workflow_dispatch:
|
||||
inputs:
|
||||
confirm_destroy:
|
||||
description: "Type the repository name to confirm destroy"
|
||||
required: true
|
||||
default: ""
|
||||
|
||||
jobs:
|
||||
destroy:
|
||||
runs-on:
|
||||
- toolzoo-host
|
||||
env:
|
||||
AWS_REGION: us-east-1
|
||||
APP_STACK_PREFIX: temp-stack
|
||||
steps:
|
||||
- name: Destroy stack and ECR images
|
||||
shell: bash
|
||||
run: |
|
||||
set -euo pipefail
|
||||
repo_full="${GITHUB_REPOSITORY}"
|
||||
owner_raw="${repo_full%%/*}"
|
||||
repo_raw="${repo_full##*/}"
|
||||
confirm="${{ github.event.inputs.confirm_destroy }}"
|
||||
if [[ "$confirm" != "$repo_raw" ]]; then
|
||||
echo "Refusing destroy: confirm_destroy must exactly match '$repo_raw'."
|
||||
exit 1
|
||||
fi
|
||||
|
||||
repo_slug="$(printf '%s' "$repo_raw" | tr '[:upper:]' '[:lower:]')"
|
||||
stack_name="${APP_STACK_PREFIX}-${repo_slug}"
|
||||
ecr_repo="temp/${repo_slug}"
|
||||
|
||||
aws cloudformation delete-stack --stack-name "$stack_name"
|
||||
aws cloudformation wait stack-delete-complete --stack-name "$stack_name"
|
||||
|
||||
if aws ecr describe-repositories --repository-names "$ecr_repo" >/dev/null 2>&1; then
|
||||
aws ecr delete-repository --repository-name "$ecr_repo" --force
|
||||
fi
|
||||
|
||||
if [[ -f catalog-info.yaml ]]; then
|
||||
awk '
|
||||
BEGIN { in_block=0 }
|
||||
/^ # BEGIN TOOLZOO MANAGED LINK$/ { in_block=1; next }
|
||||
/^ # END TOOLZOO MANAGED LINK$/ { in_block=0; next }
|
||||
in_block==1 { next }
|
||||
{ print }
|
||||
' catalog-info.yaml > /tmp/catalog-info.yaml.cleaned
|
||||
|
||||
if ! cmp -s catalog-info.yaml /tmp/catalog-info.yaml.cleaned; then
|
||||
mv /tmp/catalog-info.yaml.cleaned catalog-info.yaml
|
||||
git config user.name "toolzoo-bot"
|
||||
git config user.email "toolzoo-bot@local"
|
||||
git add catalog-info.yaml
|
||||
git commit -m "Remove stale service URL after destroy"
|
||||
git push origin HEAD:main
|
||||
else
|
||||
rm -f /tmp/catalog-info.yaml.cleaned
|
||||
fi
|
||||
fi
|
||||
|
||||
Reference in New Issue
Block a user