forked from thunderbird/appointment
-
Notifications
You must be signed in to change notification settings - Fork 0
235 lines (203 loc) · 8 KB
/
deploy-production.yml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
name: deploy-production
concurrency:
group: deploy-production
cancel-in-progress: true
on:
release:
types: [published]
permissions:
id-token: write # required for OIDC connectiong to AWS
contents: read
jobs:
deploy-prod-iac:
environment: production
if: startsWith(github.ref_name, 'r-') # the prefix we have added to the tag
runs-on: ubuntu-latest
outputs:
bucket: ${{ steps.output-bucket-name.outputs.bucket }}
cloudfront_id: ${{ steps.output-cloudfront-distro.outputs.cloudfront_id }}
env:
TF_VAR_region: ${{ vars.AWS_REGION }}
TF_VAR_environment: ${{ vars.ENV_SHORT_NAME }}
TF_VAR_name_prefix: "tb-${{ vars.PROJECT_SHORT_NAME }}-${{ vars.ENV_SHORT_NAME }}"
TF_VAR_app_env: ${{ vars.APP_ENV }}
TF_VAR_db_enc_secret: ${{ vars.DB_ENCRYPTED_SECRET }}
TF_VAR_frontend_url: ${{ vars.FRONTEND_URL }}
TF_VAR_fxa_secret: ${{ vars.FXA_SECRET }}
TF_VAR_google_oauth_secret: ${{ vars.GOOGLE_OAUTH_SECRET }}
TF_VAR_log_level: ${{ vars.LOG_LEVEL }}
TF_VAR_short_base_url: ${{ vars.SHORT_BASE_URL }}
TF_VAR_smtp_secret: ${{ vars.SMTP_SECRET }}
TF_VAR_zoom_callback: ${{ vars.ZOOM_CALLBACK }}
TF_VAR_zoom_secret: ${{ vars.zoom_secret }}
TF_VAR_sentry_dsn: ${{ vars.SENTRY_DSN }}
TF_VAR_ssl_cert_arn: ${{ vars.SSL_CERT_ARN }}
steps:
- name: Get Artifact from Release
uses: dsaltares/fetch-gh-release-asset@master
with:
version: ${{ github.event.release.id }}
file: iac.zip
- name: Unzip Artifact
run: unzip iac.zip
- name: install opentofu
uses: opentofu/setup-opentofu@v1
with:
tofu_version: ${{ vars.TF_VERSION }}
tofu_wrapper: false
- name: install terragrunt
run: |
sudo wget -q -O /bin/terragrunt "https://github.com/gruntwork-io/terragrunt/releases/download/v${{ vars.TG_VERSION }}/terragrunt_linux_amd64"
sudo chmod +x /bin/terragrunt
terragrunt -v
- name: Configure AWS credentials
uses: aws-actions/configure-aws-credentials@v4
with:
role-to-assume: ${{ secrets.IAM_ROLE }}
role-session-name: Appointment_GitHub_to_AWS_via_FederatedOIDC
aws-region: ${{ vars.AWS_REGION }}
- name: vpc
working-directory: ./tofu/environments/prod/network/vpc
run: |
terragrunt init -upgrade
terragrunt validate
terragrunt plan -out tfplan
terragrunt apply tfplan
- name: backend-infra
working-directory: ./tofu/environments/prod/services/backend-infra
run: |
terragrunt init -upgrade
terragrunt validate
terragrunt plan -out tfplan
terragrunt apply tfplan
- name: cache
working-directory: ./tofu/environments/prod/data-store/cache
run: |
terragrunt init -upgrade
terragrunt validate
terragrunt plan -out tfplan
terragrunt apply tfplan
- name: database
working-directory: ./tofu/environments/prod/data-store/database
run: |
terragrunt init -upgrade
terragrunt validate
terragrunt plan -out tfplan
terragrunt apply tfplan
- name: frontend-infra
working-directory: ./tofu/environments/prod/services/frontend-infra
run: |
terragrunt init -upgrade
terragrunt validate
terragrunt plan -out tfplan
terragrunt apply tfplan
- name: output-bucket-name
id: output-bucket-name
working-directory: ./tofu/environments/prod/services/frontend-infra
run: |
terragrunt init -upgrade
output=$(terragrunt output bucket_name | tr -d '"')
echo bucket=$output >> $GITHUB_OUTPUT
- name: output-cloudfront-distro
id: output-cloudfront-distro
working-directory: ./tofu/environments/prod/services/frontend-infra
run: |
terragrunt init -upgrade
output=$(terragrunt output cloudfront_id)
echo cloudfront_id=$output >> $GITHUB_OUTPUT
deploy-prod-frontend:
needs: deploy-prod-iac
if: startsWith(github.ref_name, 'r-') # the prefix we have added to the tag
environment: production
runs-on: ubuntu-latest
steps:
- name: Get Artifact from Release
uses: dsaltares/fetch-gh-release-asset@master
with:
version: ${{ github.event.release.id }}
file: frontend.zip
- name: Unzip Artifact
run: unzip frontend.zip
- name: Configure AWS credentials
uses: aws-actions/configure-aws-credentials@v4
with:
role-to-assume: ${{ secrets.IAM_ROLE }}
role-session-name: Appointment_GitHub_to_AWS_via_FederatedOIDC
aws-region: ${{ vars.AWS_REGION }}
- name: Deploy frontend to S3
run: aws s3 sync ./dist "s3://${{ needs.deploy-prod-iac.outputs.bucket }}"
- name: Invalidate Cloudfront cache
run: aws cloudfront create-invalidation --distribution-id ${{ needs.deploy-prod-iac.outputs.cloudfront_id }} --paths "/*"
deploy-prod-backend:
needs: deploy-prod-iac
if: startsWith(github.ref_name, 'r-') # the prefix we have added to the tag
environment: production
runs-on: ubuntu-latest
env:
TF_VAR_region: ${{ vars.AWS_REGION }}
TF_VAR_environment: ${{ vars.ENV_SHORT_NAME }}
TF_VAR_name_prefix: "tb-${{ vars.PROJECT_SHORT_NAME }}-${{ vars.ENV_SHORT_NAME }}"
TF_VAR_app_env: ${{ vars.APP_ENV }}
TF_VAR_db_enc_secret: ${{ vars.DB_ENCRYPTED_SECRET }}
TF_VAR_frontend_url: ${{ vars.FRONTEND_URL }}
TF_VAR_fxa_secret: ${{ vars.FXA_SECRET }}
TF_VAR_google_oauth_secret: ${{ vars.GOOGLE_OAUTH_SECRET }}
TF_VAR_log_level: ${{ vars.LOG_LEVEL }}
TF_VAR_short_base_url: ${{ vars.SHORT_BASE_URL }}
TF_VAR_smtp_secret: ${{ vars.SMTP_SECRET }}
TF_VAR_zoom_callback: ${{ vars.ZOOM_CALLBACK }}
TF_VAR_zoom_secret: ${{ vars.zoom_secret }}
TF_VAR_sentry_dsn: ${{ vars.SENTRY_DSN }}
TF_VAR_ssl_cert_arn: ${{ vars.SSL_CERT_ARN }}
steps:
- name: Get IaC from Release
uses: dsaltares/fetch-gh-release-asset@master
with:
version: ${{ github.event.release.id }}
file: iac.zip
- name: Get ECR tag from Release
uses: dsaltares/fetch-gh-release-asset@master
with:
version: ${{ github.event.release.id }}
file: ecr_tag.zip
- name: Unzip IaC
run: unzip iac.zip
- name: Unzip ECR tag
id: get_ecr_tag
run: |
unzip ecr_tag.zip
output=$(cat ecr_tag.txt)
echo ecr_tag=$output >> $GITHUB_OUTPUT
- name: install opentofu
uses: opentofu/setup-opentofu@v1
with:
tofu_version: ${{ vars.TF_VERSION }}
tofu_wrapper: false
- name: install terragrunt
run: |
sudo wget -q -O /bin/terragrunt "https://github.com/gruntwork-io/terragrunt/releases/download/v${{ vars.TG_VERSION }}/terragrunt_linux_amd64"
sudo chmod +x /bin/terragrunt
terragrunt -v
- name: Configure AWS credentials
uses: aws-actions/configure-aws-credentials@v4
with:
role-to-assume: ${{ secrets.IAM_ROLE }}
role-session-name: Appointment_GitHub_to_AWS_via_FederatedOIDC
aws-region: ${{ vars.AWS_REGION }}
- name: Prepare backend dependencies
run: |
cd tofu/environments/prod/network/vpc
terragrunt init -upgrade
cd ../../data-store/database
terragrunt init -upgrade
cd ../../data-store/cache
terragrunt init -upgrade
cd ../../services/backend-infra
terragrunt init -upgrade
- name: Deploy Backend
working-directory: ./tofu/environments/prod/services/backend-service
run: |
terragrunt init -upgrade
terragrunt validate
terragrunt plan -var "image=${{ steps.get_ecr_tag.outputs.ecr_tag }}" -out tfplan
terragrunt apply tfplan