-
Notifications
You must be signed in to change notification settings - Fork 0
164 lines (144 loc) · 5.33 KB
/
main-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
name: Main build & deploy
on:
workflow_dispatch:
push:
branches: ["main"]
paths:
- 'src/**'
- '.github/workflows/main-build-and-deploy.yml'
jobs:
set-env:
runs-on: ubuntu-22.04
name: Set Environment Values
outputs:
branch: ${{ steps.var.outputs.branch }}
checked-out-sha: ${{ steps.var.outputs.checked-out-sha }}
steps:
- uses: actions/checkout@v4
with:
ref: ${{ github.ref }}
- id: var
run: |
GIT_BRANCH=${GITHUB_BASE_REF:-${GITHUB_REF#refs/heads/}}
CHECKED_OUT_SHA="$(git log -1 '--format=format:%H')"
echo "branch=$GIT_BRANCH" >> $GITHUB_OUTPUT
echo "checked-out-sha=${CHECKED_OUT_SHA}" >> $GITHUB_OUTPUT
create-and-publish-image:
needs: set-env
name: Create & Publish Image
uses: ./.github/workflows/build-image.yml
secrets: inherit
with:
branch: ${{ needs.set-env.outputs.branch }}
checked-out-sha: ${{ needs.set-env.outputs.checked-out-sha }}
deploy-to-dev:
runs-on: ubuntu-22.04
needs: create-and-publish-image
name: Deploy to development
environment: development
# Permissions for OIDC authentication
permissions:
id-token: write
contents: write
issues: write
steps:
- name: Check out repository
uses: actions/checkout@v4
# Login to Azure using OIDC
- name: Login to Azure CLI
uses: azure/login@v2
with:
client-id: ${{ secrets.AZURE_CLIENT_ID }}
tenant-id: ${{ secrets.AZURE_TENANT_ID }}
subscription-id: ${{ secrets.AZURE_SUBSCRIPTION_ID }}
# Deploy Web Application to slot
- name: Deploy to Azure App Services slot
uses: azure/webapps-deploy@v3
with:
app-name: ${{ vars.WEBAPP_NAME }}
images: ${{ needs.create-and-publish-image.outputs.dockerImageTag }}
slot-name: "${{ vars.WEBAPP_SLOT_NAME }}"
# Make a request to the health check endpoint
- name: Make request to health check endpoint
uses: ./.github/actions/health-check
with:
webapp_name: ${{ vars.WEBAPP_NAME }}
slot_name: ${{ vars.WEBAPP_SLOT_NAME }}
# Swap the slots
- name: Swap to the production slot
run: |
az webapp deployment slot swap --resource-group ${{ vars.RESOURCE_NAME_PREFIX }}-rg --name ${{ vars.WEBAPP_NAME }} --slot ${{ vars.WEBAPP_SLOT_NAME }} --target-slot production
deploy-to-staging:
runs-on: ubuntu-22.04
needs: [create-and-publish-image, deploy-to-dev]
name: Deploy to staging
environment: staging
# Permissions for OIDC authentication
permissions:
id-token: write
contents: write
issues: write
steps:
- name: Check out repository
uses: actions/checkout@v4
# Login to Azure using OIDC
- name: Login to Azure CLI
uses: azure/login@v2
with:
client-id: ${{ secrets.AZURE_CLIENT_ID }}
tenant-id: ${{ secrets.AZURE_TENANT_ID }}
subscription-id: ${{ secrets.AZURE_SUBSCRIPTION_ID }}
# Deploy Web Application
- name: Deploy to Azure App Services
uses: azure/webapps-deploy@v3
with:
app-name: ${{ vars.WEBAPP_NAME }}
images: ${{ needs.create-and-publish-image.outputs.dockerImageTag }}
slot-name: "${{ vars.WEBAPP_SLOT_NAME }}"
# Make a request to the health check endpoint
- name: Make request to health check endpoint
uses: ./.github/actions/health-check
with:
webapp_name: ${{ vars.WEBAPP_NAME }}
slot_name: ${{ vars.WEBAPP_SLOT_NAME }}
# Swap the slots
- name: Swap to the production slot
run: |
az webapp deployment slot swap --resource-group ${{ vars.RESOURCE_NAME_PREFIX }}-rg --name ${{ vars.WEBAPP_NAME }} --slot ${{ vars.WEBAPP_SLOT_NAME }} --target-slot production
deploy-to-production:
runs-on: ubuntu-22.04
needs: [create-and-publish-image, deploy-to-staging]
name: Deploy to production
environment: production
# Permissions for OIDC authentication
permissions:
id-token: write
contents: write
issues: write
steps:
- name: Check out repository
uses: actions/checkout@v4
# Login to Azure using OIDC
- name: Login to Azure CLI
uses: azure/login@v2
with:
client-id: ${{ secrets.AZURE_CLIENT_ID }}
tenant-id: ${{ secrets.AZURE_TENANT_ID }}
subscription-id: ${{ secrets.AZURE_SUBSCRIPTION_ID }}
# Deploy Web Application
- name: Deploy to Azure App Services
uses: azure/webapps-deploy@v3
with:
app-name: ${{ vars.WEBAPP_NAME }}
images: ${{ needs.create-and-publish-image.outputs.dockerImageTag }}
slot-name: "${{ vars.WEBAPP_SLOT_NAME }}"
# Make a request to the health check endpoint
- name: Make request to health check endpoint
uses: ./.github/actions/health-check
with:
webapp_name: ${{ vars.WEBAPP_NAME }}
slot_name: ${{ vars.WEBAPP_SLOT_NAME }}
# Swap the slots
- name: Swap to the production slot
run: |
az webapp deployment slot swap --resource-group ${{ vars.RESOURCE_NAME_PREFIX }}-rg --name ${{ vars.WEBAPP_NAME }} --slot ${{ vars.WEBAPP_SLOT_NAME }} --target-slot production