Skip to content

Commit f263cdd

Browse files
committed
ci: Added deployment jobs.
1 parent f2b012d commit f263cdd

4 files changed

Lines changed: 147 additions & 1 deletion

File tree

.github/workflows/deploy-app.yaml

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
name: Deploy application
2+
3+
on:
4+
workflow_dispatch:
5+
inputs:
6+
application:
7+
description: Application to deploy.
8+
required: true
9+
type: string
10+
environment:
11+
description: Environment to deploy to.
12+
default: development
13+
required: true
14+
type: environment
15+
16+
permissions:
17+
contents: read
18+
19+
jobs:
20+
deploy:
21+
name: Deploy ${{ inputs.application }} to ${{ inputs.environment }}
22+
runs-on: ubuntu-latest
23+
environment: ${{ inputs.environment }}
24+
env:
25+
AWS_ACCESS_KEY_ID: ${{ secrets.AWS_ACCESS_KEY_ID }}
26+
AWS_SECRET_ACCESS_KEY: ${{ secrets.AWS_SECRET_ACCESS_KEY }}
27+
AWS_REGION: ${{ vars.AWS_REGION || 'us-east-1' }}
28+
steps:
29+
- name: Checkout code
30+
uses: actions/checkout@v4
31+
- name: Set up AWS credentials
32+
uses: aws-actions/configure-aws-credentials@v4
33+
with:
34+
aws-access-key-id: ${{ secrets.AWS_ACCESS_KEY_ID }}
35+
aws-secret-access-key: ${{ secrets.AWS_SECRET_ACCESS_KEY }}
36+
aws-region: us-east-1
37+
- name: Setup OpenTofu
38+
uses: opentofu/setup-opentofu@v1
39+
- name: Initialize OpenTofu
40+
working-directory: ./tofu/config/${{ inputs.environment }}/infra
41+
run: tofu init
42+
- name: Apply changes
43+
working-directory: ./tofu/config/${{ inputs.environment }}/infra
44+
run: tofu apply --target module.app\[\"${{ inputs.application }}\"] --auto-approve

.github/workflows/deploy.yaml

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
name: Deploy infrastructure
2+
3+
on:
4+
workflow_dispatch:
5+
inputs:
6+
environment:
7+
description: Environment to deploy to.
8+
default: development
9+
required: true
10+
type: environment
11+
12+
permissions:
13+
contents: read
14+
15+
jobs:
16+
deploy:
17+
name: Deploy infrastrucure to ${{ inputs.environment }}
18+
runs-on: ubuntu-latest
19+
environment: ${{ inputs.environment }}
20+
env:
21+
AWS_ACCESS_KEY_ID: ${{ secrets.AWS_ACCESS_KEY_ID }}
22+
AWS_SECRET_ACCESS_KEY: ${{ secrets.AWS_SECRET_ACCESS_KEY }}
23+
AWS_REGION: ${{ vars.AWS_REGION || 'us-east-1' }}
24+
steps:
25+
- name: Checkout code
26+
uses: actions/checkout@v4
27+
- name: Set up AWS credentials
28+
uses: aws-actions/configure-aws-credentials@v4
29+
with:
30+
aws-access-key-id: ${{ secrets.AWS_ACCESS_KEY_ID }}
31+
aws-secret-access-key: ${{ secrets.AWS_SECRET_ACCESS_KEY }}
32+
aws-region: us-east-1
33+
- name: Setup OpenTofu
34+
uses: opentofu/setup-opentofu@v1
35+
- name: Initialize OpenTofu
36+
working-directory: ./tofu/config/${{ inputs.environment }}/infra
37+
run: tofu init
38+
- name: Apply changes
39+
working-directory: ./tofu/config/${{ inputs.environment }}/infra
40+
run: tofu apply --auto-approve

.github/workflows/plan-app.yaml

Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
name: Plan application deployment
2+
3+
on:
4+
push:
5+
branches-ignore:
6+
- main
7+
repository_dispatch:
8+
types:
9+
- plan-app
10+
workflow_dispatch:
11+
inputs:
12+
application:
13+
description: Application to plan.
14+
required: true
15+
type: string
16+
environment:
17+
description: Environment to plan on.
18+
default: development
19+
required: true
20+
type: environment
21+
22+
permissions:
23+
contents: read
24+
25+
jobs:
26+
plan:
27+
name: Plan deploy of ${{ inputs.application }} to ${{ inputs.environment }}
28+
runs-on: ubuntu-latest
29+
environment: ${{ inputs.environment }}
30+
env:
31+
AWS_ACCESS_KEY_ID: ${{ secrets.AWS_ACCESS_KEY_ID }}
32+
AWS_SECRET_ACCESS_KEY: ${{ secrets.AWS_SECRET_ACCESS_KEY }}
33+
AWS_REGION: ${{ vars.AWS_REGION || 'us-east-1' }}
34+
steps:
35+
- name: "DEBUG: Dump inputs"
36+
uses: imesense/gha-echo-action@v0.2
37+
with:
38+
input-string: ${{ toJson(inputs) }}
39+
- name: "DEBUG: Dump payload"
40+
uses: imesense/gha-echo-action@v0.2
41+
with:
42+
input-string: ${{ toJson(github.event.client_payload) }}
43+
- name: Checkout code
44+
uses: actions/checkout@v4
45+
- name: Set up AWS credentials
46+
uses: aws-actions/configure-aws-credentials@v4
47+
with:
48+
aws-access-key-id: ${{ secrets.AWS_ACCESS_KEY_ID }}
49+
aws-secret-access-key: ${{ secrets.AWS_SECRET_ACCESS_KEY }}
50+
aws-region: us-east-1
51+
- name: Setup OpenTofu
52+
uses: opentofu/setup-opentofu@v1
53+
- name: Initialize OpenTofu
54+
working-directory: ./tofu/config/${{ inputs.environment }}/infra
55+
run: tofu init
56+
- name: Plan changes
57+
working-directory: ./tofu/config/${{ inputs.environment }}/infra
58+
run: tofu plan --target module.app\[\"${{ inputs.application }}\"]
59+
- name: Display plan
60+
uses: imesense/gha-echo-action@v0.2
61+
with:
62+
input-string: ${{ steps.plan.outputs.stdout }}

.github/workflows/plan.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ jobs:
4343
with:
4444
aws-access-key-id: ${{ secrets.AWS_ACCESS_KEY_ID }}
4545
aws-secret-access-key: ${{ secrets.AWS_SECRET_ACCESS_KEY }}
46-
aws-region: us-east-1
46+
aws-region: ${{ vars.AWS_REGION || 'us-east-1' }}
4747
- name: Setup OpenTofu
4848
uses: opentofu/setup-opentofu@v1
4949
- name: Initialize OpenTofu

0 commit comments

Comments
 (0)