-
Notifications
You must be signed in to change notification settings - Fork 0
213 lines (186 loc) · 7.9 KB
/
ci.yaml
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
name: Release CI
env:
project-name: mmw
fd-aws-tf-modules-version: v2.23.0
on:
push:
branches: ["main", "pv/reusable"]
tags: ["v*.*.*"]
jobs:
deploy-staging-2:
with:
stage: staging
project-name: mmw
fd-aws-tf-modules-version: v2.23.0
uses: ./.github/workflows/reusable.yml
secrets: inherit
deploy-staging:
environment:
name: staging
url: https://console.staging.modelmywatershed.org
env:
stage: staging
permissions:
id-token: write
contents: read
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- uses: hashicorp/setup-terraform@v3
with:
terraform_version: "1.7.5"
- name: Preparing Environment
id: prep_env
run: |
echo "Creating terraform backend file ..."
echo '' > config.s3.backend.tf
echo 'terraform {' >> config.s3.backend.tf
echo ' backend "s3" {' >> config.s3.backend.tf
echo ' encrypt = true' >> config.s3.backend.tf
echo " bucket = \"${{ secrets.TF_STATE_BUCKET }}\"" >> config.s3.backend.tf
echo " dynamodb_table = \"${{ secrets.TF_STATE_LOCK_TABLE }}\"" >> config.s3.backend.tf
echo " key = \"${{ env.project-name }}-${{ env.stage }}.tfstate\"" >> config.s3.backend.tf
echo " region = \"${{ secrets.AWS_REGION }}\"" >> config.s3.backend.tf
echo ' }' >> config.s3.backend.tf
echo '}' >> config.s3.backend.tf
cat config.s3.backend.tf
echo "Using FilmDrop Terraform ${{ env.fd-aws-tf-modules-version }} release..."
./scripts/retrieve_tf_modules.sh ${{ env.fd-aws-tf-modules-version }}
- name: Configure Terraform Init Credentials
id: init_creds
uses: aws-actions/configure-aws-credentials@v4
with:
aws-region: ${{ secrets.AWS_REGION }}
role-to-assume: ${{ secrets.AWS_ROLE }}
role-session-name: GitHubReleaseInit
- name: Terraform Init
id: tf_init
run: terraform init
- name: Terraform Validate
id: tf_validate
run: terraform validate
- name: Configure Terraform Plan Credentials
id: plan_creds
uses: aws-actions/configure-aws-credentials@v4
with:
aws-region: ${{ secrets.AWS_REGION }}
role-to-assume: ${{ secrets.AWS_ROLE }}
role-session-name: GitHubReleasePlan
- name: Terraform Plan
id: tf_plan
run: terraform plan -var-file="${{ env.stage }}.tfvars" -out ${{ env.stage }}.tfplan -lock=false
- name: Configure Terraform Apply Credentials
id: apply_creds
uses: aws-actions/configure-aws-credentials@v4
with:
aws-region: ${{ secrets.AWS_REGION }}
role-to-assume: ${{ secrets.AWS_ROLE }}
role-session-name: GitHubReleaseApply
- name: Terraform Apply
id: tf_apply
run: terraform apply -lock=false -input=false ${{ env.stage }}.tfplan
- name: Post status to Slack channel
id: tf_apply_successs
if: steps.tf_apply.outcome == 'success'
continue-on-error: true
uses: slackapi/[email protected]
with:
channel-id: ${{ secrets.SLACK_CHANNEL_ID }}
slack-message: ":badger_dance: ${{ env.project-name }}-${{ env.stage }}-titiler ${{ github.ref_name }} terraform apply job has succeeded!\n${{ github.event.pull_request.html_url || github.event.head_commit.url }}"
env:
SLACK_BOT_TOKEN: ${{ secrets.SLACK_BOT_TOKEN }}
- name: Post status to Slack channel
id: tf_apply_failure
if: steps.tf_apply.outcome != 'success'
continue-on-error: true
uses: slackapi/[email protected]
with:
channel-id: ${{ secrets.SLACK_CHANNEL_ID }}
slack-message: ":sadpanda: ${{ env.project-name }}-${{ env.stage }}-titiler ${{ github.ref_name }} terraform apply has failed!\n:alert: make sure cleanup job deletes all AWS resources!\n${{ github.event.pull_request.html_url || github.event.head_commit.url }}"
env:
SLACK_BOT_TOKEN: ${{ secrets.SLACK_BOT_TOKEN }}
deploy-prod:
environment:
name: prod
url: https://console.modelmywatershed.org
env:
stage: prod
permissions:
id-token: write
contents: read
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- uses: hashicorp/setup-terraform@v3
with:
terraform_version: "1.7.5"
- name: Preparing Environment
id: prep_env
run: |
echo "Creating terraform backend file ..."
echo '' > config.s3.backend.tf
echo 'terraform {' >> config.s3.backend.tf
echo ' backend "s3" {' >> config.s3.backend.tf
echo ' encrypt = true' >> config.s3.backend.tf
echo " bucket = \"${{ secrets.TF_STATE_BUCKET }}\"" >> config.s3.backend.tf
echo " dynamodb_table = \"${{ secrets.TF_STATE_LOCK_TABLE }}\"" >> config.s3.backend.tf
echo " key = \"${{ env.project-name }}-${{ env.stage }}.tfstate\"" >> config.s3.backend.tf
echo " region = \"${{ secrets.AWS_REGION }}\"" >> config.s3.backend.tf
echo ' }' >> config.s3.backend.tf
echo '}' >> config.s3.backend.tf
cat config.s3.backend.tf
echo "Using FilmDrop Terraform ${{ env.fd-aws-tf-modules-version }} release..."
./scripts/retrieve_tf_modules.sh ${{ env.fd-aws-tf-modules-version }}
- name: Configure Terraform Init Credentials
id: init_creds
uses: aws-actions/configure-aws-credentials@v4
with:
aws-region: ${{ secrets.AWS_REGION }}
role-to-assume: ${{ secrets.AWS_ROLE }}
role-session-name: GitHubReleaseInit
- name: Terraform Init
id: tf_init
run: terraform init
- name: Terraform Validate
id: tf_validate
run: terraform validate
- name: Configure Terraform Plan Credentials
id: plan_creds
uses: aws-actions/configure-aws-credentials@v4
with:
aws-region: ${{ secrets.AWS_REGION }}
role-to-assume: ${{ secrets.AWS_ROLE }}
role-session-name: GitHubReleasePlan
- name: Terraform Plan
id: tf_plan
run: terraform plan -var-file="${{ env.stage }}.tfvars" -out ${{ env.stage }}.tfplan -lock=false
- name: Configure Terraform Apply Credentials
id: apply_creds
uses: aws-actions/configure-aws-credentials@v4
with:
aws-region: ${{ secrets.AWS_REGION }}
role-to-assume: ${{ secrets.AWS_ROLE }}
role-session-name: GitHubReleaseApply
- name: Terraform Apply
id: tf_apply
run: terraform apply -lock=false -input=false ${{ env.stage }}.tfplan
- name: Post status to Slack channel
id: tf_apply_successs
if: steps.tf_apply.outcome == 'success'
continue-on-error: true
uses: slackapi/[email protected]
with:
channel-id: ${{ secrets.SLACK_CHANNEL_ID }}
slack-message: ":badger_dance: ${{ env.project-name }}-${{ env.stage }}-titiler ${{ github.ref_name }} terraform apply job has succeeded!\n${{ github.event.pull_request.html_url || github.event.head_commit.url }}"
env:
SLACK_BOT_TOKEN: ${{ secrets.SLACK_BOT_TOKEN }}
- name: Post status to Slack channel
id: tf_apply_failure
if: steps.tf_apply.outcome != 'success'
continue-on-error: true
uses: slackapi/[email protected]
with:
channel-id: ${{ secrets.SLACK_CHANNEL_ID }}
slack-message: ":sadpanda: ${{ env.project-name }}-${{ env.stage }}-titiler ${{ github.ref_name }} terraform apply has failed!\n:alert: make sure cleanup job deletes all AWS resources!\n${{ github.event.pull_request.html_url || github.event.head_commit.url }}"
env:
SLACK_BOT_TOKEN: ${{ secrets.SLACK_BOT_TOKEN }}