-
Notifications
You must be signed in to change notification settings - Fork 12
163 lines (145 loc) · 5.85 KB
/
remove-experimental-cdk.yml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
name: "Remove Experimental (CDK)"
on:
workflow_dispatch:
pull_request:
types: [ closed ]
permissions:
id-token: write
contents: read
actions: read
jobs:
remove:
environment:
name: "dev"
runs-on: ubuntu-22.04
steps:
# gettign PR is trivial here because the only tirgger is closing a PR
- name: Echo PR#
env:
PR: ${{ github.event.number }}
run: echo "Your PR is ${PR}"
# Checkout the code
- uses: actions/checkout@v3
with:
submodules: true
# Setup Node
- uses: actions/setup-node@v3
with:
node-version: 20
# Setup Python
- uses: actions/setup-python@v5
with:
python-version: '3.12'
# Configure AWS credentials for GitHub Actions
- name: Configure AWS credentials for GitHub Actions
uses: aws-actions/configure-aws-credentials@v4
with:
role-to-assume: ${{ secrets.AWS_OIDC_ROLE_TO_ASSUME }}
aws-region: us-east-1
- name: Destroy PR-Specific Redirect Stack
env:
PR_NUMBER: ${{ github.event.number }}
AWS_ACCOUNT_ID: ${{ secrets.AWS_ACCOUNT_ID }}
AWS_DEFAULT_REGION: ${{ vars.AWS_DEFAULT_REGION }}
CDK_DEBUG: true
ENVIRONMENT_NAME: ${{ env.ENVIRONMENT_NAME }}
run: |
pushd cdk-eregs
npm install -g aws-cdk@latest @aws-sdk/client-ssm
npm install
# Generate the exact stack name for this PR
STACK_NAME="cms-eregs-eph-${PR_NUMBER}-redirect-api"
echo "Destroying PR-specific stack: ${STACK_NAME}"
cdk destroy "${STACK_NAME}" \
-c environment=${{ env.ENVIRONMENT_NAME }} \
--force \
--app "npx ts-node bin/zip-lambdas.ts"
echo "Cleanup completed for stack: ${STACK_NAME}"
popd
- name: Destroy PR-Maintenance Stack
env:
PR_NUMBER: ${{ github.event.number }}
AWS_ACCOUNT_ID: ${{ secrets.AWS_ACCOUNT_ID }}
AWS_DEFAULT_REGION: ${{ vars.AWS_DEFAULT_REGION }}
CDK_DEBUG: true
ENVIRONMENT_NAME: ${{ env.ENVIRONMENT_NAME }}
run: |
pushd cdk-eregs
npm install -g aws-cdk@latest @aws-sdk/client-ssm
npm install
# Generate the exact stack name for this PR
STACK_NAME="cms-eregs-eph-${PR_NUMBER}-maintenance-api"
echo "Destroying PR-specific stack: ${STACK_NAME}"
cdk destroy "${STACK_NAME}" \
-c environment=${{ env.ENVIRONMENT_NAME }} \
--force \
--app "npx ts-node bin/zip-lambdas.ts"
echo "Cleanup completed for stack: ${STACK_NAME}"
popd
- name: Cleanup Docker-based Lambda Stacks
env:
PR_NUMBER: ${{ github.event.number }}
AWS_ACCOUNT_ID: ${{ secrets.AWS_ACCOUNT_ID }}
AWS_DEFAULT_REGION: ${{ vars.AWS_DEFAULT_REGION }}
CDK_DEBUG: true
ENVIRONMENT_NAME: ${{ env.ENVIRONMENT_NAME }}
run: |
pushd cdk-eregs
npm install -g aws-cdk@latest @aws-sdk/client-ssm
npm install
# Delete the database for this ephemeral environment
echo "Deleting database for PR: ${PR_NUMBER}"
aws lambda invoke --function-name cms-eregs-eph-$PR_NUMBER-dropdb /dev/stdout | tee -a aws.log
# Check for invocation errors
! grep -q FunctionError aws.log
# Generate the stack names for this PR
TEXT_EXTRACTOR_STACK="cms-eregs-eph-${PR_NUMBER}-text-extractor"
FR_PARSER_STACK="cms-eregs-eph-${PR_NUMBER}-fr-parser"
ECFR_PARSER_STACK="cms-eregs-eph-${PR_NUMBER}-ecfr-parser"
API_STACK="cms-eregs-eph-${PR_NUMBER}-api"
# Destroy fr-parser stack
echo "Destroying PR-specific stack: ${FR_PARSER_STACK}"
cdk destroy "${FR_PARSER_STACK}" \
-c environment=${{ env.ENVIRONMENT_NAME }} \
--force \
--app "npx ts-node bin/docker-lambdas.ts"
# Destroy ecfr-parser stack
echo "Destroying PR-specific stack: ${ECFR_PARSER_STACK}"
cdk destroy "${ECFR_PARSER_STACK}" \
-c environment=${{ env.ENVIRONMENT_NAME }} \
--force \
--app "npx ts-node bin/docker-lambdas.ts"
# Destroy api-stack stack
echo "Destroying PR-specific stack: ${API_STACK}"
cdk destroy "${API_STACK}" \
-c environment=${{ env.ENVIRONMENT_NAME }} \
--force \
--app "npx ts-node bin/docker-lambdas.ts"
# Destroy text-extractor stack
echo "Destroying PR-specific stack: ${TEXT_EXTRACTOR_STACK}"
cdk destroy "${TEXT_EXTRACTOR_STACK}" \
-c environment=${{ env.ENVIRONMENT_NAME }} \
--force \
--app "npx ts-node bin/docker-lambdas.ts"
echo "Cleanup completed for all Docker-based stacks"
popd
- name: Destroy PR-Specific Static-Asset Stack
env:
PR_NUMBER: ${{ github.event.number }}
AWS_ACCOUNT_ID: ${{ secrets.AWS_ACCOUNT_ID }}
AWS_DEFAULT_REGION: ${{ vars.AWS_DEFAULT_REGION }}
CDK_DEBUG: true
ENVIRONMENT_NAME: ${{ env.ENVIRONMENT_NAME }}
run: |
pushd cdk-eregs
npm install -g aws-cdk@latest @aws-sdk/client-ssm
npm install
# Generate the exact stack name for this PR
STACK_NAME="cms-eregs-eph-${PR_NUMBER}-static-assets"
echo "Destroying PR-specific stack: ${STACK_NAME}"
cdk destroy "${STACK_NAME}" \
-c environment=${{ env.ENVIRONMENT_NAME }} \
--force \
--app "npx ts-node bin/zip-lambdas.ts"
echo "Cleanup completed for stack: ${STACK_NAME}"
popd