Skip to content

Commit 97f25a5

Browse files
dustymabejlebon
authored andcommitted
Update to work with COSA 10e397b
There was a pretty large refactor tha landed in COSA in coreos/coreos-assembler#3943 Let's pick up those changes here and change the way we call runvm-osbuild to adapt.
1 parent 7e61fc5 commit 97f25a5

File tree

2 files changed

+43
-46
lines changed

2 files changed

+43
-46
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,7 @@ mode and some software installed:
7878
sudo dnf update -y
7979
sudo setenforce 0
8080
sudo sed -i -e 's/SELINUX=enforcing/SELINUX=permissive/' /etc/selinux/config
81-
sudo dnf install -y osbuild osbuild-tools osbuild-ostree podman jq xfsprogs e2fsprogs
81+
sudo dnf install -y osbuild osbuild-tools osbuild-ostree podman jq xfsprogs e2fsprogs zip
8282
```
8383

8484
Now you should be able to generate an image with something like:

custom-coreos-disk-images.sh

Lines changed: 42 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -18,11 +18,22 @@ set -eux -o pipefail
1818
# sudo ./custom-coreos-disk-images.sh \
1919
# --ociarchive /path/to/coreos.ociarchive --platforms qemu,metal
2020
#
21-
# - coreos.ociarchive.x86_64.qemu.qcow2
22-
# - coreos.ociarchive.x86_64.metal.qcow2
21+
# - coreos-qemu.x86_64.qcow2
22+
# - coreos-metal.x86_64.raw
2323

2424
ARCH=$(arch)
2525

26+
# A list of supported platforms and the filename suffix of the main
27+
# artifact that platform produces.
28+
declare -A SUPPORTED_PLATFORMS=(
29+
['applehv']='raw.gz'
30+
['gcp']='tar.gz'
31+
['hyperv']='vhdx.zip'
32+
['metal4k']='raw'
33+
['metal']='raw'
34+
['qemu']='qcow2'
35+
)
36+
2637
check_rpm() {
2738
req=$1
2839
if ! rpm -q "$req" &>/dev/null; then
@@ -32,7 +43,7 @@ check_rpm() {
3243
}
3344

3445
check_rpms() {
35-
reqs=(osbuild osbuild-tools osbuild-ostree jq xfsprogs e2fsprogs)
46+
reqs=(osbuild osbuild-tools osbuild-ostree jq xfsprogs e2fsprogs zip)
3647
for req in "${reqs[@]}"; do
3748
check_rpm "$req"
3849
done
@@ -113,74 +124,60 @@ main() {
113124
image_size=16384 # RHCOS
114125
fi
115126

116-
# Make a local tmpdir
127+
# Make a local tmpdir and outidr
117128
tmpdir=$(mktemp -d ./tmp-osbuild-XXX)
129+
outdir="${tmpdir}/out"
130+
mkdir $outdir
118131

119132
# Freeze on specific version for now to increase stability.
120133
#gitreporef="main"
121-
gitreporef="3a76784b37fe073718a7f9d9d67441d9d8b34c10"
134+
gitreporef="10e397bfd966a60e5e43ec3ad49443c0c9323d74"
122135
gitrepotld="https://raw.githubusercontent.com/coreos/coreos-assembler/${gitreporef}/"
123136
pushd "${tmpdir}"
124137
curl -LO --fail "${gitrepotld}/src/runvm-osbuild"
125138
chmod +x runvm-osbuild
126-
for manifest in "coreos.osbuild.${ARCH}.mpp.yaml" platform.{applehv,gcp,hyperv,metal,qemu}.ipp.yaml; do
139+
for manifest in "coreos.osbuild.${ARCH}.mpp.yaml" platform.{applehv,gcp,hyperv,metal,qemu,qemu-secex}.ipp.yaml; do
127140
curl -LO --fail "${gitrepotld}/src/osbuild-manifests/${manifest}"
128141
done
129142
popd
130143

131144

132-
for platform in "${PLATFORMS[@]}"; do
133-
134-
suffix=
135-
case $platform in
136-
applehv)
137-
suffix=raw
138-
;;
139-
gcp)
140-
suffix=tar.gz
141-
;;
142-
hyperv)
143-
suffix=vhdx
144-
;;
145-
metal)
146-
suffix=raw
147-
;;
148-
qemu)
149-
suffix=qcow2
150-
;;
151-
*)
152-
echo "unknown platform provided"
153-
exit 1
154-
;;
155-
esac
156-
outfile="./$(basename $OCIARCHIVE).${ARCH}.${platform}.${suffix}"
157-
158-
# - rootfs size is only used on s390x secex so we pass "0" here
159-
# - extra-kargs from image.yaml/image.json is currently empty
160-
# on RHCOS but we may want to start picking it up from inside
161-
# the container image (/usr/share/coreos-assembler/image.json)
162-
# in the future. https://github.com/openshift/os/blob/master/image.yaml
163-
cat > "${tmpdir}/diskvars.json" << EOF
145+
# - rootfs size is only used on s390x secex so we pass "0" here
146+
# - extra-kargs from image.yaml/image.json is currently empty
147+
# on RHCOS but we may want to start picking it up from inside
148+
# the container image (/usr/share/coreos-assembler/image.json)
149+
# in the future. https://github.com/openshift/os/blob/master/image.yaml
150+
runvm_osbuild_config_json="${tmpdir}/runvm-osbuild-config.json"
151+
cat > "${runvm_osbuild_config_json}" << EOF
164152
{
153+
"artifact-name-prefix": "$(basename -s .ociarchive $OCIARCHIVE)",
165154
"osname": "${osname}",
166155
"deploy-via-container": "true",
167156
"ostree-container": "${OCIARCHIVE}",
168-
"image-type": "${platform}",
169157
"container-imgref": "${imgref}",
170158
"metal-image-size": "3072",
171159
"cloud-image-size": "${image_size}",
172160
"rootfs-size": "0",
173161
"extra-kargs-string": ""
174162
}
175163
EOF
176-
"${tmpdir}/runvm-osbuild" \
177-
--config "${tmpdir}/diskvars.json" \
178-
--filepath "./${outfile}" \
179-
--mpp "${tmpdir}/coreos.osbuild.${ARCH}.mpp.yaml"
180-
echo "Created $platform image file at: ${outfile}"
164+
"${tmpdir}/runvm-osbuild" \
165+
--config "${runvm_osbuild_config_json}" \
166+
--mpp "${tmpdir}/coreos.osbuild.${ARCH}.mpp.yaml" \
167+
--outdir "${outdir}" \
168+
--platforms "$(IFS=,; echo "${PLATFORMS[*]}")"
169+
170+
for platform in "${PLATFORMS[@]}"; do
171+
# Set the filename of the artifact and the local image path
172+
# where from the OSBuild out directory where it resides.
173+
suffix="${SUPPORTED_PLATFORMS[$platform]}"
174+
imgname=$(basename -s .ociarchive $OCIARCHIVE)-${platform}.${ARCH}.${suffix}
175+
imgpath="${outdir}/${platform}/${imgname}"
176+
mv "${imgpath}" ./
177+
echo "Created $platform image file at: ${imgname}"
181178
done
182179

183-
rm -f "${tmpdir}"/*; rmdir "${tmpdir}" # Cleanup
180+
rm -rf "${outdir}"; rm -f "${tmpdir}"/*; rmdir "${tmpdir}" # Cleanup
184181
}
185182

186183
main "$@"

0 commit comments

Comments
 (0)