-
Notifications
You must be signed in to change notification settings - Fork 0
132 lines (117 loc) Β· 5.94 KB
/
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
on:
push:
branches:
- 'main'
paths:
- 'src/**'
- 'infra/**'
workflow_dispatch:
name: π Deploy
env:
DOTNET_VERSION: '6.0'
ARTIFACT_DIR: './artifacts'
jobs:
deploy-infra:
name: ποΈ Deploy Infrastructure
runs-on: ubuntu-latest
outputs:
apiDataAppName: ${{ steps.deploy.outputs.apiDataAppName }}
simulationAppName: ${{ steps.deploy.outputs.simulationAppName }}
patchesListenSecretUrl: ${{ steps.deploy.outputs.patchesListenSecretUrl }}
patchesSendSecretUrl: ${{ steps.deploy.outputs.patchesSendSecretUrl }}
ingressListenSecretUrl: ${{ steps.deploy.outputs.ingressListenSecretUrl }}
ingressSendSecretUrl: ${{ steps.deploy.outputs.ingressSendSecretUrl }}
azureDigitalTwinsEndpoint: ${{ steps.deploy.outputs.azureDigitalTwinsEndpoint }}
azureDigitalTwinsName: ${{ steps.deploy.outputs.azureDigitalTwinsName }}
tableEndpoint: ${{ steps.deploy.outputs.tableEndpoint }}
eventGridTopicName: ${{ steps.deploy.outputs.eventGridTopicName }}
functionAppName: ${{ steps.deploy.outputs.functionAppName }}
steps:
- uses: actions/checkout@v3
- name: π Azure Login
uses: azure/login@v1
with:
creds: ${{ secrets.AZURE_CREDENTIALS }}
- name: ποΈ Deploy
id: deploy
uses: azure/arm-deploy@v1
with:
subscriptionId: ${{ secrets.AZURE_SUBSCRIPTION_ID }}
resourceGroupName: ${{ secrets.AZURE_RESOURCE_GROUP_NAME }}
template: ./infra/main.bicep
parameters: 'tenantId=${{ secrets.AZURE_TENANT_ID }} principalId=${{ secrets.AZURE_CLIENT_ID }}'
failOnStdErr: false
build-code:
name: π’ Build Code
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@main
- name: π§ Setup DotNet ${{ env.DOTNET_VERSION }} Environment
uses: actions/setup-dotnet@v1
with:
dotnet-version: ${{ env.DOTNET_VERSION }}
- name: ποΈ Build Solution
shell: pwsh
run: |
mkdir ${{ env.ARTIFACT_DIR }}
dotnet publish ./src/CopyTheWorld/CopyTheWorld.sln --configuration Release
Compress-Archive -Path ./src/CopyTheWorld/CopyTheWorld.ApiData/bin/Release/net6.0/publish/* -DestinationPath ${{ env.ARTIFACT_DIR }}/CopyTheWorld.ApiData.zip
Compress-Archive -Path ./src/CopyTheWorld/CopyTheWorld.Functions/bin/Release/net6.0/publish/* -DestinationPath ${{ env.ARTIFACT_DIR }}/CopyTheWorld.Functions.zip
Compress-Archive -Path ./src/CopyTheWorld/CopyTheWorld.Simulations/bin/Release/net6.0/publish/* -DestinationPath ${{ env.ARTIFACT_DIR }}/CopyTheWorld.Simulations.zip
- name: β¬οΈ Upload Artifact
uses: actions/upload-artifact@v3
with:
name: artifacts
path: ${{ env.ARTIFACT_DIR }}
deploy-code:
name: π Deploy Code
runs-on: ubuntu-latest
needs: [build-code, deploy-infra]
steps:
- name: β¬οΈ Download artifacts
uses: actions/download-artifact@v3
with:
name: artifacts
- name: π Azure Login
uses: azure/login@v1
with:
creds: ${{ secrets.AZURE_CREDENTIALS }}
- name: πΎ Install Azure IoT Extension
shell: pwsh
run: az extension add -n azure-iot
- name: πͺ§ Configure event routes
shell: pwsh
run: |
az dt route create -n ${{ needs.deploy-infra.outputs.azureDigitalTwinsName }} -g ${{ secrets.AZURE_RESOURCE_GROUP_NAME }} --en changes --rn twin-updates --filter "type = 'Microsoft.DigitalTwins.Twin.Update'"
- name: π Deploy ApiData Function
shell: pwsh
run: |
az functionapp deploy --resource-group ${{ secrets.AZURE_RESOURCE_GROUP_NAME }} --name ${{ needs.deploy-infra.outputs.apiDataAppName }} --src-path CopyTheWorld.ApiData.zip --type zip
az functionapp config appsettings set -g ${{ secrets.AZURE_RESOURCE_GROUP_NAME }} -n ${{ needs.deploy-infra.outputs.apiDataAppName }} --settings "[email protected](SecretUri=${{ needs.deploy-infra.outputs.patchesSendSecretUrl }})" "AdtEndpoint=${{ needs.deploy-infra.outputs.azureDigitalTwinsEndpoint }}"
- name: π Deploy Simulations Function
shell: pwsh
run: |
az functionapp deploy --resource-group ${{ secrets.AZURE_RESOURCE_GROUP_NAME }} --name ${{ needs.deploy-infra.outputs.simulationAppName }} --src-path CopyTheWorld.Simulations.zip --type zip
- name: π Deploy Core Functions
shell: pwsh
run: |
az functionapp deploy --resource-group ${{ secrets.AZURE_RESOURCE_GROUP_NAME }} --name ${{ needs.deploy-infra.outputs.functionAppName }} --src-path CopyTheWorld.Functions.zip --type zip
az functionapp config appsettings set -g ${{ secrets.AZURE_RESOURCE_GROUP_NAME }} -n ${{ needs.deploy-infra.outputs.functionAppName }} --settings "[email protected](SecretUri=${{ needs.deploy-infra.outputs.patchesListenSecretUrl }})" "[email protected](SecretUri=${{ needs.deploy-infra.outputs.patchesSendSecretUrl }})" "[email protected](SecretUri=${{ needs.deploy-infra.outputs.ingressListenSecretUrl }})" "AdtEndpoint=${{ needs.deploy-infra.outputs.azureDigitalTwinsEndpoint }}" "TableEndpoint=${{ needs.deploy-infra.outputs.tableEndpoint }}" "TableName=mapping"
deploy-event-grid-subscriptions:
name: π Deploy Event Grid Subscriptions
runs-on: ubuntu-latest
needs: [deploy-code, deploy-infra]
steps:
- uses: actions/checkout@v3
- name: π Azure Login
uses: azure/login@v1
with:
creds: ${{ secrets.AZURE_CREDENTIALS }}
- name: ποΈ Deploy
id: deploy
uses: azure/arm-deploy@v1
with:
subscriptionId: ${{ secrets.AZURE_SUBSCRIPTION_ID }}
resourceGroupName: ${{ secrets.AZURE_RESOURCE_GROUP_NAME }}
template: ./infra/event-grid-subscriptions.bicep
parameters: './infra/parameters/event-grid-subscriptions.json functionAppName=${{ needs.deploy-infra.outputs.functionAppName }} eventGridTopicName=${{ needs.deploy-infra.outputs.eventGridTopicName }}'