-
Notifications
You must be signed in to change notification settings - Fork 0
102 lines (93 loc) · 4.73 KB
/
deploy-release.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
######################################################
# Deploy a current release (ie: swap deployment slots)
# when a release is published
######################################################
name: Publish release (swap deployment slots)
on:
workflow_dispatch:
release:
types:
- published
env:
# app insights app/api used to indicate deployment
PLAYGROUND_AZURE_APPINSIGHTS_APPID: a9cbc1ce-0afc-4732-99f5-1927d4c3cba1
PLAYGROUND_AZURE_APPINSIGHTS_APPKEY: h66cl408ch83hk3cwmv5706f1tqrypxfpk45hleb
# function app settings
# AZURE_FUNCTIONAPP_RESOURCEGROUP: <secret>
# AZURE_FUNCTIONAPP_NAME: <secret>
AZURE_FUNCTION_APP_STAGING_DEPLOYMENT_SLOT: staging
# credentials for bot with contributor rights on resource group
# PLAYGROUND_BOT_AZURE_TENANTID: <secret>
# PLAYGROUND_BOT_AZURE_CLIENTID: <secret>
# PLAYGROUND_BOT_AZURE_CLIENTSECRET: <secret>
#
# 1. deploy the release
# 2. update the app setting for the production slot to be the
# current tag name
#
jobs:
update-prod-slot-settings:
name: Update Azure Function app settings
runs-on: ubuntu-latest
steps:
######################################################################
# login to Azure CLI via service principal
######################################################################
- name: 🔑 Login to Azure
run: az login --service-principal --tenant $BOT_TENANT_ID --username $BOT_CLIENT_ID --password $BOT_CLIENT_SECRET
env:
BOT_TENANT_ID: ${{ secrets.PLAYGROUND_BOT_AZURE_TENANTID }}
BOT_CLIENT_ID: ${{ secrets.PLAYGROUND_BOT_AZURE_CLIENTID }}
BOT_CLIENT_SECRET: ${{ secrets.PLAYGROUND_BOT_AZURE_CLIENTSECRET }}
######################################################################
# update azure function app setting to commit hash
######################################################################
- name: 📄 Set Azure Function app's app setting "APP_VERSION" & "COMMIT_HASH"
run: |
az functionapp config appsettings set --resource-group $FUNCTION_APP_RESOURCE_GROUP --name $FUNCTION_APP_NAME --slot-settings "APP_VERSION=$SLOT_SETTING__APP_VERSION" "COMMIT_HASH=$SLOT_SETTING__COMMIT_HASH"
env:
FUNCTION_APP_RESOURCE_GROUP: ${{ secrets.AZURE_FUNCTIONAPP_RESOURCEGROUP }}
FUNCTION_APP_NAME: ${{ secrets.AZURE_FUNCTIONAPP_NAME }}
SLOT_SETTING__APP_VERSION: ${{ github.event.release.tag_name }}
SLOT_SETTING__COMMIT_HASH: ${{ github.sha }}
swap-deployment-slots:
name: Swap Azure Function deployment slots
runs-on: ubuntu-latest
needs: update-prod-slot-settings
steps:
######################################################################
# login to Azure CLI via service principal
######################################################################
- name: 🔑 Login to Azure
run: az login --service-principal --tenant $BOT_TENANT_ID --username $BOT_CLIENT_ID --password $BOT_CLIENT_SECRET
env:
BOT_TENANT_ID: ${{ secrets.PLAYGROUND_BOT_AZURE_TENANTID }}
BOT_CLIENT_ID: ${{ secrets.PLAYGROUND_BOT_AZURE_CLIENTID }}
BOT_CLIENT_SECRET: ${{ secrets.PLAYGROUND_BOT_AZURE_CLIENTSECRET }}
######################################################################
# swap deployment slots
######################################################################
- name: 🔀 Swap staging & production deployment slot
run: |
az functionapp deployment slot swap --resource-group $FUNCTION_APP_RESOURCE_GROUP --name $FUNCTION_APP_NAME --slot $FUNCTION_APP_STAGING_SLOT --target-slot $FUNCTION_APP_PRODUCTION_SLOT
env:
FUNCTION_APP_RESOURCE_GROUP: ${{ secrets.AZURE_FUNCTIONAPP_RESOURCEGROUP }}
FUNCTION_APP_NAME: ${{ secrets.AZURE_FUNCTIONAPP_NAME }}
FUNCTION_APP_STAGING_SLOT: ${{ env.AZURE_FUNCTION_APP_STAGING_DEPLOYMENT_SLOT }}
FUNCTION_APP_PRODUCTION_SLOT: production
annotate_appinsights:
name: Annotate deployment to Azure AppInsights
runs-on: ubuntu-latest
needs: swap-deployment-slots
steps:
######################################################################
# add release annotation to Azure App Insights
######################################################################
- name: 📄 Annotate deployment to Azure Application Insights
uses: wictorwilen/application-insights-action@v1
with:
applicationId: ${{ secrets.PLAYGROUND_AZURE_APPINSIGHTS_APPID }}
apiKey: ${{ secrets.PLAYGROUND_AZURE_APPINSIGHTS_APPKEY }}
releaseName: Deployed v${{ github.event.release.tag_name }}
message: Swapped staging & production slots
actor: ${{ github.actor }}