-
Notifications
You must be signed in to change notification settings - Fork 18
74 lines (63 loc) · 2.32 KB
/
destroy.yaml
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
name: Destroy Production
on:
workflow_dispatch:
inputs:
cleanup:
description: 'Cleanup bucket & logs (yes/no)'
required: true
default: 'no'
jobs:
destroy:
name: Destroy
runs-on: ubuntu-latest
steps:
- name: Set up Node
uses: actions/setup-node@v1
with:
node-version: 14.x
- name: Checkout code
uses: actions/checkout@v2
with:
ref: production
- name: Cache dependencies
uses: actions/cache@v2
with:
path: ~/.npm
key: ${{ runner.OS }}-npm-${{ hashFiles('**/package-lock.json') }}
restore-keys: |
${{ runner.OS }}-npm-
${{ runner.OS }}-
- name: Install dependencies
run: npm ci
- 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: ${{ secrets.AWS_REGION }}
- name: Decrypt config
run: npm run decrypt-config -- --passphrase="$ENCRYPT_PASSPHRASE" maildog.config.json.gpg
env:
ENCRYPT_PASSPHRASE: ${{ secrets.ENCRYPT_PASSPHRASE }}
- name: Deactivate receipt rule set
run: aws ses set-active-receipt-rule-set
- name: Destroy stack
run: npx cdk destroy --force
env:
ENVIRONMENT_NAME: production
cleanup:
name: Cleanup
if: ${{ github.event.inputs.cleanup == 'yes' }}
needs: destroy
runs-on: ubuntu-latest
steps:
- 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: ${{ secrets.AWS_REGION }}
- name: Remove bucket and its content
run: aws s3 rb s3://$(aws s3api list-buckets --query "Buckets[?starts_with(Name, 'maildog-production-')].Name" --output text) --force
- name: Clear log groups from Lambda functions
run: aws logs describe-log-groups --log-group-name-prefix "/aws/lambda/MailDog-production-" --query "logGroups[].logGroupName" --output text | xargs -I {} -n 1 aws logs delete-log-group --log-group-name {}