forked from virt-s1/bootc-workflow-test
-
Notifications
You must be signed in to change notification settings - Fork 0
/
bib-image.sh
executable file
·669 lines (599 loc) · 22.9 KB
/
bib-image.sh
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
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
#!/bin/bash
set -exuo pipefail
source tools/shared_lib.sh
dump_runner
image_inspect
TEMPDIR=$(mktemp -d)
trap 'rm -rf -- "$TEMPDIR"' EXIT
# SSH configurations
SSH_KEY=${TEMPDIR}/id_rsa
ssh-keygen -f "${SSH_KEY}" -N "" -q -t rsa-sha2-256 -b 2048
SSH_KEY_PUB="${SSH_KEY}.pub"
if [[ ${TIER1_IMAGE_URL} =~ bootc-image-builder ]]; then
BIB_IMAGE_URL=$TIER1_IMAGE_URL
TIER1_IMAGE_URL=${RHEL_REGISTRY_URL}/rhel9-rhel_bootc:rhel-${VERSION}
else
# 9.4 bib -> 9.4 bootc image; 9.5 bib -> 9.5 bootc image
if [[ "$REDHAT_ID" == "rhel" ]]; then
BIB_IMAGE_URL="${BIB_IMAGE_URL:-${RHEL_REGISTRY_URL}/rhel9-rhel_bootc-image-builder:rhel-${REDHAT_VERSION_ID}}"
else
BIB_IMAGE_URL="${BIB_IMAGE_URL:-quay.io/centos-bootc/bootc-image-builder:latest}"
fi
fi
LAYERED_IMAGE="${LAYERED_IMAGE-cloud-init}"
LAYERED_DIR="examples/$LAYERED_IMAGE"
INSTALL_CONTAINERFILE="$LAYERED_DIR/Containerfile"
UPGRADE_CONTAINERFILE=${TEMPDIR}/Containerfile.upgrade
QUAY_REPO_TAG="${QUAY_REPO_TAG:-$(tr -dc a-z0-9 < /dev/urandom | head -c 4 ; echo '')}"
INVENTORY_FILE="${TEMPDIR}/inventory"
REPLACE_CLOUD_USER=""
TEST_IMAGE_NAME="bootc-workflow-test"
greenprint "Login quay.io"
sudo podman login -u "${QUAY_USERNAME}" -p "${QUAY_PASSWORD}" quay.io
case "$REDHAT_ID" in
"rhel")
# work with old TEST_OS variable value rhel-9-x
TEST_OS=$(echo "${REDHAT_ID}-${REDHAT_VERSION_ID}" | sed 's/\./-/')
# RHEL image can be saved in private repo only
TEST_IMAGE_URL="quay.io/redhat_emp1/${TEST_IMAGE_NAME}:${QUAY_REPO_TAG}"
LOCAL_IMAGE_URL="localhost/${TEST_IMAGE_NAME}:${QUAY_REPO_TAG}"
SSH_USER="cloud-user"
sed "s/REPLACE_ME/${DOWNLOAD_NODE}/; s|REPLACE_BATCH_COMPOSE|${BATCH_COMPOSE}|; s/REPLACE_COMPOSE_ID/${CURRENT_COMPOSE_ID}/" files/rhel-9-y.template | tee "${LAYERED_DIR}"/rhel-9-y.repo > /dev/null
ADD_REPO="COPY rhel-9-y.repo /etc/yum.repos.d/rhel-9-y.repo"
ADD_RHC="RUN dnf install -y rhc"
if [[ "$PLATFORM" == "aws" ]]; then
SSH_USER="ec2-user"
REPLACE_CLOUD_USER='RUN sed -i "s/name: cloud-user/name: ec2-user/g" /etc/cloud/cloud.cfg'
fi
greenprint "Prepare cloud-init file"
tee -a "playbooks/user-data" > /dev/null << EOF
#cloud-config
yum_repos:
rhel-9y-baseos:
name: rhel-9y-baseos
baseurl: http://${DOWNLOAD_NODE}/rhel-9/nightly/${BATCH_COMPOSE}RHEL-9/${CURRENT_COMPOSE_ID}/compose/BaseOS/\$basearch/os/
enabled: true
gpgcheck: false
rhel-9y-appstream:
name: rhel-9y-appstream
baseurl: http://${DOWNLOAD_NODE}/rhel-9/nightly/${BATCH_COMPOSE}RHEL-9/${CURRENT_COMPOSE_ID}/compose/AppStream/\$basearch/os/
enabled: true
gpgcheck: false
EOF
GUEST_ID_DC70="rhel9_64Guest"
BOOT_ARGS="uefi"
;;
"centos")
# work with old TEST_OS variable value centos-stream-9
TEST_OS=$(echo "${REDHAT_ID}-${REDHAT_VERSION_ID}" | sed 's/-/-stream-/')
TEST_IMAGE_URL="quay.io/bootc-test/${TEST_IMAGE_NAME}:${QUAY_REPO_TAG}"
SSH_USER="cloud-user"
ADD_REPO=""
ADD_RHC=""
if [[ "$PLATFORM" == "aws" ]]; then
SSH_USER="ec2-user"
REPLACE_CLOUD_USER='RUN sed -i "s/name: cloud-user/name: ec2-user/g" /etc/cloud/cloud.cfg'
fi
GUEST_ID_DC70="centos9_64Guest"
BOOT_ARGS="uefi,firmware.feature0.name=secure-boot,firmware.feature0.enabled=no"
;;
"fedora")
TEST_OS="${REDHAT_ID}-${REDHAT_VERSION_ID}"
TEST_IMAGE_URL="quay.io/bootc-test/${TEST_IMAGE_NAME}:${QUAY_REPO_TAG}"
SSH_USER="fedora"
ADD_REPO=""
ADD_RHC=""
GUEST_ID_DC70="fedora64Guest"
BOOT_ARGS="uefi"
;;
*)
redprint "Variable TIER1_IMAGE_URL is not supported"
exit 1
;;
esac
greenprint "Configure container build arch"
if [[ "$CROSS_ARCH" == "True" ]]; then
if [[ "$ARCH" == "x86_64" ]]; then
ARCH="aarch64"
else
ARCH="x86_64"
fi
fi
case "$ARCH" in
"x86_64")
BUILD_PLATFORM="linux/amd64"
;;
"aarch64")
BUILD_PLATFORM="linux/arm64"
;;
esac
greenprint "Create ${TEST_OS} installation Containerfile"
sed -i "s|^FROM.*|FROM $TIER1_IMAGE_URL\n$ADD_REPO\n$ADD_RHC|" "$INSTALL_CONTAINERFILE"
if [[ "$LAYERED_IMAGE" == "useradd-ssh" ]]; then
sed -i "s|exampleuser|$SSH_USER|g" "$INSTALL_CONTAINERFILE"
fi
tee -a "$INSTALL_CONTAINERFILE" > /dev/null << EOF
RUN dnf -y clean all
$REPLACE_CLOUD_USER
EOF
if [[ "$IMAGE_TYPE" == "vmdk" ]]; then
greenprint "Install cloud-init for vmdk image"
sed -i "s/open-vm-tools/cloud-init open-vm-tools/" "$INSTALL_CONTAINERFILE"
fi
greenprint "Check $TEST_OS installation Containerfile"
cat "$INSTALL_CONTAINERFILE"
greenprint "Build $TEST_OS installation container image"
if [[ "$LAYERED_IMAGE" == "useradd-ssh" ]]; then
sudo podman build --platform "$BUILD_PLATFORM" --tls-verify=false --retry=5 --retry-delay=10 --build-arg "sshpubkey=$(cat "${SSH_KEY_PUB}")" -t "${TEST_IMAGE_NAME}:${QUAY_REPO_TAG}" "$LAYERED_DIR"
else
sudo podman build --platform "$BUILD_PLATFORM" --tls-verify=false --retry=5 --retry-delay=10 -t "${TEST_IMAGE_NAME}:${QUAY_REPO_TAG}" "$LAYERED_DIR"
fi
[[ $- =~ x ]] && debug=1 && set +x
sed "s/REPLACE_ME/${QUAY_SECRET}/g" files/auth.template | tee auth.json > /dev/null
[[ $debug == 1 ]] && set -x
sudo podman build --platform "$BUILD_PLATFORM" --tls-verify=false --retry=5 --retry-delay=10 --from "localhost/${TEST_IMAGE_NAME}:${QUAY_REPO_TAG}" --secret id=creds,src=./auth.json -t "${TEST_IMAGE_NAME}:${QUAY_REPO_TAG}" examples/container-auth
greenprint "Push $TEST_OS installation container image"
sudo podman push --tls-verify=false --quiet "${TEST_IMAGE_NAME}:${QUAY_REPO_TAG}" "$TEST_IMAGE_URL"
greenprint "Prepare inventory file"
tee -a "$INVENTORY_FILE" > /dev/null << EOF
[cloud]
localhost
[guest]
[cloud:vars]
ansible_connection=local
[guest:vars]
ansible_user="$SSH_USER"
ansible_private_key_file="$SSH_KEY"
ansible_ssh_common_args="-o StrictHostKeyChecking=no -o UserKnownHostsFile=/dev/null"
[all:vars]
ansible_python_interpreter=/usr/bin/python3
EOF
greenprint "Prepare ansible.cfg"
export ANSIBLE_CONFIG="${PWD}/playbooks/ansible.cfg"
# bib does not support btrfs yet
greenprint "Configure rootfs randomly"
ROOTFS_LIST=( \
"ext4" \
"xfs" \
)
RND_LINE=$((RANDOM % 2))
ROOTFS="${ROOTFS_LIST[$RND_LINE]}"
case "$IMAGE_TYPE" in
"ami")
greenprint "Build $TEST_OS $IMAGE_TYPE image"
AMI_NAME="bootc-bib-${TEST_OS}-${ARCH}-${QUAY_REPO_TAG}"
AWS_BUCKET_NAME="bootc-bib-images-test"
# To build RHEL image - private image, --local and localhost image have to be used
if [[ "$REDHAT_ID" == "rhel" ]]; then
sudo podman run \
--rm \
-it \
--privileged \
--pull=newer \
--tls-verify=false \
--security-opt label=type:unconfined_t \
-v /var/lib/containers/storage:/var/lib/containers/storage \
--env AWS_ACCESS_KEY_ID="$AWS_ACCESS_KEY_ID" \
--env AWS_SECRET_ACCESS_KEY="$AWS_SECRET_ACCESS_KEY" \
"$BIB_IMAGE_URL" \
--type ami \
--target-arch "$ARCH" \
--aws-ami-name "$AMI_NAME" \
--aws-bucket "$AWS_BUCKET_NAME" \
--aws-region "$AWS_REGION" \
--local \
"$LOCAL_IMAGE_URL"
else
sudo podman run \
--rm \
-it \
--privileged \
--pull=newer \
--tls-verify=false \
--security-opt label=type:unconfined_t \
-v /var/lib/containers/storage:/var/lib/containers/storage \
--env AWS_ACCESS_KEY_ID="$AWS_ACCESS_KEY_ID" \
--env AWS_SECRET_ACCESS_KEY="$AWS_SECRET_ACCESS_KEY" \
"$BIB_IMAGE_URL" \
--type ami \
--target-arch "$ARCH" \
--aws-ami-name "$AMI_NAME" \
--aws-bucket "$AWS_BUCKET_NAME" \
--aws-region "$AWS_REGION" \
--rootfs "$ROOTFS" \
"$TEST_IMAGE_URL"
fi
greenprint "Get uploaded AMI ID and snapshot ID"
AMI_ID=$(
aws ec2 describe-images \
--filters "Name=name,Values=${AMI_NAME}" \
--query 'Images[*].ImageId' \
--output text
)
greenprint "Deploy $IMAGE_TYPE instance"
ansible-playbook -v \
-i "$INVENTORY_FILE" \
-e test_os="$TEST_OS" \
-e ssh_key_pub="$SSH_KEY_PUB" \
-e inventory_file="$INVENTORY_FILE" \
-e ami_id="$AMI_ID" \
"playbooks/deploy-aws.yaml"
;;
"qcow2"|"raw")
greenprint "Build $TEST_OS $IMAGE_TYPE image"
mkdir -p output
# To build RHEL image - private image, --local and localhost image have to be used
if [[ "$REDHAT_ID" == "rhel" ]]; then
sudo podman run \
--rm \
-it \
--privileged \
--pull=newer \
--tls-verify=false \
--security-opt label=type:unconfined_t \
-v "$(pwd)/output":/output \
-v /var/lib/containers/storage:/var/lib/containers/storage \
"$BIB_IMAGE_URL" \
--type "$IMAGE_TYPE" \
--target-arch "$ARCH" \
--chown "$(id -u "$(whoami)"):$(id -g "$(whoami)")" \
--local \
"$LOCAL_IMAGE_URL"
else
sudo podman run \
--rm \
-it \
--privileged \
--pull=newer \
--tls-verify=false \
--security-opt label=type:unconfined_t \
-v "$(pwd)/output":/output \
-v /var/lib/containers/storage:/var/lib/containers/storage \
"$BIB_IMAGE_URL" \
--type "$IMAGE_TYPE" \
--target-arch "$ARCH" \
--chown "$(id -u "$(whoami)"):$(id -g "$(whoami)")" \
--rootfs "$ROOTFS" \
"$TEST_IMAGE_URL"
fi
if [[ "$IMAGE_TYPE" == "raw" ]]; then
qemu-img convert -f raw output/image/disk.raw -O qcow2 output/image/disk.qcow2
sudo mv output/image/disk.qcow2 /var/lib/libvirt/images && sudo rm -rf output
# raw image will run test on bios vm for x86_64
if [[ "$ARCH" == "x86_64" ]]; then
BIB_FIRMWARE=bios
else
BIB_FIRMWARE=uefi
fi
else
sudo mv output/qcow2/disk.qcow2 /var/lib/libvirt/images && sudo rm -rf output
# qcow2 image will run test on uefi vm
BIB_FIRMWARE=uefi
fi
greenprint "Deploy $IMAGE_TYPE instance"
ansible-playbook -v \
-i "$INVENTORY_FILE" \
-e test_os="$TEST_OS" \
-e ssh_key_pub="$SSH_KEY_PUB" \
-e ssh_user="$SSH_USER" \
-e inventory_file="$INVENTORY_FILE" \
-e bib="true" \
-e boot_args="$BOOT_ARGS" \
-e bib_firmware="$BIB_FIRMWARE" \
"playbooks/deploy-libvirt.yaml"
;;
"vmdk")
mkdir -p output
greenprint "Build $TEST_OS $IMAGE_TYPE image"
# To build RHEL image - private image, --local and localhost image have to be used
if [[ "$REDHAT_ID" == "rhel" ]]; then
sudo podman run \
--rm \
-it \
--privileged \
--pull=newer \
--tls-verify=false \
--security-opt label=type:unconfined_t \
-v "$(pwd)/output":/output \
-v /var/lib/containers/storage:/var/lib/containers/storage \
"$BIB_IMAGE_URL" \
--type vmdk \
--target-arch "$ARCH" \
--local \
"$LOCAL_IMAGE_URL"
else
sudo podman run \
--rm \
-it \
--privileged \
--pull=newer \
--tls-verify=false \
--security-opt label=type:unconfined_t \
-v "$(pwd)/output":/output \
-v /var/lib/containers/storage:/var/lib/containers/storage \
"$BIB_IMAGE_URL" \
--type vmdk \
--target-arch "$ARCH" \
--rootfs "$ROOTFS" \
"$TEST_IMAGE_URL"
fi
greenprint "Deploy $IMAGE_TYPE instance"
DATACENTER_70="Datacenter7.0"
DATASTORE_70="datastore-80"
DATACENTER_70_POOL="/Datacenter7.0/host/Automation/Resources"
FIRMWARE_LIST=( \
"bios" \
"efi" \
)
RND_LINE=$((RANDOM % 2))
FIRMWARE="${FIRMWARE_LIST[$RND_LINE]}"
greenprint "📋 Random run firmware: $FIRMWARE"
VMDK_FILENAME="${TEST_OS}-${ARCH}-${QUAY_REPO_TAG}"
VSPHERE_VM_NAME="bib-${FIRMWARE}-${VMDK_FILENAME}-v70"
greenprint "📋 Rename vmdk file name"
sudo mv output/vmdk/disk.vmdk "output/vmdk/${VMDK_FILENAME}.vmdk"
sudo chmod 644 "output/vmdk/${VMDK_FILENAME}.vmdk"
sudo chown "$(whoami)" "output/vmdk/${VMDK_FILENAME}.vmdk"
greenprint "📋 Uploading vmdk image to vsphere datacenter 7.0"
govc import.vmdk \
-dc="${DATACENTER_70}" \
-ds="${DATASTORE_70}" \
-pool="${DATACENTER_70_POOL}" \
"output/vmdk/${VMDK_FILENAME}.vmdk" > /dev/null
sudo rm -rf output
greenprint "📋 Generate user-data and meta-data"
envsubst > metadata.yaml <<EOF
instance-id: bib-${QUAY_REPO_TAG}
local-hostname: bib-${TEST_OS}
EOF
cat metadata.yaml
envsubst > userdata.yaml <<EOF
#cloud-config
users:
- default
- name: $SSH_USER
sudo: ALL=(ALL) NOPASSWD:ALL
groups: sudo, wheel
lock_passwd: true
ssh_authorized_keys:
- $(cat "$SSH_KEY_PUB")
EOF
cat userdata.yaml
METADATA=$(gzip -c9 <metadata.yaml | { base64 -w0 2>/dev/null || base64; })
USERDATA=$(gzip -c9 <userdata.yaml | { base64 -w0 2>/dev/null || base64; })
greenprint "📋 Create vm in vsphere datacenter 7.0"
govc vm.create \
-dc="$DATACENTER_70" \
-ds="$DATASTORE_70" \
-pool="$DATACENTER_70_POOL" \
-net="VM Network" \
-net.adapter=vmxnet3 \
-disk.controller=pvscsi \
-on=false \
-c=2 \
-m=4096 \
-g="$GUEST_ID_DC70" \
-firmware="$FIRMWARE" \
"$VSPHERE_VM_NAME"
govc vm.change \
-dc="$DATACENTER_70" \
-vm="$VSPHERE_VM_NAME" \
-e guestinfo.metadata="$METADATA" \
-e guestinfo.metadata.encoding="gzip+base64" \
-e guestinfo.userdata="$USERDATA" \
-e guestinfo.userdata.encoding="gzip+base64" \
govc vm.disk.attach \
-dc="$DATACENTER_70" \
-ds="$DATASTORE_70" \
-vm="$VSPHERE_VM_NAME" \
-link=false \
-disk="${VMDK_FILENAME}/${VMDK_FILENAME}.vmdk"
govc vm.power \
-on \
-dc="$DATACENTER_70" \
"$VSPHERE_VM_NAME"
GUEST_ADDRESS=$(govc vm.ip -v4 -dc="$DATACENTER_70" -wait=10m "$VSPHERE_VM_NAME")
greenprint "🛃 VM IP address is: $GUEST_ADDRESS"
sed -i "/\[guest\]/a $GUEST_ADDRESS" "$INVENTORY_FILE"
wait_for_ssh_up () {
SSH_OPTIONS=(-o StrictHostKeyChecking=no -o UserKnownHostsFile=/dev/null -o ConnectTimeout=5)
SSH_STATUS=$(sudo ssh "${SSH_OPTIONS[@]}" -i "${SSH_KEY}" ${SSH_USER}@"${1}" '/bin/bash -c "echo -n READY"')
if [[ $SSH_STATUS == READY ]]; then
echo 1
else
echo 0
fi
}
greenprint "🛃 Checking for SSH is ready to go"
for _ in $(seq 0 30); do
RESULT=$(wait_for_ssh_up "$GUEST_ADDRESS")
if [[ $RESULT == 1 ]]; then
echo "SSH is ready now! 🥳"
break
fi
sleep 10
done
greenprint "Clean up userdata.yaml and metadata.yaml"
rm -f userdata.yaml metadata.yaml
;;
"anaconda-iso")
greenprint "Build $TEST_OS $IMAGE_TYPE image"
mkdir -p output
# To build RHEL image - private image, --local and localhost image have to be used
if [[ "$REDHAT_ID" == "rhel" ]]; then
sudo podman run \
--rm \
-it \
--privileged \
--pull=newer \
--tls-verify=false \
--security-opt label=type:unconfined_t \
-v "$(pwd)/output":/output \
-v /var/lib/containers/storage:/var/lib/containers/storage \
"$BIB_IMAGE_URL" \
--type "$IMAGE_TYPE" \
--target-arch "$ARCH" \
--chown "$(id -u "$(whoami)"):$(id -g "$(whoami)")" \
--local \
"$LOCAL_IMAGE_URL"
else
sudo podman run \
--rm \
-it \
--privileged \
--pull=newer \
--tls-verify=false \
--security-opt label=type:unconfined_t \
-v "$(pwd)/output":/output \
-v /var/lib/containers/storage:/var/lib/containers/storage \
"$BIB_IMAGE_URL" \
--type "$IMAGE_TYPE" \
--target-arch "$ARCH" \
--chown "$(id -u "$(whoami)"):$(id -g "$(whoami)")" \
--rootfs "$ROOTFS" \
"$TEST_IMAGE_URL"
fi
ISOMOUNT=$(mktemp -d)
greenprint "Mounting install.iso -> $ISOMOUNT"
sudo mount -v -o ro "output/bootiso/install.iso" "$ISOMOUNT"
NEW_KS_FILE="${TEMPDIR}/bib.ks"
greenprint "Default osbuild-base.ks"
cat "${ISOMOUNT}/osbuild-base.ks"
greenprint "Default osbuild.ks"
cat "${ISOMOUNT}/osbuild.ks"
greenprint "Preparing modified kickstart file"
cat > "$NEW_KS_FILE" << EOFKS
text
$(cat "${ISOMOUNT}/osbuild-base.ks")
$(cat "${ISOMOUNT}/osbuild.ks")
EOFKS
sed -i '/%include/d' "$NEW_KS_FILE"
greenprint "Writing new ISO"
sudo mkksiso -c "console=ttyS0,115200" --ks "$NEW_KS_FILE" "output/bootiso/install.iso" "/var/lib/libvirt/images/install.iso"
greenprint "==== NEW KICKSTART FILE ===="
cat "$NEW_KS_FILE"
greenprint "============================"
greenprint "Clean up ISO building environment"
sudo umount -v "$ISOMOUNT"
rm -rf "$ISOMOUNT"
sudo rm -rf output
greenprint "💾 Create vm qcow2 files for ISO installation"
sudo qemu-img create -f qcow2 "/var/lib/libvirt/images/disk.qcow2" 10G
if [[ "$ARCH" == "x86_64" ]]; then
FIRMWARE_LIST=( \
"bios" \
"uefi" \
)
RND_LINE=$((RANDOM % 2))
FIRMWARE="${FIRMWARE_LIST[$RND_LINE]}"
else
FIRMWARE="uefi"
fi
greenprint "Deploy $IMAGE_TYPE instance"
ansible-playbook -v \
-i "$INVENTORY_FILE" \
-e test_os="$TEST_OS" \
-e ssh_key_pub="$SSH_KEY_PUB" \
-e ssh_user="$SSH_USER" \
-e inventory_file="$INVENTORY_FILE" \
-e bib="true" \
-e firmware="$FIRMWARE" \
-e boot_args="$BOOT_ARGS" \
"playbooks/deploy-libvirt.yaml"
;;
"to-disk")
if [[ "$REDHAT_ID" == "fedora" ]]; then
ROOTFS="btrfs"
fi
greenprint "💾 Create disk.raw"
sudo truncate -s 10G disk.raw
greenprint "bootc install to disk.raw"
sudo podman run \
--rm \
--privileged \
--pid=host \
--security-opt label=type:unconfined_t \
-v /var/lib/containers:/var/lib/containers \
-v /dev:/dev \
-v .:/output \
"$TEST_IMAGE_URL" \
bootc install to-disk --filesystem "$ROOTFS" --generic-image --via-loopback /output/disk.raw
sudo qemu-img convert -f raw ./disk.raw -O qcow2 "/var/lib/libvirt/images/disk.qcow2"
rm -f disk.raw
if [[ "$ARCH" == "x86_64" ]]; then
BIB_FIRMWARE_LIST=( \
"bios" \
"uefi" \
)
RND_LINE=$((RANDOM % 2))
BIB_FIRMWARE="${BIB_FIRMWARE_LIST[$RND_LINE]}"
else
BIB_FIRMWARE="uefi"
fi
greenprint "Deploy $IMAGE_TYPE instance"
ansible-playbook -v \
-i "$INVENTORY_FILE" \
-e test_os="$TEST_OS" \
-e ssh_key_pub="$SSH_KEY_PUB" \
-e ssh_user="$SSH_USER" \
-e inventory_file="$INVENTORY_FILE" \
-e bib="true" \
-e boot_args="$BOOT_ARGS" \
-e bib_firmware="$BIB_FIRMWARE" \
"playbooks/deploy-libvirt.yaml"
;;
*)
redprint "Variable IMAGE_TYPE has to be defined"
exit 1
;;
esac
greenprint "Run ostree checking test on $PLATFORM instance"
ansible-playbook -v \
-i "$INVENTORY_FILE" \
-e test_os="$TEST_OS" \
-e bootc_image="$TEST_IMAGE_URL" \
-e layered_image="$LAYERED_IMAGE" \
-e image_label_version_id="$REDHAT_VERSION_ID" \
playbooks/check-system.yaml
greenprint "Create upgrade Containerfile"
tee "$UPGRADE_CONTAINERFILE" > /dev/null << EOF
FROM "$TEST_IMAGE_URL"
RUN dnf -y install wget && \
dnf -y clean all
EOF
greenprint "Build $TEST_OS upgrade container image"
sudo podman build --platform "$BUILD_PLATFORM" --tls-verify=false --retry=5 --retry-delay=10 -t "${TEST_IMAGE_NAME}:${QUAY_REPO_TAG}" -f "$UPGRADE_CONTAINERFILE" .
greenprint "Push $TEST_OS upgrade container image"
sudo podman push --tls-verify=false --quiet "${TEST_IMAGE_NAME}:${QUAY_REPO_TAG}" "$TEST_IMAGE_URL"
greenprint "Upgrade $TEST_OS system"
ansible-playbook -v \
-i "$INVENTORY_FILE" \
-e bootc_image="$TEST_IMAGE_URL" \
playbooks/upgrade.yaml
greenprint "Run ostree checking test after upgrade on $PLATFORM instance"
ansible-playbook -v \
-i "$INVENTORY_FILE" \
-e test_os="$TEST_OS" \
-e bootc_image="$TEST_IMAGE_URL" \
-e image_label_version_id="$REDHAT_VERSION_ID" \
-e upgrade="true" \
playbooks/check-system.yaml
greenprint "Rollback $TEST_OS system"
ansible-playbook -v \
-i "$INVENTORY_FILE" \
playbooks/rollback.yaml
if [[ "$IMAGE_TYPE" == vmdk ]]; then
greenprint "Delete $VSPHERE_VM_NAME from vsphere"
govc vm.destroy -dc="${DATACENTER_70}" "${VSPHERE_VM_NAME}"
else
greenprint "Terminate $PLATFORM instance and deregister AMI"
ansible-playbook -v \
-i "$INVENTORY_FILE" \
-e platform="$PLATFORM" \
playbooks/remove.yaml
fi
greenprint "Clean up"
rm -rf auth.json "${LAYERED_DIR}/rhel-9-y.repo"
unset ANSIBLE_CONFIG
greenprint "🎉 All tests passed."
exit 0