Skip to content

Commit 0763455

Browse files
authored
Teardown workflow (#43)
* Add reusable teardown workflow for DEV environment * Add detailed teardown workflows for DEV environment * Add "Getting Started with Workflows" section to DevOps Guide
1 parent 84d0da2 commit 0763455

3 files changed

Lines changed: 160 additions & 1 deletion

File tree

.github/workflows/teardown-dev.yml

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
name: Teardown DEV
2+
3+
on:
4+
workflow_dispatch:
5+
6+
concurrency:
7+
group: ${{ github.workflow }}
8+
cancel-in-progress: false
9+
10+
jobs:
11+
destroy:
12+
name: Teardown DEV
13+
uses: ./.github/workflows/teardown-reusable.yml
14+
with:
15+
aws_role_arn: ${{ vars.AWS_ROLE_ARN_DEV }}
16+
aws_region: ${{ vars.AWS_REGION }}
17+
cdk_env: ${{ vars.CDK_ENV_DEV }}
18+
secrets: inherit
Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
1+
name: Teardown (Reusable)
2+
3+
on:
4+
workflow_call:
5+
inputs:
6+
aws_role_arn:
7+
description: 'AWS Role ARN for credential assumption'
8+
required: true
9+
type: string
10+
aws_region:
11+
description: 'AWS region'
12+
required: false
13+
type: string
14+
default: 'us-east-1'
15+
cdk_env:
16+
description: 'CDK environment variables'
17+
required: true
18+
type: string
19+
20+
jobs:
21+
destroy:
22+
name: Teardown
23+
runs-on: ubuntu-latest
24+
timeout-minutes: 15
25+
26+
permissions:
27+
contents: read
28+
id-token: write
29+
30+
steps:
31+
- name: Checkout repository
32+
uses: actions/checkout@v6
33+
34+
- name: Setup Node.js
35+
uses: actions/setup-node@v6
36+
with:
37+
node-version-file: .nvmrc
38+
cache: 'npm'
39+
40+
- name: Configure AWS credentials
41+
uses: aws-actions/configure-aws-credentials@v6
42+
with:
43+
role-to-assume: ${{ inputs.aws_role_arn }}
44+
aws-region: ${{ inputs.aws_region }}
45+
role-session-name: teardown-lambda-starter
46+
47+
- name: Install infrastructure dependencies
48+
working-directory: ./infrastructure
49+
run: npm ci
50+
51+
- name: Create infrastructure .env file
52+
working-directory: ./infrastructure
53+
run: echo "${{ inputs.cdk_env }}" > .env
54+
55+
- name: Destroy CDK stacks
56+
working-directory: ./infrastructure
57+
run: npm run destroy:all -- --force --progress events
58+
59+
# Final Step: Clean up sensitive infrastructure files
60+
- name: Clean up sensitive files
61+
if: always()
62+
working-directory: ./infrastructure
63+
run: |
64+
echo "🧹 Cleaning up sensitive files..."
65+
rm -f .env
66+
rm -rf cdk.out
67+
echo "✅ Sensitive files cleaned up"

docs/DevOpsGuide.md

Lines changed: 75 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,11 +29,85 @@ The project utilizes the following workflows.
2929
| ---------------------- | ----------------------------- | -------------------------------------- |
3030
| Continuous Integration | Lint, build, test | pull_request, manual |
3131
| Deploy to DEV | Deploy to DEV environment | manual |
32+
| Teardown DEV | Destroy infrastructure in DEV | manual |
3233
| Code Quality | Generate code quality reports | push to main branch, scheduled, manual |
3334

3435
---
3536

36-
## Workflow Configuration
37+
## Deployment Workflows
38+
39+
The project includes environment-specific deployment workflows that use GitHub Actions to deploy the application and infrastructure to AWS. Deployments require proper AWS credentials and environment variables to be configured.
40+
41+
### Deploy to DEV
42+
43+
**Workflow:** `deploy-dev.yml`
44+
45+
Manually triggered workflow that deploys the application and infrastructure to the DEV environment.
46+
47+
**Process:**
48+
49+
1. Checks out the repository
50+
2. Sets up Node.js environment
51+
3. Configures AWS credentials via OIDC role assumption
52+
4. Installs and builds application code
53+
5. Runs all application tests
54+
6. Installs and builds infrastructure code
55+
7. Bootstraps CDK (if needed)
56+
8. Synthesizes CDK stacks
57+
9. Deploys all CDK stacks
58+
10. Cleans up sensitive files
59+
60+
**Trigger:** Manual (`workflow_dispatch`)
61+
62+
---
63+
64+
## Teardown Workflows
65+
66+
The project includes teardown (destroy) workflows for removing provisioned infrastructure from specific environments. These workflows use a reusable workflow pattern to maintain consistency across environments.
67+
68+
### Teardown (Reusable)
69+
70+
**Workflow:** `teardown-reusable.yml`
71+
72+
A reusable workflow that provides the foundational teardown logic. This workflow is called by environment-specific teardown workflows and accepts the following inputs:
73+
74+
- `aws_role_arn` (required): AWS IAM role ARN for credential assumption
75+
- `aws_region` (optional): AWS region (defaults to `us-east-1`)
76+
- `cdk_env` (required): CDK environment variables containing stack configuration
77+
78+
**Process:**
79+
80+
1. Checks out the repository
81+
2. Sets up Node.js environment
82+
3. Configures AWS credentials via OIDC role assumption
83+
4. Installs infrastructure dependencies
84+
5. Creates `.env` file with CDK configuration
85+
6. Destroys all CDK stacks using `npm run destroy:all -- --force --progress events`
86+
7. Cleans up sensitive files (`.env`, `cdk.out`)
87+
88+
### Teardown DEV
89+
90+
**Workflow:** `teardown-dev.yml`
91+
92+
Environment-specific workflow that triggers the reusable teardown workflow for the DEV environment.
93+
94+
**Process:**
95+
96+
- Calls the reusable `teardown-reusable.yml` workflow
97+
- Passes DEV-specific configuration:
98+
- `AWS_ROLE_ARN_DEV` as the AWS role ARN
99+
- `AWS_REGION` as the AWS region
100+
- `CDK_ENV_DEV` as the CDK environment variables
101+
102+
**Concurrency:** Only one DEV teardown can run at a time; subsequent requests will cancel the in-progress workflow.
103+
104+
**Trigger:** Manual (`workflow_dispatch`)
105+
106+
**⚠️ Warning:** Teardown workflows permanently destroy provisioned AWS infrastructure. Use with caution and ensure you have backups of any critical data.
107+
108+
---
109+
110+
## Getting Started with Workflows
37111

38112
Workflows are defined in `.github/workflows/` as YAML files. Each workflow is triggered by specific events (push, pull_request, release, etc.).
39113

0 commit comments

Comments
 (0)