1
1
name : Data replication pipeline
2
- run-name : ${{ inputs.action }} data replication resources for ${{ inputs.environment }}
2
+ run-name : Deploy ${{ inputs.deployment_type }} data replication resources for ${{ inputs.environment }}
3
3
4
4
on :
5
5
workflow_dispatch :
15
15
- qa
16
16
- sandbox-alpha
17
17
- sandbox-beta
18
+ deployment_type :
19
+ description : Service to deploy
20
+ required : true
21
+ type : choice
22
+ options :
23
+ - Full deployment
24
+ - DB snapshot only
25
+ - Webapp only
18
26
image_tag :
19
27
description : Docker image tag to deploy
20
28
required : false
21
29
type : string
22
- action :
23
- description : Action to perform on data replication env
24
- required : true
25
- type : choice
26
- options :
27
- - Destroy
28
- - Recreate
29
- default : Recreate
30
30
db_snapshot_arn :
31
31
description : ARN of the DB snapshot to use (optional)
32
32
required : false
41
41
aws_role : ${{ inputs.environment == 'production'
42
42
&& 'arn:aws:iam::820242920762:role/GithubDeployDataReplicationInfrastructure'
43
43
|| 'arn:aws:iam::393416225559:role/GithubDeployDataReplicationInfrastructure' }}
44
+ recreate_db : ${{ inputs.deployment_type == 'Full deployment' || inputs.deployment_type == 'DB snapshot only' }}
45
+ recreate_webapp : ${{ inputs.deployment_type == 'Full deployment' || inputs.deployment_type == 'Webapp only' }}
44
46
45
47
defaults :
46
48
run :
@@ -50,8 +52,8 @@ concurrency:
50
52
group : deploy-data-replica-${{ inputs.environment }}
51
53
52
54
jobs :
53
- prepare :
54
- if : ${{ inputs.action == 'Recreate' }}
55
+ prepare-db-replica :
56
+ if : env.recreate_db == 'true'
55
57
name : Prepare data replica
56
58
runs-on : ubuntu-latest
57
59
permissions :
@@ -95,25 +97,13 @@ jobs:
95
97
terraform init -backend-config="env/${{ inputs.environment }}-backend.hcl" -upgrade
96
98
DB_SECRET_ARN=$(terraform output --raw db_secret_arn)
97
99
echo "DB_SECRET_ARN=$DB_SECRET_ARN" >> $GITHUB_OUTPUT
98
- - name : ECR login
99
- id : login-ecr
100
- uses : aws-actions/amazon-ecr-login@v2
101
- - name : Get docker image digest
102
- id : get-docker-image-digest
103
- run : |
104
- set -e
105
- DOCKER_IMAGE="${{ steps.login-ecr.outputs.registry }}/mavis/webapp:${{ inputs.image_tag || github.sha }}"
106
- docker pull "$DOCKER_IMAGE"
107
- DOCKER_DIGEST=$(docker inspect --format='{{index .RepoDigests 0}}' "$DOCKER_IMAGE")
108
- DIGEST="${DOCKER_DIGEST#*@}"
109
- echo "DIGEST=$DIGEST" >> $GITHUB_OUTPUT
110
100
outputs :
111
101
SNAPSHOT_ARN : ${{ steps.get-latest-snapshot.outputs.SNAPSHOT_ARN }}
112
102
DB_SECRET_ARN : ${{ steps.get-db-secret-arn.outputs.DB_SECRET_ARN }}
113
- DOCKER_DIGEST : ${{ steps.get-docker-image-digest.outputs.DIGEST }}
114
103
115
- plan-destroy :
116
- name : Plan destruction job
104
+ prepare-webapp :
105
+ if : env.recreate_webapp == 'true'
106
+ name : Prepare webapp
117
107
runs-on : ubuntu-latest
118
108
permissions :
119
109
id-token : write
@@ -125,64 +115,34 @@ jobs:
125
115
with :
126
116
role-to-assume : ${{ env.aws_role }}
127
117
aws-region : eu-west-2
128
- - name : Install terraform
129
- uses : hashicorp/setup-terraform@v3
130
- with :
131
- terraform_version : 1.11.4
132
- - name : Terraform Plan
133
- run : |
134
- set -e
135
- terraform init -backend-config="env/${{ inputs.environment }}-backend.hcl" -upgrade
136
- terraform plan -destroy -var-file="env/${{ inputs.environment }}.tfvars" -var="image_digest=filler_value" \
137
- -var="db_secret_arn=filler_value" -var="imported_snapshot=filler_value" \
138
- -out ${{ runner.temp }}/tfplan_destroy | tee ${{ runner.temp }}/tf_stdout
139
- - name : Upload artifact
140
- uses : actions/upload-artifact@v4
141
- with :
142
- name : tfplan_destroy_infrastructure-${{ inputs.environment }}
143
- path : ${{ runner.temp }}/tfplan_destroy
144
-
145
- destroy :
146
- name : Destroy data replication infrastructure
147
- runs-on : ubuntu-latest
148
- needs : plan-destroy
149
- environment : ${{ inputs.environment }}
150
- permissions :
151
- id-token : write
152
- steps :
153
- - name : Checkout code
154
- uses : actions/checkout@v4
155
- - name : Configure AWS Credentials
156
- uses : aws-actions/configure-aws-credentials@v4
157
- with :
158
- role-to-assume : ${{ env.aws_role }}
159
- aws-region : eu-west-2
160
- - name : Install terraform
161
- uses : hashicorp/setup-terraform@v3
162
- with :
163
- terraform_version : 1.11.4
164
- - name : Download artifact
165
- uses : actions/download-artifact@v4
166
- with :
167
- name : tfplan_destroy_infrastructure-${{ inputs.environment }}
168
- path : ${{ runner.temp }}
169
- - name : Terraform Destroy
170
- id : destroy
118
+ - name : ECR login
119
+ id : login-ecr
120
+ uses : aws-actions/amazon-ecr-login@v2
121
+ - name : Get docker image digest
122
+ id : get-docker-image-digest
171
123
run : |
172
124
set -e
173
- terraform init -backend-config="env/${{ inputs.environment }}-backend.hcl" -upgrade
174
- terraform apply ${{ runner.temp }}/tfplan_destroy
125
+ DOCKER_IMAGE="${{ steps.login-ecr.outputs.registry }}/mavis/webapp:${{ inputs.image_tag || github.sha }}"
126
+ docker pull "$DOCKER_IMAGE"
127
+ DOCKER_DIGEST=$(docker inspect --format='{{index .RepoDigests 0}}' "$DOCKER_IMAGE")
128
+ DIGEST="${DOCKER_DIGEST#*@}"
129
+ echo "DIGEST=$DIGEST" >> $GITHUB_OUTPUT
130
+ outputs :
131
+ DOCKER_DIGEST : ${{ steps.get-docker-image-digest.outputs.DIGEST }}
175
132
176
133
plan :
177
134
name : Terraform plan
178
135
runs-on : ubuntu-latest
179
136
needs :
180
- - prepare
181
- - destroy
137
+ - prepare-db-replica
138
+ - prepare-webapp
139
+ if : ${{ !cancelled() &&
140
+ (needs.prepare-db-replica.result == 'success' || needs.prepare-db-replica.result == 'skipped') &&
141
+ (needs.prepare-webapp.result == 'success' || needs.prepare-webapp.result == 'skipped') }}
182
142
env :
183
- SNAPSHOT_ARN : ${{ needs.prepare.outputs.SNAPSHOT_ARN }}
184
- DB_SECRET_ARN : ${{ needs.prepare.outputs.DB_SECRET_ARN }}
185
- DOCKER_DIGEST : ${{ needs.prepare.outputs.DOCKER_DIGEST }}
143
+ SNAPSHOT_ARN : ${{ needs.prepare-db-replica .outputs.SNAPSHOT_ARN }}
144
+ DB_SECRET_ARN : ${{ needs.prepare-db-replica .outputs.DB_SECRET_ARN }}
145
+ DOCKER_DIGEST : ${{ needs.prepare-webapp .outputs.DOCKER_DIGEST }}
186
146
permissions :
187
147
id-token : write
188
148
steps :
@@ -202,6 +162,10 @@ jobs:
202
162
run : |
203
163
set -e
204
164
terraform init -backend-config="env/${{ inputs.environment }}-backend.hcl" -upgrade
165
+ if [ "${{ env.recreate_db }}" == "true" ]; then
166
+ echo "Tainting the database instance for recreation"
167
+ terraform taint aws_rds_cluster.cluster
168
+ fi
205
169
terraform plan -var="image_digest=${{ env.DOCKER_DIGEST }}" -var="db_secret_arn=${{ env.DB_SECRET_ARN }}" \
206
170
-var="imported_snapshot=${{ env.SNAPSHOT_ARN }}" -var-file="env/${{ inputs.environment }}.tfvars" \
207
171
-var='allowed_egress_cidr_blocks=${{ inputs.egress_cidr }}' \
0 commit comments