Skip to content

Commit 1fb32f8

Browse files
committed
Create MicroShift iso using image mode and bootc image builder
With 4.18 microshift removed the steps of creating the iso using image builder and there is no more `build.sh` script which is consumed by mircoshift.sh script to create it. This PR use the image mode and bootc image builder (BIB) to create the iso which is now microshift team also pushing forward.
1 parent e8b11eb commit 1fb32f8

File tree

7 files changed

+297
-133
lines changed

7 files changed

+297
-133
lines changed

00-microshift-dns.yaml

-15
This file was deleted.

createdisk.sh

-3
Original file line numberDiff line numberDiff line change
@@ -72,9 +72,6 @@ EOF
7272
# also in case of microshift the ports like 2222, 443, 80 ..etc need to be manually added
7373
# and OCP/OKD/podman bundles have it disabled by default.
7474
${SSH} core@${VM_IP} -- sudo systemctl disable firewalld
75-
${YQ} eval --inplace ".dns.baseDomain = \"${SNC_PRODUCT_NAME}.${BASE_DOMAIN}\"" 00-microshift-dns.yaml
76-
${SCP} 00-microshift-dns.yaml core@${VM_IP}:/home/core
77-
${SSH} core@${VM_IP} -- 'sudo mv /home/core/00-microshift-dns.yaml /etc/microshift/config.d/00-microshift-dns.yaml'
7875
# Make sure `baseDomain` is set to crc.testing
7976
${SSH} core@${VM_IP} -- "grep '^\s\+baseDomain: ${SNC_PRODUCT_NAME}.${BASE_DOMAIN}' /etc/microshift/config.d/00-microshift-dns.yaml"
8077
# Remove the lvm system.device file since it have diskID and deviceName which changes

image-mode/microshift/build.sh

