-
Notifications
You must be signed in to change notification settings - Fork 0
211 lines (188 loc) · 6.76 KB
/
build-and-deploy.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
name: Deploy
on:
push:
branches:
- main
- 652_replicate_test_environment_to_aks
pull_request:
branches:
- main
types:
- labeled
- synchronize
- reopened
- opened
- converted_to_draft
env:
CONTAINER_REGISTRY: ghcr.io
jobs:
docker:
name: Docker build and push
if: contains(github.event.pull_request.labels.*.name, 'deploy') || contains(github.event.pull_request.labels.*.name, 'deploy_v2') || github.event_name != 'pull_request'
runs-on: ubuntu-latest
outputs:
docker_image: ${{ steps.dockerimage.outputs.docker_image_tag }}
steps:
- uses: actions/checkout@v3
- uses: ./.github/workflows/actions/build-docker
id: dockerimage
with:
github_username: ${{ github.actor }}
github_token: ${{ secrets.GITHUB_TOKEN }}
deploy_review:
name: Deploy to review environment
concurrency: deploy_review_${{ github.event.pull_request.number }}
needs: [docker]
runs-on: ubuntu-latest
if: contains(github.event.pull_request.labels.*.name, 'deploy')
environment:
name: review
steps:
- uses: actions/checkout@v3
- uses: ./.github/workflows/actions/deploy-environment
id: deploy
with:
environment_name: review
docker_image: ${{ needs.docker.outputs.docker_image }}
azure_credentials: ${{ secrets.AZURE_CREDENTIALS }}
terraform_vars: workspace_variables/review.tfvars.json
pr_id: ${{ github.event.pull_request.number }}
- name: Post sticky pull request comment
if: github.event_name == 'pull_request'
uses: marocchino/sticky-pull-request-comment@v2
with:
message: |
Review app deployed to ${{ steps.deploy.outputs.environment_url }}
deploy_v2_review:
name: Deploy to review_aks environment
concurrency: deploy_v2_review_${{ github.event.pull_request.number }}
needs: [docker]
runs-on: ubuntu-latest
if: contains(github.event.pull_request.labels.*.name, 'deploy_v2')
environment:
name: review_aks
steps:
- uses: actions/checkout@v3
- uses: ./.github/workflows/actions/deploy_v2
id: deploy_v2
with:
environment: review_aks
docker_image: ${{ needs.docker.outputs.docker_image }}
azure-credentials: ${{ secrets.AZURE_CREDENTIALS }}
arm-access-key: ${{ secrets.ARM_ACCESS_KEY }}
pr-id: ${{ github.event.pull_request.number }}
- name: Post sticky pull request comment
if: github.event_name == 'pull_request'
uses: marocchino/sticky-pull-request-comment@v2
with:
message: |
AKS review app deployed to ${{ steps.deploy_v2.outputs.environment_url }}
deploy_v2_dev:
name: Deploy to development_aks environment
concurrency: deploy_v2_development
needs: [docker]
runs-on: ubuntu-latest
continue-on-error: true
if: github.ref == 'refs/heads/main' && github.event_name == 'push'
environment:
name: development_aks
steps:
- uses: actions/checkout@v3
- uses: ./.github/workflows/actions/deploy_v2
id: deploy_v2
with:
environment: development_aks
docker_image: ${{ needs.docker.outputs.docker_image }}
azure-credentials: ${{ secrets.AZURE_CREDENTIALS }}
arm-access-key: ${{ secrets.ARM_ACCESS_KEY }}
- uses: ./.github/workflows/actions/smoke-test-v2
id: smoke-test
with:
environment: development_aks
azure_credentials: ${{ secrets.AZURE_CREDENTIALS }}
deploy_v2_test:
name: Deploy to test_aks environment
concurrency: deploy_v2_test
needs: [docker]
runs-on: ubuntu-latest
continue-on-error: true
if: contains(github.event.pull_request.labels.*.name, 'deploy_v2')
environment:
name: test_aks
steps:
- uses: actions/checkout@v3
- uses: ./.github/workflows/actions/deploy_v2
id: deploy_v2
with:
environment: test_aks
docker_image: ${{ needs.docker.outputs.docker_image }}
azure-credentials: ${{ secrets.AZURE_CREDENTIALS }}
arm-access-key: ${{ secrets.ARM_ACCESS_KEY }}
- uses: ./.github/workflows/actions/smoke-test-v2
id: smoke-test
with:
environment: test_aks
azure_credentials: ${{ secrets.AZURE_CREDENTIALS }}
deploy_nonprod:
name: Deploy to ${{ matrix.environment }} environment
runs-on: ubuntu-latest
if: github.ref == 'refs/heads/main' && github.event_name == 'push'
concurrency: deploy_${{ matrix.environment }}
needs: [docker]
strategy:
max-parallel: 1
matrix:
environment: [dev, test, preprod]
environment:
name: ${{ matrix.environment }}
url: ${{ steps.deploy.outputs.environment_url }}
outputs:
environment_url: ${{ steps.deploy.outputs.environment_url }}
steps:
- uses: actions/checkout@v3
- name: Docker image tag
id: image
run: |
echo ::set-output name=tag::$CONTAINER_REGISTRY/$(echo $GITHUB_REPOSITORY | tr '[:upper:]' '[:lower:]'):$GITHUB_SHA
env:
CONTAINER_REGISTRY: ${{ env.CONTAINER_REGISTRY }}
shell: bash
- uses: ./.github/workflows/actions/deploy-environment
id: deploy
with:
environment_name: ${{ matrix.environment }}
docker_image: ${{ steps.image.outputs.tag }}
azure_credentials: ${{ secrets.AZURE_CREDENTIALS }}
terraform_vars: workspace_variables/${{ matrix.environment }}.tfvars.json
- uses: ./.github/workflows/actions/smoke-test
id: smoke-test
with:
environment: ${{ matrix.environment }}
azure_credentials: ${{ secrets.AZURE_CREDENTIALS }}
deploy_production:
name: Deploy to production environment
runs-on: ubuntu-latest
if: github.ref == 'refs/heads/main' && github.event_name == 'push'
environment:
name: production
url: ${{ steps.deploy.outputs.environment_url }}
concurrency: deploy_production
needs: [docker, deploy_nonprod]
outputs:
environment_url: ${{ steps.deploy.outputs.environment_url }}
steps:
- uses: actions/checkout@v3
- name: Docker image tag
id: image
run: |
echo ::set-output name=tag::$CONTAINER_REGISTRY/$(echo $GITHUB_REPOSITORY | tr '[:upper:]' '[:lower:]'):$GITHUB_SHA
env:
CONTAINER_REGISTRY: ${{ env.CONTAINER_REGISTRY }}
shell: bash
- uses: ./.github/workflows/actions/deploy-environment
id: deploy
with:
environment_name: production
docker_image: ${{ steps.image.outputs.tag }}
azure_credentials: ${{ secrets.AZURE_CREDENTIALS }}
terraform_vars: workspace_variables/production.tfvars.json