forked from AzureArcForKubernetes/azure-cli-extensions
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathk8s-custom-pipelines.yml
344 lines (296 loc) · 12.2 KB
/
k8s-custom-pipelines.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
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
trigger:
batch: true
branches:
include:
- k8s-extension/public
- k8s-extension/private
pr:
branches:
include:
- k8s-extension/public
- k8s-extension/private
stages:
- stage: BuildTestPublishExtension
displayName: "Build, Test, and Publish Extension"
variables:
TEST_PATH: $(Agent.BuildDirectory)/s/testing
CLI_REPO_PATH: $(Agent.BuildDirectory)/s
SUBSCRIPTION_ID: "15c06b1b-01d6-407b-bb21-740b8617dea3"
RESOURCE_GROUP: "K8sPartnerExtensionTest"
BASE_CLUSTER_NAME: "k8s-extension-cluster"
IS_PRIVATE_BRANCH: $[or(eq(variables['Build.SourceBranch'], 'refs/heads/k8s-extension/private'), eq(variables['System.PullRequest.TargetBranch'], 'k8s-extension/private'))]
EXTENSION_NAME: "k8s-extension"
EXTENSION_FILE_NAME: "k8s_extension"
jobs:
- job: K8sExtensionTestSuite
displayName: "Run the Test Suite"
pool:
vmImage: 'ubuntu-latest'
steps:
- checkout: self
- bash: |
echo "Installing helm3"
curl -fsSL -o get_helm.sh https://raw.githubusercontent.com/helm/helm/master/scripts/get-helm-3
chmod 700 get_helm.sh
./get_helm.sh
echo "Installing kubectl"
curl -LO "https://storage.googleapis.com/kubernetes-release/release/$(curl -s https://storage.googleapis.com/kubernetes-release/release/stable.txt)/bin/linux/amd64/kubectl"
chmod +x ./kubectl
sudo mv ./kubectl /usr/local/bin/kubectl
kubectl version --client
displayName: "Setup the VM with helm3 and kubectl"
- task: UsePythonVersion@0
displayName: 'Use Python 3.6'
inputs:
versionSpec: 3.6
- bash: |
set -ev
echo "Building extension ${EXTENSION_NAME}..."
# prepare and activate virtualenv
pip install virtualenv
python3 -m venv env/
source env/bin/activate
# clone azure-cli
git clone -q --single-branch -b dev https://github.com/Azure/azure-cli.git ../azure-cli
pip install --upgrade pip
pip install -q azdev
ls $(CLI_REPO_PATH)
azdev --version
azdev setup -c ../azure-cli -r $(CLI_REPO_PATH) -e $(EXTENSION_NAME)
azdev extension build $(EXTENSION_NAME)
workingDirectory: $(CLI_REPO_PATH)
displayName: "Setup and Build Extension with azdev"
- bash: |
K8S_EXTENSION_VERSION=$(ls ${EXTENSION_FILE_NAME}* | cut -d "-" -f2)
echo "##vso[task.setvariable variable=K8S_EXTENSION_VERSION]$K8S_EXTENSION_VERSION"
cp * $(TEST_PATH)/bin
workingDirectory: $(CLI_REPO_PATH)/dist
displayName: "Copy the Built .whl to Extension Test Path"
- bash: |
RAND_STR=$RANDOM
AKS_CLUSTER_NAME="${BASE_CLUSTER_NAME}-${RAND_STR}-aks"
ARC_CLUSTER_NAME="${BASE_CLUSTER_NAME}-${RAND_STR}-arc"
JSON_STRING=$(jq -n \
--arg SUB_ID "$SUBSCRIPTION_ID" \
--arg RG "$RESOURCE_GROUP" \
--arg AKS_CLUSTER_NAME "$AKS_CLUSTER_NAME" \
--arg ARC_CLUSTER_NAME "$ARC_CLUSTER_NAME" \
--arg K8S_EXTENSION_VERSION "$K8S_EXTENSION_VERSION" \
'{subscriptionId: $SUB_ID, resourceGroup: $RG, aksClusterName: $AKS_CLUSTER_NAME, arcClusterName: $ARC_CLUSTER_NAME, extensionVersion: {"k8s-extension": $K8S_EXTENSION_VERSION, connectedk8s: "1.0.0"}}')
echo $JSON_STRING > settings.json
cat settings.json
workingDirectory: $(TEST_PATH)
displayName: "Generate a settings.json file"
- bash : |
echo "Downloading the kind script"
curl -Lo ./kind https://kind.sigs.k8s.io/dl/v0.9.0/kind-linux-amd64
chmod +x ./kind
./kind create cluster
displayName: "Create and Start the Kind cluster"
- bash: |
curl -sL https://aka.ms/InstallAzureCLIDeb | sudo bash
displayName: "Upgrade az to latest version"
- task: AzureCLI@2
displayName: Bootstrap
inputs:
azureSubscription: AzureResourceConnection
scriptType: pscore
scriptLocation: inlineScript
inlineScript: |
.\Bootstrap.ps1 -CI
workingDirectory: $(TEST_PATH)
- task: AzureCLI@2
displayName: Run the Test Suite Public Extensions Only
inputs:
azureSubscription: AzureResourceConnection
scriptType: pscore
scriptLocation: inlineScript
inlineScript: |
.\Test.ps1 -CI -OnlyPublicTests -Type k8s-extension
workingDirectory: $(TEST_PATH)
continueOnError: true
condition: and(succeeded(), eq(variables['IS_PRIVATE_BRANCH'], 'False'))
- task: AzureCLI@2
displayName: Run the Test Suite on Private + Public Extensions
inputs:
azureSubscription: AzureResourceConnection
scriptType: pscore
scriptLocation: inlineScript
inlineScript: |
.\Test.ps1 -CI -Type k8s-extension
workingDirectory: $(TEST_PATH)
continueOnError: true
condition: and(succeeded(), eq(variables['IS_PRIVATE_BRANCH'], 'True'))
- task: PublishTestResults@2
inputs:
testResultsFormat: 'JUnit'
testResultsFiles: '**/testing/results/*.xml'
failTaskOnFailedTests: true
condition: succeededOrFailed()
- task: AzureCLI@2
displayName: Cleanup
inputs:
azureSubscription: AzureResourceConnection
scriptType: pscore
scriptLocation: inlineScript
inlineScript: |
.\Cleanup.ps1 -CI
workingDirectory: $(TEST_PATH)
condition: succeededOrFailed()
- job: BuildPublishExtension
pool:
vmImage: 'ubuntu-latest'
displayName: "Build and Publish the Extension Artifact"
variables:
CLI_REPO_PATH: $(Agent.BuildDirectory)/s
steps:
- bash: |
echo "Using the private preview of k8s-extension to build..."
cp $(CLI_REPO_PATH)/src/k8s-extension $(CLI_REPO_PATH)/src/k8s-extension-private -r
mv $(CLI_REPO_PATH)/src/k8s-extension-private/azext_k8s_extension $(CLI_REPO_PATH)/src/k8s-extension-private/azext_k8s_extension_private
cp $(CLI_REPO_PATH)/src/k8s-extension-private/setup_private.py $(CLI_REPO_PATH)/src/k8s-extension-private/setup.py
cp $(CLI_REPO_PATH)/src/k8s-extension-private/azext_k8s_extension_private/consts_private.py $(CLI_REPO_PATH)/src/k8s-extension-private/azext_k8s_extension_private/consts.py
EXTENSION_NAME="k8s-extension-private"
EXTENSION_FILE_NAME="k8s_extension_private"
echo "##vso[task.setvariable variable=EXTENSION_NAME]$EXTENSION_NAME"
echo "##vso[task.setvariable variable=EXTENSION_FILE_NAME]$EXTENSION_FILE_NAME"
condition: and(succeeded(), eq(variables['IS_PRIVATE_BRANCH'], 'True'))
displayName: "Copy Files, Set Variables for k8s-extension-private"
- bash: |
echo "Using the public version of k8s-extension to build..."
EXTENSION_NAME="k8s-extension"
EXTENSION_FILE_NAME="k8s_extension"
echo "##vso[task.setvariable variable=EXTENSION_NAME]$EXTENSION_NAME"
echo "##vso[task.setvariable variable=EXTENSION_FILE_NAME]$EXTENSION_FILE_NAME"
condition: and(succeeded(), eq(variables['IS_PRIVATE_BRANCH'], 'False'))
displayName: "Copy Files, Set Variables for k8s-extension"
- task: UsePythonVersion@0
displayName: 'Use Python 3.6'
inputs:
versionSpec: 3.6
- bash: |
set -ev
echo "Building extension ${EXTENSION_NAME}..."
# prepare and activate virtualenv
pip install virtualenv
python3 -m venv env/
source env/bin/activate
# clone azure-cli
git clone -q --single-branch -b dev https://github.com/Azure/azure-cli.git ../azure-cli
pip install --upgrade pip
pip install -q azdev
ls $(CLI_REPO_PATH)
azdev --version
azdev setup -c ../azure-cli -r $(CLI_REPO_PATH) -e $(EXTENSION_NAME)
azdev extension build $(EXTENSION_NAME)
workingDirectory: $(CLI_REPO_PATH)
displayName: "Setup and Build Extension with azdev"
- task: PublishBuildArtifacts@1
inputs:
pathToPublish: $(CLI_REPO_PATH)/dist
- stage: AzureCLIOfficial
displayName: "Azure Official CLI Code Checks"
dependsOn: []
jobs:
- job: CheckLicenseHeader
displayName: "Check License"
pool:
vmImage: 'ubuntu-latest'
steps:
- task: UsePythonVersion@0
displayName: 'Use Python 3.6'
inputs:
versionSpec: 3.6
- bash: |
set -ev
# prepare and activate virtualenv
python -m venv env/
chmod +x ./env/bin/activate
source ./env/bin/activate
# clone azure-cli
git clone -q --single-branch -b dev https://github.com/Azure/azure-cli.git ../azure-cli
pip install --upgrade pip
pip install -q azdev
azdev setup -c ../azure-cli -r ./
azdev --version
az --version
azdev verify license
- job: StaticAnalysis
displayName: "Static Analysis"
pool:
vmImage: 'ubuntu-latest'
steps:
- task: UsePythonVersion@0
displayName: 'Use Python 3.6'
inputs:
versionSpec: 3.6
- bash: pip install wheel==0.30.0 pylint==1.9.5 flake8==3.5.0 requests
displayName: 'Install wheel, pylint, flake8, requests'
- bash: python scripts/ci/source_code_static_analysis.py
displayName: "Static Analysis"
- job: IndexVerify
displayName: "Verify Extensions Index"
pool:
vmImage: 'ubuntu-latest'
steps:
- task: UsePythonVersion@0
displayName: 'Use Python 3.7'
inputs:
versionSpec: 3.7
- bash: |
#!/usr/bin/env bash
set -ev
pip install wheel==0.30.0 requests packaging
export CI="ADO"
python ./scripts/ci/test_index.py -v
displayName: "Verify Extensions Index"
- job: SourceTests
displayName: "Integration Tests, Build Tests"
pool:
vmImage: 'ubuntu-latest'
strategy:
matrix:
Python36:
python.version: '3.6'
Python38:
python.version: '3.8'
steps:
- task: UsePythonVersion@0
displayName: 'Use Python $(python.version)'
inputs:
versionSpec: '$(python.version)'
- bash: pip install wheel==0.30.0
displayName: 'Install wheel==0.30.0'
- bash: ./scripts/ci/test_source.sh
displayName: 'Run integration test and build test'
env:
ADO_PULL_REQUEST_LATEST_COMMIT: $(System.PullRequest.SourceCommitId)
ADO_PULL_REQUEST_TARGET_BRANCH: $(System.PullRequest.TargetBranch)
- job: LintModifiedExtensions
displayName: "CLI Linter on Modified Extensions"
pool:
vmImage: 'ubuntu-latest'
steps:
- task: UsePythonVersion@0
displayName: 'Use Python 3.6'
inputs:
versionSpec: 3.6
- bash: |
set -ev
# prepare and activate virtualenv
pip install virtualenv
python -m virtualenv venv/
source ./venv/bin/activate
# clone azure-cli
git clone --single-branch -b dev https://github.com/Azure/azure-cli.git ../azure-cli
pip install --upgrade pip
pip install azdev
azdev --version
azdev setup -c ../azure-cli -r ./ -e k8s-extension
# overwrite the default AZURE_EXTENSION_DIR set by ADO
AZURE_EXTENSION_DIR=~/.azure/cliextensions az --version
AZURE_EXTENSION_DIR=~/.azure/cliextensions azdev linter --include-whl-extensions k8s-extension
displayName: "CLI Linter on Modified Extension"
env:
ADO_PULL_REQUEST_LATEST_COMMIT: $(System.PullRequest.SourceCommitId)
ADO_PULL_REQUEST_TARGET_BRANCH: $(System.PullRequest.TargetBranch)