-
Notifications
You must be signed in to change notification settings - Fork 0
118 lines (111 loc) · 4.36 KB
/
vmssupdate.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
name: Blob storage website CI
on:
push:
branches: [ main ]
workflow_dispatch:
jobs:
build:
runs-on: ubuntu-latest
steps:
# Set environment variables
- name: Set a few env vars based on current date and time
run: |
echo "APPVERSION=$(date +'%Y%m%d-%H%M%S')" >> $GITHUB_ENV
echo "SASEXPIRY=$(date -u -d '+6 months' +'%Y-%m-%dT%H:%MZ')" >> $GITHUB_ENV
# Checkout the repo
- uses: actions/checkout@v3
# Build, test, and publish the app
- name: Setup .NET
uses: actions/setup-dotnet@v3
with:
dotnet-version: 7.0.x
- name: Restore dependencies
run: dotnet restore
working-directory: ./app
- name: Build
run: dotnet build --no-restore
working-directory: ./app
- name: Test
run: dotnet test --no-build --verbosity normal
working-directory: ./app
- name: Publish
run: dotnet publish app/app.csproj -c Release -o publishedapp
- name: DEBUG only - print the contents of the publishedapp directory
run: ls -R publishedapp
# We may need artifacts in other jobs. Add the published app to a ZIP file, create artifacts including the scripts to run on the VMSS
- name: Create artifact directory
run: mkdir -p artifacts
# cd into publishedapp so the root folder is not included in the zip file, only the files in it
- name: Zip Published App
uses: montudor/action-zip@v1
with:
args: zip -qq -r artifacts/publishedapp.zip . -i publishedapp/**
- name: Upload a Build Artifact
uses: actions/upload-artifact@v3
with:
name: publishedapp
path: artifacts/publishedapp.zip
if-no-files-found: error
- name: Upload the update script to the artifacts directory
run: cp cse/updateapp.ps1 ./artifacts/updateapp.ps1
# Login to Azure
- uses: azure/login@v1
with:
creds: ${{ secrets.AZURE_CREDENTIALS }}
# Upload artifacts to Blob Storage where destination path is the APPVERSION envvar created earlier
- name: Upload to Blob Storage
uses: azure/CLI@v1
with:
inlineScript: |
az storage blob upload-batch -d ${{ secrets.STORAGE_CONTAINER_NAME}} \
--account-name ${{ secrets.STORAGE_ACCOUNT_NAME }} \
--destination-path $APPVERSION \
--source artifacts
# Generate SAS token for the uploaded artifacts - App
- name: Get published app URI in blob storage
uses: azure/CLI@v1
with:
inlineScript: |
echo "uri=$(az storage blob url --container-name ${{ secrets.STORAGE_CONTAINER_NAME }} \
--account-name ${{ secrets.STORAGE_ACCOUNT_NAME }} \
--name $APPVERSION/publishedapp.zip \
--account-key ${{ secrets.STORAGE_ACCOUNT_KEY }}} \
--output tsv)" >> $GITHUB_OUTPUT
id: appSasUri
# Generate SAS token for the uploaded artifacts - Script
- name: Get ps1 script URI in blob storage
uses: azure/CLI@v1
with:
inlineScript: |
echo "uri=$(az storage blob url --container-name ${{ secrets.STORAGE_CONTAINER_NAME }} \
--account-name ${{ secrets.STORAGE_ACCOUNT_NAME }} \
--name $APPVERSION/updateapp.ps1 \
--account-key ${{ secrets.STORAGE_ACCOUNT_KEY }}} \
--output tsv)" >> $GITHUB_OUTPUT
id: ps1SasUri
# Set the updated customScript extension to run on the VMSS
# use protected-settings so we can add storage account name and key
- name: Set VMSS custom script extension
uses: azure/CLI@v1
with:
inlineScript: |
az vmss extension set \
--publisher Microsoft.Compute \
--version 1.10 \
--name CustomScriptExtension \
--vmss-name ${{ secrets.VMSS_NAME }} \
--resource-group ${{ secrets.VMSS_RG_NAME }} \
--settings '{}' \
--protected-settings '{"fileUris": [ \
"${{ steps.ps1SasUri.outputs.uri }}", \
"${{ steps.appSasUri.outputs.uri }}" \
], \
"storageAccountName": "${{ secrets.STORAGE_ACCOUNT_NAME }}", \
"storageAccountKey": "${{ secrets.STORAGE_ACCOUNT_KEY }}", \
"commandToExecute": "cd ${{ env.APPVERSION }} && powershell.exe -ExecutionPolicy Unrestricted -File updateapp.ps1" \
}'
# Logout from Azure
- name: logout
run: |
az logout
if: always()