-
Notifications
You must be signed in to change notification settings - Fork 3
268 lines (230 loc) · 8.4 KB
/
azure-dev.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
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
on:
push:
branches:
- main
pull_request:
concurrency:
group: ${{ github.workflow }}-${{ github.event.pull_request.number || github.ref }}
cancel-in-progress: true
name: Test and deploy
permissions:
contents: read
issues: read
id-token: write
actions: write
checks: write
pull-requests: write
# Set up environment variables
env:
IMAGE_NAME: data-management-suite/web-${{ vars.AZURE_ENV_NAME }}
IMAGE_TAG: ${{ github.sha }}
LATEST_IMAGE_TAG: latest
CONTAINER_REGISTRY_ADDRESS: ${{ vars.AZURE_CONTAINER_REGISTRY_NAME }}.azurecr.io
FULL_IMAGE_NAME: ${{ vars.AZURE_CONTAINER_REGISTRY_NAME }}.azurecr.io/data-management-suite/web-${{ vars.AZURE_ENV_NAME }}:${{ github.sha }}
PLAYWRIGHT_USER_PASSWORD: ${{ secrets.PLAYWRIGHT_USER_PASSWORD }}
jobs:
end2endtest:
name: End 2 end test
timeout-minutes: 10
runs-on: ubuntu-latest
services:
# Label used to access the service container
postgres:
# Docker Hub image
image: postgis/postgis:15-3.3
# Provide the password for postgres
env:
POSTGRES_PASSWORD: postgres
POSTGRES_USER: postgres
POSTGRES_DB: remix
# Set health checks to wait until postgres has started
options: >-
--health-cmd pg_isready
--health-interval 10s
--health-timeout 5s
--health-retries 5
ports:
# Maps tcp port 5432 on service container to the host
- 5432:5432
env:
DATABASE_URL: 'postgresql://postgres:postgres@localhost:5432/remix'
SESSION_SECRET: super-duper-s3cret
NODE_VERSION: 18
steps:
- name: 🛑 Cancel Previous Runs
uses: styfle/[email protected]
with:
access_token: ${{ github.token }}
- name: ⬇️ Checkout repo
uses: actions/checkout@v3
- name: ⎔ Setup node
uses: actions/setup-node@v3
with:
node-version: ${{ env.NODE_VERSION }}
- name: 📥 Download deps
uses: bahmutov/npm-install@v1
- name: 🛠 Setup Database
run: npx prisma migrate reset --force
- name: 🌱 Seed the Database
run: npx prisma db seed
- name: ⚙️ Build
run: npm run build
- name: Install Playwright Browsers
run: npx playwright install --with-deps
- name: Run Playwright tests
run: npx remix-serve ./build/index.js & npx playwright test
env:
AZURE_TENANT_ID: ${{ vars.ARM_TENANT_ID }}
AZURE_CLIENT_ID: ${{ vars.AZURE_APP_CLIENT_ID }}
AZURE_CLIENT_SECRET: ${{ secrets.AZURE_APP_CLIENT_SECRET }}
- name: Upload artifacts
uses: actions/upload-artifact@v3
if: always()
with:
name: playwright-report
path: playwright-report/
retention-days: 30
provision:
runs-on: ubuntu-latest
needs:
- end2endtest
if: github.actor != 'dependabot[bot]'
defaults:
run:
shell: bash
# We keep Terraform files in the infra directory.
working-directory: ./infra
env:
ARM_CLIENT_ID: ${{ vars.ARM_CLIENT_ID }}
ARM_CLIENT_SECRET: ${{ secrets.ARM_CLIENT_SECRET }}
ARM_SUBSCRIPTION_ID: ${{ vars.AZURE_SUBSCRIPTION_ID }}
ARM_TENANT_ID: ${{ vars.AZURE_TENANT_ID }}
AZURE_ENV_NAME: dev
RS_RESOURCE_GROUP: ${{ vars.RS_RESOURCE_GROUP }}
RS_STORAGE_ACCOUNT: ${{ vars.RS_STORAGE_ACCOUNT }}
RS_CONTAINER_NAME: ${{ vars.RS_CONTAINER_NAME }}
TF_VAR_location: ${{ vars.AZURE_LOCATION }}
TF_VAR_environment_name: dev
TF_VAR_database_password: ${{ secrets.DATABASE_PASSWORD }}
TF_VAR_session_secret: ${{ secrets.SESSION_SECRET }}
TF_VAR_app_client_id: ${{ vars.AZURE_APP_CLIENT_ID }}
TF_VAR_app_client_secret: ${{ secrets.AZURE_APP_CLIENT_SECRET }}
TF_VAR_web_app_exists: true
steps:
- name: Checkout
uses: actions/checkout@v2
- name: Login to Azure
uses: azure/login@v1
with:
creds: '${{ secrets.AZURE_CREDENTIALS }}'
- name: Install Terraform
uses: hashicorp/setup-terraform@v1
with:
terraform_version: '1.5.7'
- name: Terraform Init
id: init
run: |
terraform init \
-backend-config="storage_account_name=${{ env.RS_STORAGE_ACCOUNT }}" \
-backend-config="container_name=${{ env.RS_CONTAINER_NAME }}" \
-backend-config="key=data-management-suite/${{ env.AZURE_ENV_NAME }}/azdremotestate.tfstate" \
-backend-config="resource_group_name=${{ env.RS_RESOURCE_GROUP }}"
- name: Terraform format
id: fmt
run: terraform fmt -check
- name: Terraform validate
id: validate
run: terraform validate
- name: Terraform plan
id: plan
if: github.event_name == 'pull_request'
run: terraform plan -no-color -input=false
continue-on-error: true
- uses: actions/github-script@v6
if: github.event_name == 'pull_request'
env:
PLAN: "terraform\n${{ steps.plan.outputs.stdout }}"
with:
script: |
const output = `#### Terraform Format and Style 🖌\`${{ steps.fmt.outcome }}\`
#### Terraform Initialization ⚙️\`${{ steps.init.outcome }}\`
#### Terraform Validation 🤖\`${{ steps.validate.outcome }}\`
#### Terraform Plan 📖\`${{ steps.plan.outcome }}\`
<details><summary>Show Plan</summary>
\`\`\`\n
${process.env.PLAN}
\`\`\`
</details>
*Pushed by: @${{ github.actor }}, Action: \`${{ github.event_name }}\`*`;
github.rest.issues.createComment({
issue_number: context.issue.number,
owner: context.repo.owner,
repo: context.repo.repo,
body: output
})
- name: Terraform Plan Status
if: steps.plan.outcome == 'failure'
run: exit 1
- name: Terraform Apply
if: github.ref == 'refs/heads/main' && github.event_name == 'push'
run: terraform apply -auto-approve -input=false
- name: Get outputs
if: github.ref == 'refs/heads/main' && github.event_name == 'push'
uses: dflook/terraform-output@v1
id: outputs
with:
path: ./infra
backend_config: |
storage_account_name=${{ env.RS_STORAGE_ACCOUNT }}
container_name=${{ env.RS_CONTAINER_NAME }}
key=data-management-suite/${{ env.AZURE_ENV_NAME }}/azdremotestate.tfstate
resource_group_name=${{ env.RS_RESOURCE_GROUP }}
outputs:
azure_container_registry_name: ${{ steps.outputs.outputs.azure_container_registry_name }}
container_app_name: ${{ steps.outputs.outputs.container_app_name }}
resource_group_name: ${{ steps.outputs.outputs.resource_group_name }}
container_app_environment_name: ${{ steps.outputs.outputs.container_app_environment_name }}
web_container_name: ${{ steps.outputs.outputs.web_container_name }}
build:
name: Build and push container image
runs-on: ubuntu-latest
needs:
- end2endtest
if: github.ref == 'refs/heads/main' && github.event_name == 'push'
steps:
- name: Checkout
uses: actions/checkout@v2
- name: Login to Azure
uses: azure/login@v1
with:
creds: '${{ secrets.AZURE_CREDENTIALS }}'
- name: Login to ACR
run: |
az acr login --name ${{ vars.AZURE_CONTAINER_REGISTRY_NAME }}
- name: Build and push container image
run: |
docker build -t ${{ env.FULL_IMAGE_NAME }} .
docker push ${{ env.FULL_IMAGE_NAME }}
deploy:
runs-on: ubuntu-latest
if: github.ref == 'refs/heads/main' && github.event_name == 'push'
env:
AZURE_LOCATION: ${{ vars.AZURE_LOCATION }}
AZURE_SUBSCRIPTION_ID: ${{ vars.AZURE_SUBSCRIPTION_ID }}
needs:
- build
- provision
steps:
- name: Checkout
uses: actions/checkout@v2
- name: Login to Azure
uses: azure/login@v1
with:
creds: '${{ secrets.AZURE_CREDENTIALS }}'
- name: Update Container image
run: |
az containerapp update \
--name ${{ needs.provision.outputs.container_app_name }} \
--resource-group ${{ needs.provision.outputs.resource_group_name }} \
--container-name web \
--image ${{ env.FULL_IMAGE_NAME }}