-
Notifications
You must be signed in to change notification settings - Fork 96
180 lines (153 loc) · 6.21 KB
/
azure-ipam-testing.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
name: Azure IPAM Testing
# permissions:
# id-token: write
# contents: read
run-name: Azure IPAM Deployment & Testing
on:
push:
branches: [ github-actions ]
pull_request:
branches: [ main ]
env:
ACR_NAME: azureipamtest
IPAM_UI_ID: ipam-ui-${{ github.run_id }}-${{ github.run_attempt }}
IPAM_ENGINE_ID: ipam-engine-${{ github.run_id }}-${{ github.run_attempt }}
jobs:
deploy:
name: Deploy Azure IPAM
runs-on: ubuntu-latest
outputs:
ipamURL: ${{ steps.pwshScript.outputs.ipamURL }}
ipamUIAppId: ${{ steps.pwshScript.outputs.ipamUIAppId }}
ipamEngineAppId: ${{ steps.pwshScript.outputs.ipamEngineAppId }}
ipamSuffix: ${{ steps.pwshScript.outputs.ipamSuffix }}
ipamResourceGroup: ${{ steps.pwshScript.outputs.ipamResourceGroup }}
steps:
- run: echo "Job triggered by a ${{ github.event_name }} event from ${{ github.head_ref }} to main."
- name: Install Deployment Prerequisites
shell: pwsh
run: |
Set-PSRepository PSGallery -InstallationPolicy Trusted
Install-Module Az, Microsoft.Graph, powershell-yaml -AllowClobber -Force
# - name: "Azure Login"
# uses: azure/login@v1
# with:
# client-id: ${{ secrets.AZURE_CLIENT_ID }}
# subscription-id: ${{ secrets.AZURE_SUBSCRIPTION_ID }}
# tenant-id: ${{ secrets.AZURE_TENANT_ID }}
# enable-AzPSSession: true
- name: Azure Login
uses: azure/login@v1
with:
creds: ${{ secrets.AZURE_CREDENTIALS }}
enable-AzPSSession: true
- name: Checkout Azure IPAM Code
uses: actions/checkout@v3
with:
sparse-checkout: |
deploy
engine
ui
lb
- name: Build Azure IPAM Containers
run: |
az acr build -r $ACR_NAME -t ipam-engine:${{ github.run_id }}-${{ github.run_attempt }} -f ./engine/Dockerfile.deb ./engine
az acr build -r $ACR_NAME -t ipam-func:${{ github.run_id }}-${{ github.run_attempt }} -f ./engine/Dockerfile.func ./engine
az acr build -r $ACR_NAME -t ipam-ui:${{ github.run_id }}-${{ github.run_attempt }} -f ./ui/Dockerfile.deb ./ui
az acr build -r $ACR_NAME -t ipam-lb:${{ github.run_id }}-${{ github.run_attempt }} -f ./lb/Dockerfile ./lb
- name: Update Docker-Compose YAML
shell: pwsh
run: |
$composeFile = Get-Content -Path ./docker-compose.prod.yml
$composeYaml = $composeFile | ConvertFrom-Yaml
$composeYaml['services']['ipam-ui'].image = "$env:ACR_NAME.azurecr.io/ipam-ui:${{ github.run_id }}-${{ github.run_attempt }}"
$composeYaml['services']['ipam-engine'].image = "$env:ACR_NAME".azurecr.io/ipam-engine:${{ github.run_id }}-${{ github.run_attempt }}"
$composeYaml['services']['nginx-proxy'].image = "$env:ACR_NAME".azurecr.io/ipam-lb:${{ github.run_id }}-${{ github.run_attempt }}"
$composeYaml | ConvertTo-Yaml | Out-File -Path ./docker-compose-prod.yml
- name: Deploy Azure IPAM
working-directory: "deploy"
id: "pwshScript"
shell: pwsh
run: ./deploy.ps1 -Location "westus3" -UIAppName $Env:IPAM_UI_ID -EngineAppName $Env:IPAM_ENGINE_ID
- name: "Output PowerShell Value 'ipamSuffix'"
run: echo "${{ steps.pwshScript.outputs.ipamSuffix }}"
- name: "Upload Logs"
working-directory: logs
shell: pwsh
run: |
$dateStamp = (Get-Date -UFormat "%Y-%m-%d_%I-%M-%S_%p").tostring()
$archiveName = "ipam-${dateStamp}.zip"
Compress-Archive -Pat ./* -DestinationPath /tmp/$archiveName
$storage = Get-AzStorageAccount -Name "ipamghactionlogs" -ResourceGroupName "Logging-RG"
$context = $storage.Context
$uploadDetails = @{
File = "/tmp/$archiveName"
Container = "deploy-logs"
Blob = $archiveName
Context = $context
StandardBlobTier = "Hot"
}
Set-AzStorageBlobContent @uploadDetails
- run: echo "${{ github.job }} status is ${{ job.status }}."
sleep:
name: Sleep for 5 Minutes
runs-on: ubuntu-latest
needs: deploy
steps:
- name: Test Sleepy Time
run: |
echo "Time: $(date +'%T')"
echo "Sleeping for 30 seconds"
sleep 30
echo "Time: $(date +'%T')"
test:
name: Test Azure IPAM via Pester
runs-on: ubuntu-latest
needs: [ deploy, sleep ]
steps:
- name: Install Testing Prerequisites
shell: pwsh
run: |
Set-PSRepository PSGallery -InstallationPolicy Trusted
Install-Module Az, Pester -AllowClobber -Force
- name: Azure Login
uses: azure/login@v1
with:
creds: ${{ secrets.AZURE_CREDENTIALS }}
enable-AzPSSession: true
- name: Checkout Azure IPAM Code
uses: actions/checkout@v3
with:
sparse-checkout: |
tests
- name: Invoke Pester Tests
working-directory: tests
env:
IPAM_RESOURCE_GROUP: ${{ needs.deploy.outputs.ipamResourceGroup }}
IPAM_URL: ${{ needs.deploy.outputs.ipamURL }}
IPAM_ENGINE_APP_ID: ${{ needs.deploy.outputs.ipamEngineAppId }}
shell: pwsh
run: |
Import-Module Pester -PassThru
Invoke-Pester -Output Detailed ./azureipam.tests.ps1 -PassThru
cleanup:
name: Cleanup Azure IPAM Deployment
runs-on: ubuntu-latest
needs: [ deploy, sleep, test ]
steps:
- name: Install Deployment Prerequisites
shell: pwsh
run: |
Set-PSRepository PSGallery -InstallationPolicy Trusted
Install-Module Az -AllowClobber -Force
- name: Azure Login
uses: azure/login@v1
with:
creds: ${{ secrets.AZURE_CREDENTIALS }}
enable-AzPSSession: true
- name : Cleanup Azure IPAM Deployment
shell: pwsh
run: |
Remove-AzResourceGroup -Name ${{ needs.deploy.outputs.ipamResourceGroup }} -Force
Get-AzADApplication -ApplicationId ${{ needs.deploy.outputs.ipamUIAppId }} | Remove-AzADApplication
Get-AzADApplication -ApplicationId ${{ needs.deploy.outputs.ipamEngineAppId }} | Remove-AzADApplication