forked from oh-sless-t2/ice-cream-infrastructure
-
Notifications
You must be signed in to change notification settings - Fork 2
178 lines (145 loc) · 7.13 KB
/
deployInfra.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
# This is a basic workflow to help you get started with Actions
name: Deploy Infra
on:
workflow_dispatch:
inputs:
RG:
description: "Resource Group to deploy to"
default: "team2App-devenv"
required: true
type: choice
options:
- team2App-devenv
- team2App-bluedevenv
- team2App-greendevenv
ApiName:
description: "Api Name"
default: "Ratings"
required: true
ResNameSeed:
description: "Resource Name Seed"
default: "icecream"
required: true
WebTrafficRestrict:
description: "Restrict web traffic from APIM to AzFnApp"
type: boolean
default: "false"
required: true
runner:
description: "GitHub runner"
default: "ubuntu-latest"
required: true
type: choice
options:
- open-hack
- ubuntu-latest
env:
#RG: "team2App-devenv" #The resource group we're deploying to.
#ParamFilePath: ".github/workflows_dep/AksDeploy-Basic.parameters.json" #Path to parameter file
#RESNAME: "Ratings" #Used in Azure Resource Naming, overrides the default in the parameter file
DEPNAME: "Dep${{ github.run_number }}" #Deployment Name
AZCLIVERSION: latest #2.30.0 #Pinning to a specific AZ CLI version
jobs:
Deploy_GitHubHosted:
if: github.event.inputs.runner != 'open-hack'
concurrency: ci-${{ github.event.inputs.RG }}
runs-on: ${{ github.event.inputs.runner }} #self-hosted #ubuntu-latest
steps:
- uses: actions/checkout@v2
- name: Job parameter check
run: |
echo "RG is: ${{ github.event.inputs.RG }}"
echo "ApiName is: ${{ github.event.inputs.ApiName }}"
echo "ResNameSeed is: ${{ github.event.inputs.ResNameSeed }}"
echo "Runner is ${{ github.event.inputs.runner }}"
echo "WebTrafficRestrict is: ${{ github.event.inputs.WebTrafficRestrict }}"
echo "Deployment name is ${{ env.DEPNAME }}"
echo "Ref is ${{ github.ref }}"
echo "EventTrigger name is ${{github.event_name}}"
echo "AZCLIVERSION is ${{ env.AZCLIVERSION }}"
echo "Inputs are ${{ tojson(github.event.inputs) }}"
- name: Azure Login
uses: Azure/login@v1
with:
creds: ${{ secrets.AZURE_CREDENTIALS }}
enable-AzPSSession: true
environment: azurecloud
allow-no-subscriptions: false
- name: Validate Infrastructure deployment
uses: Azure/cli@1.0.4
with:
azcliversion: ${{ env.AZCLIVERSION }}
inlineScript: |
RG="${{ github.event.inputs.RG }}"
RESNAME="${{ github.event.inputs.ApiName }}"
ResNameSeed="${{ github.event.inputs.ResNameSeed }}"
WebTrafficRestrict="${{ github.event.inputs.WebTrafficRestrict }}"
az deployment group validate -f main.bicep -g $RG -p appName=$RESNAME resNameSeed=$ResNameSeed restrictTrafficToJustAPIM=$WebTrafficRestrict
- name: Deploy Infrastructure
id: deployInfra
uses: Azure/cli@1.0.4
with:
azcliversion: ${{ env.AZCLIVERSION }}
inlineScript: |
RG="${{ github.event.inputs.RG }}"
RESNAME="${{ github.event.inputs.ApiName }}"
ResNameSeed="${{ github.event.inputs.ResNameSeed }}"
WebTrafficRestrict="${{ github.event.inputs.WebTrafficRestrict }}"
az deployment group create -f main.bicep -g $RG -p appName=$RESNAME resNameSeed=$ResNameSeed restrictTrafficToJustAPIM=$WebTrafficRestrict --name $DEPNAME
DEPSTATUS=$(az deployment operation group list --resource-group $RG --name $DEPNAME) #--query "[?properties.provisioningState=='Failed']"
echo $DEPSTATUS
#outputs
APPURL=$(az deployment group show -n $DEPNAME -g $RG --query "properties.outputs.appUrl.value" -o tsv)
echo "APPURL returned from az deployment = $APPURL"
echo "::set-output name=APPURL::$APPURL"
APPNAME=$(az deployment group show -n $DEPNAME -g $RG --query "properties.outputs.appName.value" -o tsv)
echo "APPNAME returned from az deployment = $APPNAME"
echo "::set-output name=APPNAME::$APPNAME"
#My runner doesn't want/need/like the docker tooling - so we're not going to do any clever actions.
#Just normal AZ CLI Commands here :)
Deploy_SelfHosted:
if: github.event.inputs.runner == 'open-hack'
concurrency: ci-${{ github.event.inputs.RG }}
runs-on: ${{ github.event.inputs.runner }} #self-hosted #ubuntu-latest
steps:
- uses: actions/checkout@v2
- name: Job parameter check
run: |
echo "RG is: ${{ github.event.inputs.RG }}"
echo "ApiName is: ${{ github.event.inputs.ApiName }}"
echo "ResNameSeed is: ${{ github.event.inputs.ResNameSeed }}"
echo "Runner is ${{ github.event.inputs.runner }}"
echo "WebTrafficRestrict is: ${{ github.event.inputs.WebTrafficRestrict }}"
echo "Deployment name is ${{ env.DEPNAME }}"
echo "Ref is ${{ github.ref }}"
echo "EventTrigger name is ${{github.event_name}}"
echo "AZCLIVERSION is ${{ env.AZCLIVERSION }}"
echo "Inputs are ${{ tojson(github.event.inputs) }}"
- name: Azure Login MSI
if: github.event.inputs.runner == 'open-hack'
run: |
az login --identity
- name: Validate Infrastructure deployment
run: |
RG="${{ github.event.inputs.RG }}"
RESNAME="${{ github.event.inputs.ApiName }}"
ResNameSeed="${{ github.event.inputs.ResNameSeed }}"
WebTrafficRestrict="${{ github.event.inputs.WebTrafficRestrict }}"
az deployment group validate -f main.bicep -g $RG -p appName=$RESNAME resNameSeed=$ResNameSeed restrictTrafficToJustAPIM=$WebTrafficRestrict
- name: Deploy Infrastructure
id: deployInfra
run: |
RG="${{ github.event.inputs.RG }}"
RESNAME="${{ github.event.inputs.ApiName }}"
ResNameSeed="${{ github.event.inputs.ResNameSeed }}"
WebTrafficRestrict="${{ github.event.inputs.WebTrafficRestrict }}"
az deployment group create -f main.bicep -g $RG -p appName=$RESNAME resNameSeed=$ResNameSeed restrictTrafficToJustAPIM=$WebTrafficRestrict --name $DEPNAME
DEPSTATUS=$(az deployment operation group list --resource-group $RG --name $DEPNAME) #--query "[?properties.provisioningState=='Failed']"
echo $DEPSTATUS
#outputs
APPURL=$(az deployment group show -n $DEPNAME -g $RG --query "properties.outputs.appUrl.value" -o tsv)
echo "APPURL returned from az deployment = $APPURL"
echo "::set-output name=APPURL::$APPURL"
APPNAME=$(az deployment group show -n $DEPNAME -g $RG --query "properties.outputs.appName.value" -o tsv)
echo "APPNAME returned from az deployment = $APPNAME"
echo "::set-output name=APPNAME::$APPNAME"