forked from vmware/photon-os-installer
-
Notifications
You must be signed in to change notification settings - Fork 0
384 lines (332 loc) · 15.8 KB
/
Copy pathpoi-vcf.yml
File metadata and controls
384 lines (332 loc) · 15.8 KB
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
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
name: photon-os-installer CI on VCF
on:
push:
workflow_dispatch:
env:
POI_IMAGE_NAME_BASE: photon/installer
GITHUB_BRANCH: master
POI_REGISTRY: poi-registry:5000
jobs:
lint-checks:
runs-on: self-hosted
steps:
- name: Checkout code
uses: actions/checkout@v3
- name: Lint checks
run: |
VENV_DIR="$(mktemp -d /var/tmp/venv.XXXXXX)"
python3 -m venv "$VENV_DIR"
"$VENV_DIR/bin/pip" install isort black flake8 shellcheck-py --index-url https://packages.vcfd.broadcom.net/artifactory/api/pypi/pypi/simple/
export PATH="$VENV_DIR/bin:$PATH"
bash lint-checks.sh
STATUS=$?
rm -r "$VENV_DIR"
exit $STATUS
dialog-tests:
runs-on: self-hosted
steps:
- name: Checkout code
uses: actions/checkout@v3
- name: Run interactive installer dialog tests
run: |
VENV_DIR="$(mktemp -d /var/tmp/venv.XXXXXX)"
# --without-pip + a --python-targeted install avoids relying on
# ensurepip's bundled wheels, which aren't available for every
# python3 in this runner fleet.
python3 -m venv --without-pip "$VENV_DIR"
# requirements.txt is needed too: the dialog code under test
# (photon_installer/commandutils.py, installer.py) imports
# requests/yaml/OpenSSL/jc transitively, even though the tests
# themselves never touch the network/disk/packages.
python3 -m pip --python "$VENV_DIR/bin/python3" install -r requirements.txt pytest pexpect --index-url https://packages.vcfd.broadcom.net/artifactory/api/pypi/pypi/simple/
"$VENV_DIR/bin/pytest" -x tests/test_iso_dialogs.py
STATUS=$?
rm -r "$VENV_DIR"
exit $STATUS
build-container:
runs-on: [ self-hosted, "docker:root" ]
steps:
- name: Checkout code
uses: actions/checkout@v3
- name: Build Docker image
run: |
POI_IMAGE_NAME=${POI_IMAGE_NAME_BASE}:${GITHUB_SHA::7}
cd docker
docker build -t $POI_IMAGE_NAME --build-context poi-helper=$(realpath $(pwd)/..) .
docker tag ${POI_IMAGE_NAME} ${POI_REGISTRY}/${POI_IMAGE_NAME}
docker push ${POI_REGISTRY}/${POI_IMAGE_NAME}
docker system prune -f
cayman_poi:
runs-on: self-hosted
steps:
- name: Checkout Cayman POI
uses: actions/checkout@master
with:
repository: vcf/cayman-poi
ref: vmware-master
path: ./cayman-poi
submodules: "true"
fetch-depth: 0
ssh-key: ${{ secrets.POI_CICD_SSH_KEY }}
ssh-strict: "false"
- name: create branch and push
run: |
cd ./cayman-poi
BRANCH_NAME="test/poi-submodule/${GITHUB_SHA::7}"
if git show-ref --verify --quiet "refs/heads/$BRANCH_NAME"; then
echo "Branch $BRANCH_NAME already exists locally, switching to it"
git checkout "$BRANCH_NAME"
elif git show-ref --verify --quiet "refs/remotes/origin/$BRANCH_NAME"; then
echo "Branch $BRANCH_NAME exists remotely, checking it out"
git checkout -b "$BRANCH_NAME" "origin/$BRANCH_NAME"
else
echo "Branch $BRANCH_NAME does not exist, creating it"
git checkout -b "$BRANCH_NAME"
fi
pushd poi/src
# sometimes the sha is not available yet
git fetch
git checkout ${GITHUB_SHA::7}
popd
git add poi/src
git config --global user.email "poi-cd@broadcom.com"
git config --global user.name "POI CI/CD"
# Only commit if there are changes
if git diff --cached --quiet; then
echo "No changes to commit, skipping commit step"
else
git commit -m "update poi/src to ${GITHUB_SHA::7} for testing branch ${{ github.ref_name }}"
fi
git push origin "$BRANCH_NAME"
- name: Wait for and monitor cayman-poi workflow
env:
GITHUB_TOKEN: ${{ secrets.PAT_POI_CICD_RO }}
run: |
BRANCH_NAME="test/poi-submodule/${GITHUB_SHA::7}"
echo "Monitoring branch: $BRANCH_NAME"
# Function to get workflow runs for the branch
get_workflow_runs() {
curl -s \
-H "Accept: application/vnd.github+json" \
-H "Authorization: Bearer $GITHUB_TOKEN" \
-H "X-GitHub-Api-Version: 2022-11-28" \
"https://github-vcf.devops.broadcom.net/api/v3/repos/vcf/cayman-poi/actions/runs?branch=$BRANCH_NAME" \
| jq -r '.workflow_runs[] | select(.head_branch == "'$BRANCH_NAME'") | "\(.id) \(.status) \(.conclusion // "null") \(.created_at)"'
}
# Wait for workflow to start (up to 5 minutes)
echo "Waiting for workflow to start on branch $BRANCH_NAME..."
timeout=300
interval=30
elapsed=0
while [ $elapsed -lt $timeout ]; do
runs=$(get_workflow_runs)
if [ -n "$runs" ]; then
echo "Workflow detected:"
echo "$runs"
break
fi
echo "No workflow found yet, waiting ${interval}s..."
sleep $interval
elapsed=$((elapsed + interval))
done
if [ $elapsed -ge $timeout ]; then
echo "ERROR: No workflow was triggered within $timeout seconds"
exit 1
fi
# Get the workflow run ID (first field from the output)
run_id=$(echo "$runs" | head -1 | cut -d' ' -f1)
echo "Monitoring workflow run ID: $run_id"
# Monitor workflow status (up to 1 hour)
timeout=3600
interval=60
elapsed=0
while [ $elapsed -lt $timeout ]; do
run_info=$(curl -s \
-H "Accept: application/vnd.github+json" \
-H "Authorization: Bearer $GITHUB_TOKEN" \
-H "X-GitHub-Api-Version: 2022-11-28" \
"https://github-vcf.devops.broadcom.net/api/v3/repos/vcf/cayman-poi/actions/runs/$run_id")
status=$(echo "$run_info" | jq -r '.status')
conclusion=$(echo "$run_info" | jq -r '.conclusion // "null"')
url=$(echo "$run_info" | jq -r '.html_url')
echo "Workflow status: $status, conclusion: $conclusion"
if [ "$status" = "completed" ]; then
echo "Workflow completed with conclusion: $conclusion"
echo "Workflow URL: $url"
if [ "$conclusion" = "success" ]; then
echo "✅ Cayman POI workflow succeeded!"
exit 0
elif [ "$conclusion" = "null" ]; then
echo "❌ Cayman POI workflow completed but conclusion is null"
echo "Check the workflow at: $url"
exit 1
else
echo "❌ Cayman POI workflow failed with conclusion: $conclusion"
echo "Check the workflow at: $url"
exit 1
fi
fi
sleep $interval
elapsed=$((elapsed + interval))
done
echo "ERROR: Workflow did not complete within $timeout seconds"
echo "Workflow URL: $url"
exit 1
ova-poi-harness:
runs-on: [ self-hosted, "docker:root" ]
needs: build-container
strategy:
fail-fast: false
matrix:
include:
- name: minimal
ova_config: minimal_ova.yaml
release: "5.0"
- name: minimal_lvm
ova_config: minimal_ova.yaml
release: "5.0"
- name: minimal_secure
ova_config: minimal_ova.yaml
release: "5.0"
- name: minimal
ova_config: minimal_ova.yaml
release: "4.0"
- name: gitlab-runner
ova_config: gitlab-runner_ova.yaml
release: "5.0"
steps:
- name: Checkout code
uses: actions/checkout@master
- name: Checkout POI Harness
uses: actions/checkout@master
with:
repository: vcf/photon-os-installer-harness
ref: main
path: ./poi-harness
ssh-key: ${{ secrets.POI_CICD_SSH_KEY }}
ssh-strict: "false"
- name: build OVA
env:
NAME: ${{ matrix.name }}
OVA_CONFIG: ${{ matrix.ova_config }}
PHOTON_RELEASE: ${{ matrix.release }}
run: |
POI_IMAGE_NAME=${POI_IMAGE_NAME_BASE}:${GITHUB_SHA::7}
KS_FILE=${NAME}_ks.yaml
PHOTON_RELEASE="${PHOTON_RELEASE:-5.0}"
VM_NAME_BASE=ova-poi-harness-${GITHUB_SHA::7}
VM_NAME=${VM_NAME_BASE}-${NAME}-${PHOTON_RELEASE}
# used by pytest
export VC_IP=${{ vars.VC_IP }}
export VC_USER=${{ vars.VC_USER }}
export VC_PASSWORD=${{ secrets.VC_PASSWORD }}
docker pull ${POI_REGISTRY}/${POI_IMAGE_NAME}
docker tag ${POI_REGISTRY}/${POI_IMAGE_NAME} ${POI_IMAGE_NAME}
pushd examples/ova
docker run --rm --privileged -v/dev:/dev -v$(pwd):/workdir ${POI_IMAGE_NAME} create-image --repo-paths= -c ${KS_FILE} -v ${PHOTON_RELEASE}
docker run --rm -v$(pwd):/workdir -w/workdir ${POI_IMAGE_NAME} create-ova --ovf --mf --vmdk --installer-config ${KS_FILE} --ova-config ${OVA_CONFIG} --compression-level 6
sudo chown -R $(id -u -n):$(id -g -n) .
popd
(cd poi-harness && echo "poi-harness sha is $(git rev-parse --short HEAD)")
pytest ./poi-harness/ci/pytest/ -rs --deploy --ovf examples/ova/*.ovf --name ${VM_NAME} --ks_config examples/ova/${KS_FILE} --ova_config examples/ova/${OVA_CONFIG}
iso-poi-harness:
runs-on: [ self-hosted, "docker:root" ]
needs: build-container
strategy:
fail-fast: false
matrix:
name: [minimal]
boot_mode: [efi, bios]
steps:
- name: Checkout code
uses: actions/checkout@master
- name: Checkout POI Harness
uses: actions/checkout@master
with:
repository: vcf/photon-os-installer-harness
ref: main
path: ./poi-harness
ssh-key: ${{ secrets.POI_CICD_SSH_KEY }}
ssh-strict: false
- name: build ISO
env:
NAME: ${{ matrix.name }}
BOOT_MODE: ${{ matrix.boot_mode }}
run: |
POI_IMAGE_NAME=${POI_IMAGE_NAME_BASE}:${GITHUB_SHA::7}
VM_NAME_BASE=poi-iso-boot-${GITHUB_SHA::7}
ISO_OVF=photon5-iso-boot-${GITHUB_SHA::7}-${BOOT_MODE}.ovf
KS_FILE=${NAME}_ks.yaml
VM_NAME=${VM_NAME_BASE}-${NAME}-${BOOT_MODE}
# used by pytest
export VC_IP=${{ vars.VC_IP }}
export VC_USER=${{ vars.VC_USER }}
export VC_PASSWORD=${{ secrets.VC_PASSWORD }}
docker pull ${POI_REGISTRY}/${POI_IMAGE_NAME}
docker tag ${POI_REGISTRY}/${POI_IMAGE_NAME} ${POI_IMAGE_NAME}
pushd examples/iso
# create ISO
docker run --rm --privileged -v/dev:/dev -v$(pwd):/workdir ${POI_IMAGE_NAME} photon-iso-builder --config iso.yaml
# create OVF that includes that ISO, and a blank hard disk
# base64 encode the ks file, must have no new lines (-w0)
KSDATA64=$(base64 -w0 < ${KS_FILE})
docker run --rm -v$(pwd):/workdir ${POI_IMAGE_NAME} ova-compose -i iso_ova.yaml -o ${ISO_OVF} -m --param ksdata64=${KSDATA64} --param boot_mode=${BOOT_MODE}
sudo chown -R $(id -u -n):$(id -g -n) .
popd
(cd poi-harness && echo "poi-harness sha is $(git rev-parse --short HEAD)")
pytest ./poi-harness/ci/pytest/ -rs --deploy --ovf examples/iso/${ISO_OVF} --name ${VM_NAME} --ks_config examples/iso/${KS_FILE} --ova_config examples/iso/iso_ova.yaml --param ksdata64=${KSDATA64} --param boot_mode=${BOOT_MODE}
update-cayman-poi-master:
runs-on: self-hosted
needs:
- cayman_poi
- ova-poi-harness
- iso-poi-harness
if: github.ref_name == 'master'
steps:
- name: Checkout Cayman POI
uses: actions/checkout@v3
with:
repository: vcf/cayman-poi
ref: vmware-master
path: ./cayman-poi
submodules: "true"
fetch-depth: 0
ssh-key: ${{ secrets.POI_CICD_SSH_KEY }}
ssh-strict: "false"
- name: update poi/src and push to vmware-master
run: |
cd ./cayman-poi
git config --global user.email "poi-cd@broadcom.com"
git config --global user.name "POI CI/CD"
pushd poi/src
# sometimes the sha is not available yet
git fetch
git checkout ${GITHUB_SHA::7}
popd
git add poi/src
# Only commit if there are changes
if git diff --cached --quiet; then
echo "No changes to commit, skipping commit step"
else
git commit -m "update poi/src to ${GITHUB_SHA::7}"
git push origin vmware-master
fi
github-public:
runs-on: self-hosted
needs:
- cayman_poi
- ova-poi-harness
- iso-poi-harness
# if: github.ref_name == 'master'
# disable until we figured out the authentication problem
if: false
steps:
- name: Checkout code
uses: actions/checkout@master
with:
fetch-depth: 0
- name: push to public GitHub
run: |
# token needs "repo, workflow" permissions
git remote add github https://gerrit-photon:${{ secrets.GERRIT_PHOTON_GITHUB_TOKEN }}@github.com/vmware/photon-os-installer.git || true
git push github