Skip to content

Commit f027683

Browse files
authored
Reusable deploy workflow (#46)
* Refactor deployment workflow to use reusable GitHub Actions * Update deployment workflows to use reusable patterns and enhance DEV deployment process
1 parent 1bdf8b5 commit f027683

File tree

3 files changed

+133
-83
lines changed

3 files changed

+133
-83
lines changed

.github/workflows/deploy-dev.yml

Lines changed: 7 additions & 74 deletions
Original file line numberDiff line numberDiff line change
@@ -9,77 +9,10 @@ concurrency:
99

1010
jobs:
1111
deploy:
12-
name: Deploy
13-
runs-on: ubuntu-latest
14-
timeout-minutes: 15
15-
16-
permissions:
17-
contents: read
18-
id-token: write
19-
20-
steps:
21-
- name: Checkout repository
22-
uses: actions/checkout@v6
23-
24-
- name: Setup Node.js
25-
uses: actions/setup-node@v6
26-
with:
27-
node-version-file: .nvmrc
28-
cache: 'npm'
29-
30-
- name: Configure AWS credentials
31-
uses: aws-actions/configure-aws-credentials@v6
32-
with:
33-
role-to-assume: ${{ vars.AWS_ROLE_ARN_DEV }}
34-
aws-region: ${{ vars.AWS_REGION }}
35-
role-session-name: deploy-dev-lambda-starter
36-
37-
- name: Install dependencies
38-
run: npm ci
39-
40-
- name: Build application
41-
run: npm run build
42-
43-
- name: Run tests
44-
run: npm run test
45-
46-
- name: Install infrastructure dependencies
47-
working-directory: ./infrastructure
48-
run: npm ci
49-
50-
- name: Create infrastructure .env file
51-
working-directory: ./infrastructure
52-
run: echo "${{ vars.CDK_ENV_DEV }}" > .env
53-
54-
- name: Build infrastructure
55-
working-directory: ./infrastructure
56-
run: npm run build
57-
58-
- name: Bootstrap CDK (if needed)
59-
working-directory: ./infrastructure
60-
run: |
61-
# Check if bootstrap is needed
62-
if ! aws cloudformation describe-stacks --stack-name CDKToolkit --region ${{ vars.AWS_REGION }} >/dev/null 2>&1; then
63-
echo "Bootstrapping CDK..."
64-
npm run bootstrap
65-
else
66-
echo "CDK already bootstrapped"
67-
fi
68-
69-
- name: Synthesize CDK stacks
70-
working-directory: ./infrastructure
71-
run: npm run synth
72-
73-
- name: Deploy CDK stacks
74-
working-directory: ./infrastructure
75-
run: npm run deploy:all -- --require-approval never --progress events
76-
77-
# Final Step: Clean up sensitive infrastructure files
78-
- name: Clean up sensitive files
79-
if: always()
80-
working-directory: ./infrastructure
81-
run: |
82-
echo "🧹 Cleaning up sensitive files..."
83-
rm -f .env
84-
rm -rf cdk.out
85-
echo "✅ Sensitive files cleaned up"
12+
name: Deploy to DEV
13+
uses: ./.github/workflows/deploy-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: 95 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,95 @@
1+
name: Deploy (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+
deploy:
22+
name: Deploy
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: deploy-lambda-starter
46+
47+
- name: Install dependencies
48+
run: npm ci
49+
50+
- name: Build application
51+
run: npm run build
52+
53+
- name: Run tests
54+
run: npm run test
55+
56+
- name: Install infrastructure dependencies
57+
working-directory: ./infrastructure
58+
run: npm ci
59+
60+
- name: Create infrastructure .env file
61+
working-directory: ./infrastructure
62+
run: echo "${{ inputs.cdk_env }}" > .env
63+
64+
- name: Build infrastructure
65+
working-directory: ./infrastructure
66+
run: npm run build
67+
68+
- name: Bootstrap CDK (if needed)
69+
working-directory: ./infrastructure
70+
run: |
71+
# Check if bootstrap is needed
72+
if ! aws cloudformation describe-stacks --stack-name CDKToolkit --region ${{ inputs.aws_region }} >/dev/null 2>&1; then
73+
echo "Bootstrapping CDK..."
74+
npm run bootstrap
75+
else
76+
echo "CDK already bootstrapped"
77+
fi
78+
79+
- name: Synthesize CDK stacks
80+
working-directory: ./infrastructure
81+
run: npm run synth
82+
83+
- name: Deploy CDK stacks
84+
working-directory: ./infrastructure
85+
run: npm run deploy:all -- --require-approval never --progress events
86+
87+
# Final Step: Clean up sensitive infrastructure files
88+
- name: Clean up sensitive files
89+
if: always()
90+
working-directory: ./infrastructure
91+
run: |
92+
echo "🧹 Cleaning up sensitive files..."
93+
rm -f .env
94+
rm -rf cdk.out
95+
echo "✅ Sensitive files cleaned up"

docs/DevOpsGuide.md

Lines changed: 31 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -36,13 +36,17 @@ The project utilizes the following workflows.
3636

3737
## Deployment Workflows
3838

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.
39+
The project includes deployment workflows that use GitHub Actions to deploy the application and infrastructure to AWS. These workflows use a reusable workflow pattern to maintain consistency across environments. Deployments require proper AWS credentials and environment variables to be configured.
4040

41-
### Deploy to DEV
41+
### Deploy (Reusable)
4242

43-
**Workflow:** `deploy-dev.yml`
43+
**Workflow:** `deploy-reusable.yml`
44+
45+
A reusable workflow that provides the foundational deployment logic. This workflow is called by environment-specific deployment workflows and accepts the following inputs:
4446

45-
Manually triggered workflow that deploys the application and infrastructure to the DEV environment.
47+
- `aws_role_arn` (required): AWS IAM role ARN for credential assumption
48+
- `aws_region` (optional): AWS region (defaults to `us-east-1`)
49+
- `cdk_env` (required): CDK environment variables containing stack configuration
4650

4751
**Process:**
4852

@@ -51,11 +55,29 @@ Manually triggered workflow that deploys the application and infrastructure to t
5155
3. Configures AWS credentials via OIDC role assumption
5256
4. Installs and builds application code
5357
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
58+
6. Installs infrastructure dependencies
59+
7. Creates `.env` file with CDK configuration
60+
8. Builds infrastructure code
61+
9. Bootstraps CDK (if needed)
62+
10. Synthesizes CDK stacks
63+
11. Deploys all CDK stacks using `npm run deploy:all -- --require-approval never --progress events`
64+
12. Cleans up sensitive files (`.env`, `cdk.out`)
65+
66+
### Deploy to DEV
67+
68+
**Workflow:** `deploy-dev.yml`
69+
70+
Environment-specific workflow that triggers the reusable deployment workflow for the DEV environment.
71+
72+
**Process:**
73+
74+
- Calls the reusable `deploy-reusable.yml` workflow
75+
- Passes DEV-specific configuration:
76+
- `AWS_ROLE_ARN_DEV` as the AWS role ARN
77+
- `AWS_REGION` as the AWS region
78+
- `CDK_ENV_DEV` as the CDK environment variables
79+
80+
**Concurrency:** Only one DEV deployment can run at a time; subsequent requests will cancel the in-progress workflow.
5981

6082
**Trigger:** Manual (`workflow_dispatch`)
6183

0 commit comments

Comments
 (0)