-
Notifications
You must be signed in to change notification settings - Fork 57
240 lines (200 loc) · 9.28 KB
/
demo_devops.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
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
name: Dapr DevOps Demo
on:
# Triggers the workflow on push
# push:
# Allows you to run this workflow manually from the Actions tab
workflow_dispatch:
env:
# The name of the resource group to be created. All resources will be place
# in the resource group and start with name.
RG_NAME: "dapr_devops_demo"
# The location to store the meta data for the deployment.
LOCATION: "eastus"
#The version of the dapr runtime version to deploy.
DAPR_VERSION: "1.4.3"
# The version of k8s control plane.
K8S_VERSION: "1.24.3"
jobs:
buildImages:
name: build ${{ matrix.app }} image
runs-on: ubuntu-latest
strategy:
matrix:
app: [csharp_provider, csharp_processor, csharp_viewer]
steps:
- name: Checkout
uses: actions/checkout@v2
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v1
- name: Login to DockerHub
uses: docker/login-action@v1
with:
password: ${{ secrets.DOCKERHUB_TOKEN }}
username: ${{ secrets.DOCKERHUB_USERNAME }}
- name: Build and push
id: docker_build
uses: docker/build-push-action@v2
with:
push: true
tags: ${{ secrets.DOCKERHUB_USERNAME }}/${{ matrix.app }}:${{ github.run_number }}
context: ./DevOps/src/${{ matrix.app }}/
- name: Output matrix values
shell: pwsh
id: values
run: |
# Get all the outputs
Write-Output "::set-output name=image::${{ secrets.DOCKERHUB_USERNAME }}/${{ matrix.app }}"
deployInfrastructure:
name: deploy infrastructure
runs-on: ubuntu-latest
steps:
- name: Clone repo
uses: actions/checkout@v2
- name: Install helm
uses: azure/setup-helm@v1
- name: Install Dapr
uses: dapr/setup-dapr@v1
- name: Login to Azure CLI
uses: azure/login@v1
with:
creds: ${{ secrets.AZURE_CREDENTIALS }}
- name: Helm dependency update
shell: pwsh
run: |
helm dependency update ./charts/
working-directory: ./DevOps/
- name: Publish Chart
uses: actions/upload-artifact@v2
with:
name: chart
path: "./DevOps/charts/"
- name: Deploy infrastructure
id: azure-deployment
shell: pwsh
run: |
$rgName = '${{ env.RG_NAME }}'
$deployment = $(az deployment sub create --name $rgName `
--location ${{ env.LOCATION }} `
--template-file main.bicep `
--parameters location=${{ env.LOCATION }} `
--parameters rgName=$rgName `
--parameters k8sversion=${{ env.K8S_VERSION }} `
--output json) | ConvertFrom-Json
$aksName = $deployment.properties.outputs.aksName.value
$serviceBusAuthRule = $deployment.properties.outputs.serviceBusAuthRule.value
$storageAccountName = $deployment.properties.outputs.storageAccountName.value
$instrumentationKey = $deployment.properties.outputs.instrumentationKey.value
$serviceBusNamespace = $deployment.properties.outputs.serviceBusNamespace.value
$cognitiveServiceName = $deployment.properties.outputs.cognitiveServiceName.value
$cognitiveServiceEndpoint = $deployment.properties.outputs.cognitiveServiceEndpoint.value
$serviceBusEndpoint = $(az servicebus namespace authorization-rule keys list `
--name $serviceBusAuthRule `
--namespace-name $serviceBusNamespace `
--resource-group $rgName `
--query primaryConnectionString `
--output tsv)
$storageAccountKey = $(az storage account keys list `
--account-name $storageAccountName `
--query [0].value `
--output tsv)
$cognitiveServiceKey = $(az cognitiveservices account keys list `
--name $cognitiveServiceName `
--resource-group $rgName `
--query key1 `
--output tsv)
# Get all the outputs
Write-Output "::set-output name=aksName::$($aksName)"
Write-Output "::set-output name=storageAccountKey::$($storageAccountKey)"
Write-Output "::set-output name=serviceBusEndpoint::$($serviceBusEndpoint)"
Write-Output "::set-output name=storageAccountName::$($storageAccountName)"
Write-Output "::set-output name=instrumentationKey::$($instrumentationKey)"
Write-Output "::set-output name=cognitiveServiceKey::$($cognitiveServiceKey)"
Write-Output "::set-output name=cognitiveServiceEndpoint::$($cognitiveServiceEndpoint)"
working-directory: ./DevOps/deploy/azure/
- name: Initialize Dapr
shell: pwsh
run: |
Write-Host "${{ steps.azure-deployment.outputs.aksName }}"
# Get the credentials to use with dapr init and helm install
az aks get-credentials --resource-group ${{ env.RG_NAME }} --name "${{ steps.azure-deployment.outputs.aksName }}"
# Initialize Dapr
# Dapr init is very noisy in the logs so group these lines so
# it can be collapsed.
Write-Output "::group::Initialize Dapr"
dapr init --kubernetes --wait --runtime-version ${{ env.DAPR_VERSION }}
Write-Output "::endgroup::"
dapr status --kubernetes
outputs:
aksName: ${{ steps.azure-deployment.outputs.aksName }}
storageAccountKey: ${{ steps.azure-deployment.outputs.storageAccountKey }}
instrumentationKey: ${{ steps.azure-deployment.outputs.instrumentationKey }}
storageAccountName: ${{ steps.azure-deployment.outputs.storageAccountName }}
serviceBusEndpoint: ${{ steps.azure-deployment.outputs.serviceBusEndpoint }}
cognitiveServiceKey: ${{ steps.azure-deployment.outputs.cognitiveServiceKey }}
cognitiveServiceEndpoint: ${{ steps.azure-deployment.outputs.cognitiveServiceEndpoint }}
deployApp:
name: deploy application
needs: [buildImages, deployInfrastructure]
runs-on: ubuntu-latest
steps:
- name: Download Helm chart
uses: actions/download-artifact@v2
with:
name: chart
path: chart
- name: Login to Azure CLI
uses: azure/login@v1
with:
creds: ${{ secrets.AZURE_CREDENTIALS }}
- name: Install helm
uses: azure/setup-helm@v1
- name: Helm upgrade
shell: pwsh
run: |
# Get the credentials to use with dapr init and helm install
az aks get-credentials `
--resource-group ${{ env.RG_NAME }} `
--name "${{ needs.deployInfrastructure.outputs.aksName }}"
# Install the demo into the cluster
helm upgrade --install csharpdemo ./chart `
--set usingPowerShell=True `
--set viewer.image.tag='${{ github.run_number }}' `
--set provider.image.tag='${{ github.run_number }}' `
--set processor.image.tag='${{ github.run_number }}' `
--set viewer.viewer.nodePort='-1' `
--set viewer.viewer.externalPort='80' `
--set viewer.viewer.image='${{ secrets.DOCKERHUB_USERNAME }}/csharp_viewer' `
--set provider.provider.image='${{ secrets.DOCKERHUB_USERNAME }}/csharp_provider' `
--set processor.processor.image='${{ secrets.DOCKERHUB_USERNAME }}/csharp_processor' `
--set components.twitter.consumerKey='${{ secrets.TWITTER_CONSUMERKEY }}' `
--set components.twitter.accessToken='${{ secrets.TWITTER_ACCESSTOKEN }}' `
--set components.twitter.accessSecret='${{ secrets.TWITTER_ACCESSSECRET }}' `
--set components.twitter.consumerSecret='${{ secrets.TWITTER_CONSUMERSECRET }}' `
--set components.tableStorage.key='${{ needs.deployInfrastructure.outputs.storageAccountKey }}' `
--set components.tableStorage.name='${{ needs.deployInfrastructure.outputs.storageAccountName }}' `
--set components.cognitiveService.token='${{ needs.deployInfrastructure.outputs.cognitiveServiceKey }}' `
--set components.serviceBus.connectionString='${{ needs.deployInfrastructure.outputs.serviceBusEndpoint }}' `
--set components.cognitiveService.endpoint='${{ needs.deployInfrastructure.outputs.cognitiveServiceEndpoint }}' `
--set enableAppInsights=true `
--set appinsights.applicationInsights.instrumentationKey='${{ needs.deployInfrastructure.outputs.instrumentationKey }}'
- name: Get IPs
shell: pwsh
run: |
function Get-IP {
[CmdletBinding()]
param (
[string]
$serviceName
)
# Make sure service is ready
$ip = $(kubectl get services $serviceName --output jsonpath='{.status.loadBalancer.ingress[0].ip}')
while ($null -eq $ip) {
Start-Sleep -Seconds 30
$ip = $(kubectl get services $serviceName --output jsonpath='{.status.loadBalancer.ingress[0].ip}')
}
Write-Output $ip
}
# Make sure services are ready
Write-Output "`nGetting IP addresses. Please wait..."
$viewerIp = Get-IP -serviceName viewer
Write-Output "`nYour app is accessible from http://$viewerIp`n"