+155
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,155 @@
1+
#!/bin/bash
2+
set -eo pipefail
3+
4+
ROOTDIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )/../../" && pwd )"
5+
SCRIPTDIR=${ROOTDIR}/image-mode/microshift
6+
IMGNAME=microshift
7+
MICROSHIFT_VERSION=4.18
8+
BUILD_ARCH=$(uname -m)
9+
OSVERSION=$(awk -F: '{print $5}' /etc/system-release-cpe)
10+
LVM_SYSROOT_SIZE_MIN=10240
11+
LVM_SYSROOT_SIZE=${LVM_SYSROOT_SIZE_MIN}
12+
OCP_PULL_SECRET_FILE=
13+
AUTHORIZED_KEYS_FILE=
14+
AUTHORIZED_KEYS=
15+
USE_MIRROR_REPO=
16+
17+
# shellcheck disable=SC2034
18+
STARTTIME="$(date +%s)"
19+
BUILDDIR=${BUILDDIR:-${ROOTDIR}/_output/image-mode}
20+
21+
usage() {
22+
local error_message="$1"
23+
24+
if [ -n "${error_message}" ]; then
25+
echo "ERROR: ${error_message}"
26+
echo
27+
fi
28+
29+
echo "Usage: $(basename "$0") <-pull_secret_file path_to_file> [OPTION]..."
30+
echo ""
31+
echo " -pull_secret_file path_to_file"
32+
echo " Path to a file containing the OpenShift pull secret, which can be"
33+
echo " obtained from https://console.redhat.com/openshift/downloads#tool-pull-secret"
34+
echo ""
35+
echo "Optional arguments:"
36+
echo " -lvm_sysroot_size num_in_MB"
37+
echo " Size of the system root LVM partition. The remaining"
38+
echo " disk space will be allocated for data (default: ${LVM_SYSROOT_SIZE})"
39+
echo " -authorized_keys_file path_to_file"
40+
echo " Path to an SSH authorized_keys file to allow SSH access"
41+
echo " into the default 'redhat' account"
42+
echo " -use-unreleased-mirror-repo <unreleased_mirror_repo>"
43+
echo " Use unreleased mirror repo to get release candidate and engineering preview rpms"
44+
echo " like (https://mirror.openshift.com/pub/openshift-v4/x86_64/microshift/ocp-dev-preview/latest-4.18/el9/os/)"
45+
echo " -microshift-version <microshift-version>"
46+
echo " Version of microshift for image generation (default: ${MICROSHIFT_VERSION}"
47+
echo " -hostname <hostname>"
48+
echo " Hostname of the machine"
49+
echo " -base-domain <base-domain>"
50+
echo " Base domain for microshift cluster"
51+
exit 1
52+
}
53+
54+
title() {
55+
echo -e "\E[34m\n# $1\E[00m"
56+
}
57+
58+
# Parse the command line
59+
while [ $# -gt 0 ] ; do
60+
case $1 in
61+
-pull_secret_file)
62+
shift
63+
OCP_PULL_SECRET_FILE="$1"
64+
[ -z "${OCP_PULL_SECRET_FILE}" ] && usage "Pull secret file not specified"
65+
[ ! -s "${OCP_PULL_SECRET_FILE}" ] && usage "Empty or missing pull secret file"
66+
shift
67+
;;
68+
-lvm_sysroot_size)
69+
shift
70+
LVM_SYSROOT_SIZE="$1"
71+
[ -z "${LVM_SYSROOT_SIZE}" ] && usage "System root LVM partition size not specified"
72+
[ "${LVM_SYSROOT_SIZE}" -lt ${LVM_SYSROOT_SIZE_MIN} ] && usage "System root LVM partition size cannot be smaller than ${LVM_SYSROOT_SIZE_MIN}MB"
73+
shift
74+
;;
75+
-authorized_keys_file)
76+
shift
77+
AUTHORIZED_KEYS_FILE="$1"
78+
[ -z "${AUTHORIZED_KEYS_FILE}" ] && usage "Authorized keys file not specified"
79+
shift
80+
;;
81+
-use-unreleased-mirror-repo)
82+
shift
83+
USE_UNRELEASED_MIRROR_REPO="$1"
84+
[ -z "${USE_UNRELEASED_MIRROR_REPO}" ] && usage "Mirror repo not specified"
85+
shift
86+
;;
87+
-microshift-version)
88+
shift
89+
MICROSHIFT_VERSION="$1"
90+
[ -z "${MICROSHIFT_VERSION}" ] && usage "MicroShift version not specified"
91+
shift
92+
;;
93+
-hostname)
94+
shift
95+
HOSTNAME="$1"
96+
[ -z "${HOSTNAME}" ] && usage "Hostname not specified"
97+
shift
98+
;;
99+
-base-domain)
100+
shift
101+
BASE_DOMAIN="$1"
102+
[ -z "${BASE_DOMAIN}" ] && usage "Base domain not specified"
103+
shift
104+
;;
105+
*)
106+
usage
107+
;;
108+
esac
109+
done
110+
111+
if [ ! -r "${OCP_PULL_SECRET_FILE}" ] ; then
112+
echo "ERROR: pull_secret_file file does not exist or not readable: ${OCP_PULL_SECRET_FILE}"
113+
exit 1
114+
fi
115+
if [ -n "${AUTHORIZED_KEYS_FILE}" ]; then
116+
if [ ! -e "${AUTHORIZED_KEYS_FILE}" ]; then
117+
echo "ERROR: authorized_keys_file does not exist: ${AUTHORIZED_KEYS_FILE}"
118+
exit 1
119+
else
120+
AUTHORIZED_KEYS=$(cat "${AUTHORIZED_KEYS_FILE}")
121+
fi
122+
fi
123+
124+
mkdir -p "${BUILDDIR}"
125+
126+
title "Preparing kickstart config"
127+
# Create a kickstart file from a template, compacting pull secret contents if necessary
128+
cat < "${SCRIPTDIR}/config/config.toml.template" \
129+
| sed "s;REPLACE_HOSTNAME;${HOSTNAME};g" \
130+
| sed "s;REPLACE_BASE_DOMAIN;${BASE_DOMAIN};g" \
131+
| sed "s;REPLACE_LVM_SYSROOT_SIZE;${LVM_SYSROOT_SIZE};g" \
132+
| sed "s;REPLACE_OCP_PULL_SECRET_CONTENTS;$(cat < "${OCP_PULL_SECRET_FILE}" | jq -c);g" \
133+
| sed "s^REPLACE_CORE_AUTHORIZED_KEYS_CONTENTS^${AUTHORIZED_KEYS}^g" \
134+
> "${BUILDDIR}"/config.toml
135+
136+
title "Building bootc image for microshift"
137+
sudo podman build --authfile ${OCP_PULL_SECRET_FILE} -t ${IMGNAME}:${MICROSHIFT_VERSION} \
138+
--build-arg USHIFT_VER=${MICROSHIFT_VERSION} \
139+
--env UNRELEASED_MIRROR_REPO=${USE_UNRELEASED_MIRROR_REPO} \
140+
-f "${SCRIPTDIR}/config/Containerfile.bootc-rhel9"
141+
142+
# As of now we are generating the ISO to have same previous behavior
143+
# TODO: Try to use qcow2 directly for vm creation
144+
title "Creating ISO image"
145+
sudo podman run --authfile ${OCP_PULL_SECRET_FILE} --rm -it \
146+
--privileged \
147+
--security-opt label=type:unconfined_t \
148+
-v /var/lib/containers/storage:/var/lib/containers/storage \
149+
-v "${BUILDDIR}"/config.toml:/config.toml \
150+
-v "${BUILDDIR}":/output \
151+
registry.redhat.io/rhel9/bootc-image-builder:latest \
152+
--local \
153+
--type iso \
154+
--config /config.toml \
155+
localhost/${IMGNAME}:${MICROSHIFT_VERSION}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
FROM registry.redhat.io/rhel9/rhel-bootc:9.4
2+
3+
ARG MICROSHIFT_VER=4.18
4+
RUN if [ -z "${UNRELEASED_MIRROR_REPO}" ]; then \
5+
dnf config-manager --set-enabled "rhocp-${USHIFT_VER}-for-rhel-9-$(uname -m)-rpms" \
6+
--set-enabled "fast-datapath-for-rhel-9-$(uname -m)-rpms"; \
7+
else \
8+
# This is required to update the gpgcheck for repoID
9+
# Add the specified OpenShift v4 dependencies repository to get packages like crio, runc, openvswitch ..etc.
10+
# to which microshift package depend on for the current architecture and MICROSHIFT_VER version (e.g., 4.18).
11+
repoID=$(echo "${UNRELEASED_MIRROR_REPO#*://}" | tr '/:' '_'); \
12+
dnf config-manager --add-repo "${UNRELEASED_MIRROR_REPO}" \
13+
--add-repo "https://mirror.openshift.com/pub/openshift-v4/$(uname -m)/dependencies/rpms/${MICROSHIFT_VER}-el9-beta" \
14+
--set-enabled "fast-datapath-for-rhel-9-$(uname -m)-rpms"; \
15+
dnf config-manager --save --setopt="${repoID}".gpgcheck=0 --setopt=*-el9-beta.gpgcheck=0; \
16+
fi
17+
RUN dnf install -y firewalld microshift microshift-release-info cloud-utils-growpart qemu-guest-agent dnsmasq && \
18+
dnf clean all && rm -fr /etc/yum.repos.d/*
19+
20+
# https://github.com/containers/bootc/discussions/1036
21+
# /Users is created to make sure share directory works on
22+
# mac because on linux it is /home and for windows it is /mnt
23+
# and both are symlink to `var` already
24+
RUN rm -fr /opt && ln -sf var/opt /opt && mkdir /var/opt
25+
RUN ln -sf var/Users /Users && mkdir /var/Users
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,99 @@
1+
[customizations.installer.kickstart]
2+
contents = """
3+
lang en_US.UTF-8
4+
keyboard us
5+
timezone UTC
6+
text
7+
reboot
8+
9+
# Configure network to use DHCP and activate on boot
10+
network --bootproto=dhcp --device=link --activate --onboot=on
11+
12+
# Partition disk with a 1MB BIOS boot, 200M EFI, 800M boot XFS partition and
13+
# an LVM volume containing a 10GB+ system root. The remainder of the volume
14+
# will be used by the CSI driver for storing data
15+
#
16+
# For example, a 20GB disk would be partitioned in the following way:
17+
#
18+
# NAME MAJ:MIN RM SIZE RO TYPE MOUNTPOINT
19+
# sda 8:0 0 20G 0 disk
20+
# ├─sda1 8:1 0 1M 0 part
21+
# ├─sda2 8:2 0 200M 0 part /boot/efi
22+
# ├─sda3 8:3 0 800M 0 part /boot
23+
# └─sda4 8:4 0 19G 0 part
24+
# └─rhel-root 253:0 0 10G 0 lvm /sysroot
25+
#
26+
zerombr
27+
clearpart --all --disklabel gpt
28+
part biosboot --fstype=biosboot --size=1
29+
part /boot/efi --fstype=efi --size=200
30+
part /boot --fstype=xfs --asprimary --size=800
31+
# Uncomment this line to add a SWAP partition of the recommended size
32+
#part swap --fstype=swap --recommended
33+
part pv.01 --grow
34+
volgroup rhel pv.01
35+
logvol / --vgname=rhel --fstype=xfs --size=REPLACE_LVM_SYSROOT_SIZE --name=root
36+
37+
# Lock root user account
38+
rootpw --lock
39+
40+
41+
%post --log=/var/log/anaconda/post-install.log --erroronfail
42+
43+
# The pull secret is mandatory for MicroShift builds on top of OpenShift, but not OKD
44+
# The /etc/crio/crio.conf.d/microshift.conf references the /etc/crio/openshift-pull-secret file
45+
cat > /etc/crio/openshift-pull-secret <<EOF
46+
REPLACE_OCP_PULL_SECRET_CONTENTS
47+
EOF
48+
chmod 600 /etc/crio/openshift-pull-secret
49+
50+
# Drop in file for microshift base domain
51+
cat > /etc/microshift/config.d/00-microshift-dns.yaml <<EOF
52+
dns:
53+
baseDomain: REPLACE_BASE_DOMAIN
54+
EOF
55+
56+
# Create a default core user, allowing it to run sudo commands without password
57+
useradd -m -d /home/core core
58+
echo -e 'core\tALL=(ALL)\tNOPASSWD: ALL' > /etc/sudoers.d/microshift
59+
60+
# Add authorized ssh keys
61+
mkdir -m 700 /home/core/.ssh
62+
cat > /home/core/.ssh/authorized_keys <<EOF
63+
REPLACE_CORE_AUTHORIZED_KEYS_CONTENTS
64+
EOF
65+
chmod 600 /home/core/.ssh/authorized_keys
66+
67+
68+
# Set static hostname
69+
echo "REPLACE_HOSTNAME" > /etc/hostname
70+
chmod 644 /etc/hostname
71+
72+
# Support to boot for UEFI and legacy mode
73+
grub2-install --target=i386-pc /dev/vda
74+
75+
# Make podman rootless available
76+
mkdir -p /home/core/.config/systemd/user/default.target.wants
77+
ln -s /usr/lib/systemd/user/podman.socket /home/core/.config/systemd/user/default.target.wants/podman.socket
78+
79+
mkdir -p /home/core/.config/containers
80+
tee /home/core/.config/containers/containers.conf <<EOF
81+
[containers]
82+
netns="bridge"
83+
rootless_networking="cni"
84+
EOF
85+
86+
# Make sure core user directory contents ownership is correct
87+
chown -R core:core /home/core/
88+
89+
touch /etc/containers/podman-machine
90+
91+
tee /etc/containers/registries.conf.d/999-podman-machine.conf <<EOF
92+
unqualified-search-registries=["docker.io"]
93+
EOF
94+
95+
# Enable linger for core user to make sure podman socket work when user not logged in
96+
mkdir -p /var/lib/systemd/linger/
97+
touch /var/lib/systemd/linger/core
98+
%end
99+
"""

0 commit comments

Comments
 (0)