1
- name : Data replication pipeline
1
+ name : Deploy Data Replication
2
2
run-name : ${{ inputs.deployment_type }} for data replication resources for ${{ inputs.environment }}
3
3
4
4
on :
15
15
- qa
16
16
- sandbox-alpha
17
17
- sandbox-beta
18
- deployment_type :
19
- description : Deployment type
20
- required : true
21
- type : choice
22
- options :
23
- - Deployment with DB recreation
24
- - Application only deployment
25
18
image_tag :
26
19
description : Docker image tag to deploy
27
20
required : false
28
21
type : string
29
- db_snapshot_arn :
30
- description : ARN of the DB snapshot to use (optional)
31
- required : false
32
- type : string
33
- egress_cidr :
34
- description : CIDR blocks to allow egress traffic.
35
- type : string
36
- required : true
37
- default : " []"
38
22
39
23
env :
40
24
aws_role : ${{ inputs.environment == 'production'
@@ -49,171 +33,46 @@ concurrency:
49
33
group : deploy-data-replica-${{ inputs.environment }}
50
34
51
35
jobs :
52
- prepare-db-replica :
53
- if : ${{ inputs.deployment_type == 'Deployment with DB recreation' }}
54
- name : Prepare data replica
36
+ validate-inputs :
55
37
runs-on : ubuntu-latest
56
- permissions :
57
- id-token : write
38
+ permissions : { }
58
39
steps :
59
- - name : Checkout code
60
- uses : actions/checkout@v5
61
- - name : Configure AWS Credentials
62
- uses : aws-actions/configure-aws-credentials@v4
63
- with :
64
- role-to-assume : ${{ env.aws_role }}
65
- aws-region : eu-west-2
66
- - name : get latest snapshot
67
- id : get-latest-snapshot
40
+ - name : Validate inputs
68
41
run : |
69
- set -e
70
- if [ -z "${{ inputs.db_snapshot_arn }}" ]; then
71
- echo "No snapshot ARN provided, fetching the latest snapshot"
72
- SNAPSHOT_ARN=$(aws rds describe-db-cluster-snapshots \
73
- --query "DBClusterSnapshots[?DBClusterIdentifier=='mavis-${{ inputs.environment }}'].[DBClusterSnapshotArn, SnapshotCreateTime]" \
74
- --output text | sort -k2 -r | head -n 1 | cut -f1)
75
-
76
- if [ -z "$SNAPSHOT_ARN" ]; then
77
- echo "No snapshots found for mavis-${{ inputs.environment }}"
78
- exit 1
79
- fi
80
- else
81
- echo "Using provided snapshot ARN: ${{ inputs.db_snapshot_arn }}"
82
- SNAPSHOT_ARN="${{ inputs.db_snapshot_arn }}"
42
+ if [[ "${{ inputs.environment }}" == "preview" || "${{ inputs.environment }}" == "production" ]]; then
43
+ if [[ -z "${{ inputs.git_ref_to_deploy }}" ]]; then
44
+ echo "Error: git_ref_to_deploy is required for preview and production environments."
45
+ exit 1
46
+ fi
83
47
fi
84
- echo "Using snapshot ARN: $SNAPSHOT_ARN"
85
- echo "SNAPSHOT_ARN=$SNAPSHOT_ARN" >> $GITHUB_OUTPUT
86
- - name : Install terraform
87
- uses : hashicorp/setup-terraform@v3
88
- with :
89
- terraform_version : 1.11.4
90
- outputs :
91
- SNAPSHOT_ARN : ${{ steps.get-latest-snapshot.outputs.SNAPSHOT_ARN }}
92
-
93
- prepare-webapp :
94
- name : Prepare webapp
48
+ determine-git-sha :
95
49
runs-on : ubuntu-latest
96
- permissions :
97
- id-token : write
50
+ permissions : { }
51
+ needs : validate-inputs
52
+ outputs :
53
+ git-sha : ${{ steps.get-git-sha.outputs.git-sha }}
98
54
steps :
99
55
- name : Checkout code
100
56
uses : actions/checkout@v5
101
- - name : Configure AWS Credentials
102
- uses : aws-actions/configure-aws-credentials@v4
103
57
with :
104
- role-to-assume : ${{ env.aws_role }}
105
- aws-region : eu-west-2
106
- - name : ECR login
107
- id : login-ecr
108
- uses : aws-actions/amazon-ecr-login@v2
109
- - name : Get docker image digest
110
- id : get-docker-image-digest
111
- run : |
112
- set -e
113
- DOCKER_IMAGE="${{ steps.login-ecr.outputs.registry }}/mavis/webapp:${{ inputs.image_tag || github.sha }}"
114
- docker pull "$DOCKER_IMAGE"
115
- DOCKER_DIGEST=$(docker inspect --format='{{index .RepoDigests 0}}' "$DOCKER_IMAGE")
116
- DIGEST="${DOCKER_DIGEST#*@}"
117
- echo "DIGEST=$DIGEST" >> $GITHUB_OUTPUT
118
- outputs :
119
- DOCKER_DIGEST : ${{ steps.get-docker-image-digest.outputs.DIGEST }}
120
-
121
- plan :
122
- name : Terraform plan
123
- runs-on : ubuntu-latest
124
- needs :
125
- - prepare-db-replica
126
- - prepare-webapp
127
- if : ${{ !cancelled() &&
128
- (needs.prepare-db-replica.result == 'success' || needs.prepare-db-replica.result == 'skipped') &&
129
- needs.prepare-webapp.result == 'success' }}
130
- env :
131
- SNAPSHOT_ARN : ${{ needs.prepare-db-replica.outputs.SNAPSHOT_ARN }}
132
- DB_SECRET_ARN : ${{ needs.prepare-db-replica.outputs.DB_SECRET_ARN || 'arn:aws:secretsmanager:eu-west-2:000000000000:secret:placeholder' }}
133
- DOCKER_DIGEST : ${{ needs.prepare-webapp.outputs.DOCKER_DIGEST }}
134
- REPLACE_DB_CLUSTER : ${{ inputs.deployment_type == 'Deployment with DB recreation' }}
58
+ ref : ${{ inputs.git_ref_to_deploy || github.sha }}
59
+ - name : Get git sha
60
+ id : get-git-sha
61
+ run : echo "git-sha=$(git rev-parse HEAD)" >> $GITHUB_OUTPUT
62
+ build-and-push-image :
135
63
permissions :
136
64
id-token : write
137
- steps :
138
- - name : Checkout code
139
- uses : actions/checkout@v5
140
- - name : Configure AWS Credentials
141
- uses : aws-actions/configure-aws-credentials@v4
142
- with :
143
- role-to-assume : ${{ env.aws_role }}
144
- aws-region : eu-west-2
145
- - name : Install terraform
146
- uses : hashicorp/setup-terraform@v3
147
- with :
148
- terraform_version : 1.11.4
149
- - name : Get db secret arn
150
- id : get-db-secret-arn
151
- working-directory : terraform/app
152
- run : |
153
- terraform init -backend-config="env/${{ inputs.environment }}-backend.hcl" -upgrade
154
- DB_SECRET_ARN=$(terraform output --raw db_secret_arn)
155
- echo "DB_SECRET_ARN=$DB_SECRET_ARN" >> $GITHUB_OUTPUT
156
- - name : Terraform Plan
157
- id : plan
158
- run : |
159
- set -eo pipefail
160
- terraform init -backend-config="env/${{ inputs.environment }}-backend.hcl" -upgrade
161
-
162
- CIDR_BLOCKS='${{ inputs.egress_cidr }}'
163
- PLAN_ARGS=(
164
- "plan"
165
- "-var=image_digest=${{ env.DOCKER_DIGEST }}"
166
- "-var=db_secret_arn=${{ steps.get-db-secret-arn.outputs.DB_SECRET_ARN }}"
167
- "-var=imported_snapshot=${{ env.SNAPSHOT_ARN }}"
168
- "-var-file=env/${{ inputs.environment }}.tfvars"
169
- "-var=allowed_egress_cidr_blocks=$CIDR_BLOCKS"
170
- "-out=${{ runner.temp }}/tfplan"
171
- )
172
-
173
- if [ "${{ env.REPLACE_DB_CLUSTER }}" = "true" ]; then
174
- PLAN_ARGS+=("-replace" "aws_rds_cluster.cluster")
175
- fi
176
- terraform "${PLAN_ARGS[@]}" | tee ${{ runner.temp }}/tf_stdout
177
- - name : Upload artifact
178
- uses : actions/upload-artifact@v4
179
- with :
180
- name : tfplan_infrastructure-${{ inputs.environment }}
181
- path : ${{ runner.temp }}/tfplan
182
-
183
- apply :
184
- name : Terraform apply
185
- runs-on : ubuntu-latest
186
- needs : plan
187
- if : ${{ !cancelled() && needs.plan.result == 'success' }}
188
- environment : ${{ inputs.environment }}
65
+ needs : determine-git-sha
66
+ uses : ./.github/workflows/build-and-push-image.yml
67
+ with :
68
+ git-sha : ${{ needs.determine-git-sha.outputs.git-sha }}
69
+ deploy-application :
189
70
permissions :
190
71
id-token : write
191
- steps :
192
- - name : Checkout code
193
- uses : actions/checkout@v5
194
- - name : Configure AWS Credentials
195
- uses : aws-actions/configure-aws-credentials@v4
196
- with :
197
- role-to-assume : ${{ env.aws_role }}
198
- aws-region : eu-west-2
199
- - name : Download artifact
200
- uses : actions/download-artifact@v5
201
- with :
202
- name : tfplan_infrastructure-${{ inputs.environment }}
203
- path : ${{ runner.temp }}
204
- - name : Install terraform
205
- uses : hashicorp/setup-terraform@v3
206
- with :
207
- terraform_version : 1.11.4
208
- - name : Apply the changes
209
- run : |
210
- set -e
211
- terraform init -backend-config="env/${{ inputs.environment }}-backend.hcl" -upgrade
212
- terraform apply ${{ runner.temp }}/tfplan
213
- - name : Deploy db-access-service
214
- run : |
215
- task_definition_arn=$(terraform output -raw task_definition_arn)
216
- aws ecs update-service \
217
- --cluster mavis-${{ inputs.environment }}-data-replication \
218
- --service mavis-${{ inputs.environment }}-data-replication \
219
- --task-definition $task_definition_arn
72
+ needs : determine-git-sha
73
+ uses : ./.github/workflows/deploy-application.yml
74
+ with :
75
+ environment : ${{ inputs.environment }}
76
+ server_types : data-replication
77
+ git_sha_to_deploy : ${{ needs.determine-git-sha.outputs.git-sha }}
78
+ app_version : ${{ inputs.git_ref_to_deploy }}
0 commit comments