Skip to content

Instantly share code, notes, and snippets.

@agracey
Created July 1, 2022 02:51
Show Gist options
  • Save agracey/cb6f14e0bbdd505c90dcff60a65a56e3 to your computer and use it in GitHub Desktop.
Save agracey/cb6f14e0bbdd505c90dcff60a65a56e3 to your computer and use it in GitHub Desktop.
#!/bin/bash
# Note: ros-image-build requires the input image to be pushed
# due to buildx usage.
# Export this here so users dont need to
export DOCKER_BUILDKIT=1
set -e
build()
{
dockerfile | docker build -f - --build-arg IMAGE="${IMAGE}" . "${@}"
}
dockerfile()
{
cat << "EOF"
FROM quay.io/costoolkit/elemental:v0.0.15-a81c51f AS elemental
FROM opensuse/leap:15.3 AS build
COPY --from=elemental /usr/bin/elemental /usr/bin
RUN sed -i -s 's/^# rpm.install.excludedocs/rpm.install.excludedocs/' /etc/zypp/zypp.conf
RUN zypper ref
RUN zypper in -y squashfs xorriso curl unzip git qemu-arm qemu-x86 qemu-tools tar e2fsprogs dosfstools pigz go1.16 qemu-uefi-aarch64 mtools rsync
RUN mkdir -p /iso/iso-overlay/boot/grub2
RUN echo -e \
'search --file --set=root /boot/kernel.xz\n'\
'set default=0\n'\
'set timeout=10\n'\
'set timeout_style=menu\n'\
'set linux=linux\n'\
'set initrd=initrd\n'\
'if [ "${grub_cpu}" = "x86_64" -o "${grub_cpu}" = "i386" -o "${grub_cpu}" = "arm64" ];then\n'\
' if [ "${grub_platform}" = "efi" ]; then\n'\
' if [ "${grub_cpu}" != "arm64" ]; then\n'\
' set linux=linuxefi\n'\
' set initrd=initrdefi\n'\
' fi\n'\
' fi\n'\
'fi\n'\
'if [ "${grub_platform}" = "efi" ]; then\n'\
' echo "Please press 't' to show the boot menu on this console"\n'\
'fi\n'\
'set font=($root)/boot/${grub_cpu}/loader/grub2/fonts/unicode.pf2\n'\
'if [ -f ${font} ];then\n'\
' loadfont ${font}\n'\
'fi\n'\
'menuentry "Install Elemental Teal to disk" --class os --unrestricted {\n'\
' echo Loading kernel...\n'\
' $linux ($root)/boot/kernel.xz cdroot root=live:CDLABEL=COS_LIVE rd.live.dir=/ rd.live.squashimg=rootfs.squashfs console=tty1 console=ttyS0 rd.cos.disable rancheros.install.automatic=false rancheros.install.config_url=/run/initramfs/live/config\n'\
' echo Loading initrd...\n'\
' $initrd ($root)/boot/rootfs.xz\n'\
'}\n'\
'\n'\
'if [ "${grub_platform}" = "efi" ]; then\n'\
' hiddenentry "Text mode" --hotkey "t" {\n'\
' set textmode=true\n'\
' terminal_output console\n'\
' }\n'\
'fi\n' > /iso/iso-overlay/boot/grub2/grub.cfg
ARG CONFIG
RUN if [ -n "$CONFIG" ]; then echo "$CONFIG" > /iso/iso-overlay/config; cp /iso/iso-overlay/config /iso/iso-overlay/config.yaml; fi
ARG IMAGE
RUN cd /iso; elemental --debug build-iso -n output --repo quay.io/costoolkit/releases-teal --overlay-iso /iso/iso-overlay $IMAGE
FROM scratch AS default
COPY --from=build /iso/output.iso /
EOF
}
usage()
{
echo "Usage:"
echo " $0 IMAGE _ [ISO_CLOUD_CONFIG]"
echo
echo " IMAGE: a Docker image"
echo " ISO_CLOUD_CONFIG: An option file that will be used as the default cloud-init in an ISO"
}
IMAGE=$1
CONFIG=$3
if [ -z "${IMAGE}" ] || echo "$@" | grep -q -- -h; then
usage
exit 1
fi
if [ -n "$CONFIG" ]; then
CONFIG_DATA="$(<$CONFIG)"
fi
build -o build/ --build-arg CONFIG="${CONFIG_DATA}" --build-arg IMAGE=${IMAGE}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment