Skip to content

Commit

Permalink
infra: Use Fedora source for Live ISO builds
Browse files Browse the repository at this point in the history
We need to add script and Dockerfile to our templating solution.
  • Loading branch information
jkonecny12 committed Aug 31, 2023
1 parent 09c2e91 commit e610539
Show file tree
Hide file tree
Showing 4 changed files with 212 additions and 6 deletions.
9 changes: 8 additions & 1 deletion dockerfile/anaconda-live-iso-creator/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,3 +1,10 @@
# ======================================
# WARNING!
# THIS FILE IS GENERATED FROM A TEMPLATE
# DO NOT EDIT THIS FILE MANUALLY!
# ======================================
# The template is located in: Dockerfile.j2

# Dockerfile to build Live iso with Anaconda from the repository.
# To find out how to build this container please look on the ./tests/README.rst file.
# This container has to be started as --privileged and with precreated loop devices otherwise
Expand Down Expand Up @@ -49,7 +56,7 @@ RUN set -ex; \
# required for ksflatten
pykickstart; \
mkdir /fedora-kickstarts; \
git clone https://pagure.io/fedora-kickstarts.git /fedora-kickstarts; \
git clone -b f39 https://pagure.io/fedora-kickstarts.git /fedora-kickstarts; \
cd /fedora-kickstarts; \
ksflatten -o /lorax/workstation.ks -c fedora-live-workstation.ks; \
# cleanups of parts which don't need to be part of the container
Expand Down
67 changes: 67 additions & 0 deletions dockerfile/anaconda-live-iso-creator/Dockerfile.j2
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
# Dockerfile to build Live iso with Anaconda from the repository.
# To find out how to build this container please look on the ./tests/README.rst file.
# This container has to be started as --privileged and with precreated loop devices otherwise
# lorax won't work correctly.
#
# Execution example:
#
# make -f ./Makefile.am container-rpms-scratch # Create Anaconda RPM in `pwd`/result/... directory.
# sudo make -f ./Makefile.am anaconda-live-iso-creator-build
#
# # /var/tmp tmpfs speeds up lorax and avoids https://bugzilla.redhat.com/show_bug.cgi?id=1906364
# sudo podman run -i --rm --privileged --tmpfs /var/tmp:rw,mode=1777 -v `pwd`/result/build/01-rpm-build:/anaconda-rpms:ro -v `pwd`/output-dir:/images:z quay.io/rhinstaller/anaconda-live-iso-creator:master
#
# note:
# - add `--network=slirp4netns` if you need to share network with host computer to reach
# repositories (VPN for example)
#

# The `image` arg will set base image for the build.
# possible values:
# registry.fedoraproject.org/fedora:35
# registry.fedoraproject.org/fedora:rawhide
# registry-proxy.engineering.redhat.com/rh-osbs/ubi9:latest # private source
# registry.access.redhat.com/ubi8/ubi # public source
ARG image
FROM ${image}
# FROM starts a new build stage with new ARGs. Put any ARGs after FROM unless required by the FROM itself.
# see https://docs.docker.com/engine/reference/builder/#understand-how-arg-and-from-interact
LABEL maintainer=anaconda-devel@lists.fedoraproject.org

# Prepare environment and install build dependencies
RUN set -ex; \
dnf update -y; \
dnf install -y \
createrepo_c \
# for clonning cockpit-project/bots/
git \
# to be able to read ip of the container and pass that to VM
iproute \
lorax-lmc-virt; \
dnf clean all

RUN mkdir /lorax /anaconda-rpms /images

# Generate kickstart file for Fedora Workstation
# TODO: add our local repository to the kickstart file
RUN set -ex; \
dnf install -y \
# required for ksflatten
pykickstart; \
mkdir /fedora-kickstarts; \
{% if distro_release == "rawhide" %}
git clone -b main https://pagure.io/fedora-kickstarts.git /fedora-kickstarts; \
{% else %}
git clone -b f{$ distro_release $} https://pagure.io/fedora-kickstarts.git /fedora-kickstarts; \
{% endif %}
cd /fedora-kickstarts; \
ksflatten -o /lorax/workstation.ks -c fedora-live-workstation.ks; \
# cleanups of parts which don't need to be part of the container
dnf remove -y pykickstart; dnf clean all; \
rm -rf /fedora-kickstarts

COPY ["lmc-build", "/"]

WORKDIR /lorax

ENTRYPOINT /lmc-build
17 changes: 12 additions & 5 deletions dockerfile/anaconda-live-iso-creator/lmc-build
Original file line number Diff line number Diff line change
@@ -1,4 +1,11 @@
#!/bin/bash
# ======================================
# WARNING!
# THIS FILE IS GENERATED FROM A TEMPLATE
# DO NOT EDIT THIS FILE MANUALLY!
# ======================================
# The template is located in: lmc-build.j2

#
# Build a Fedora Workstation Live ISO by livemedia-creator. The Live iso will be stored in the `/images/` directory.
# We have to build the RPMs files of Anaconda first and then add them as volume
Expand Down Expand Up @@ -56,12 +63,12 @@ popd


#### get ISO for build ####
# download new cockpit CI rawhide iso (it's gated)
# download new cockpit CI iso (it's gated)
mkdir /var/tmp/lmc-build
pushd /var/tmp/lmc-build
git clone --depth 1 https://github.com/cockpit-project/bots.git
./bots/image-download fedora-rawhide-boot
cp -L ./bots/images/fedora-rawhide-boot /lorax/fedora-rawhide-boot.iso
./bots/image-download fedora-39-boot
cp -L ./bots/images/fedora-39-boot /lorax/fedora-boot.iso
rm -rf ./bots
popd

Expand Down Expand Up @@ -104,10 +111,10 @@ livemedia-creator \
--iso-name="Fedora-Workstation.iso" \
--macboot \
--project=Fedora-Workstation-Live \
--releasever=Rawhide \
--releasever=39 \
--vcpus=$proposed_cpu \
--ram=$proposed_mem \
--iso=/lorax/fedora-rawhide-boot.iso \
--iso=/lorax/fedora-boot.iso \
--ks=$WORKSTATION_KS \
--logfile="$LOG_DIR/build.log" \
--resultdir=/lorax/result
Expand Down
125 changes: 125 additions & 0 deletions dockerfile/anaconda-live-iso-creator/lmc-build.j2
Original file line number Diff line number Diff line change
@@ -0,0 +1,125 @@
#!/bin/bash
#
# Build a Fedora Workstation Live ISO by livemedia-creator. The Live iso will be stored in the `/images/` directory.
# We have to build the RPMs files of Anaconda first and then add them as volume
# mount to /anaconda-rpms to the container (could be RO mount).
#
# sudo make -f ./Makefile.am container-rpms-scratch
# sudo podman run -i --rm --privileged --tmpfs /var/tmp:rw,mode=1777 -v `pwd`/result/build/01-rpm-build:/anaconda-rpms:ro -v `pwd`/output-dir:/images:z quay.io/rhinstaller/anaconda-live-iso-creator:master
#
# Input directory:
# /anaconda-rpms/ (Anaconda RPM files for the build)
#
# Output directory:
# /images (Where the boot.iso will be stored)

set -eux

INPUT_RPMS=/anaconda-rpms/
REPO_DIR=/tmp/anaconda-rpms/
OUT_DIR=/images/
LOG_DIR="$OUT_DIR"/logs/
# fedora-kickstarts clone during the Anaconda build
# https://pagure.io/fedora-kickstarts/tree/main
WORKSTATION_KS=/lorax/workstation.ks

HTTP_LOG=$LOG_DIR/http.log
HTTP_PID=/lorax/httpd.pid

start_http_server() {
python3 -m http.server -d . 1>&2 2>$HTTP_LOG &
echo "$!" > $HTTP_PID

# extract container IP
IP=$(ip addr | grep 'state UP' -A2 | tail -n1 | awk '{print $2}' | cut -f1 -d'/')
echo "http://$IP:8000/"
}

stop_http_server() {
kill -s SIGTERM "$(cat $HTTP_PID)"
}

# pre-create loop devices manually. In the container you can't use losetup for that.
mknod -m 0660 /dev/loop0 b 7 0 2> /dev/null || true
mknod -m 0660 /dev/loop1 b 7 1 2> /dev/null || true
mknod -m 0660 /dev/loop2 b 7 2 2> /dev/null || true
mknod -m 0660 /dev/loop3 b 7 3 2> /dev/null || true


#### create and serve repo from provided Anaconda RPMs ####
mkdir -p $REPO_DIR
cp -a $INPUT_RPMS/* $REPO_DIR || echo "RPM files can't be copied!" # We could just do the build with official repositories only
createrepo_c $REPO_DIR
pushd $REPO_DIR
HTTP_SERVER=$(start_http_server)
popd


#### get ISO for build ####
# download new cockpit CI iso (it's gated)
mkdir /var/tmp/lmc-build
pushd /var/tmp/lmc-build
git clone --depth 1 https://github.com/cockpit-project/bots.git
{% if distro_release == "rawhide" %}
./bots/image-download fedora-rawhide-boot
cp -L ./bots/images/fedora-rawhide-boot /lorax/fedora-boot.iso
{% else %}
./bots/image-download fedora-{$ distro_release $}-boot
cp -L ./bots/images/fedora-{$ distro_release $}-boot /lorax/fedora-boot.iso
{% endif %}
rm -rf ./bots
popd


#### find out recommended power for qemu ####
mem=$(awk -F":" '$1~/MemTotal/{print int($2 / 1024) }' /proc/meminfo )
cpu=$(nproc)

# use 80% of available power
proposed_cpu=$((cpu*80/100))
proposed_mem=$((mem*80/100))

# do not get lower than 2048MB (default) and 1 cpu
if [ $proposed_mem -lt 2048 ]; then
proposed_mem=2048
fi

if [ $proposed_cpu -lt 1 ]; then
proposed_cpu=1
fi

echo "Virtual machine will start with cpu:$proposed_cpu memory:${proposed_mem}MB"


#### add webui dependencies to kickstart ####
cat >> $WORKSTATION_KS << EOF
repo --name anaconda-local --baseurl=$HTTP_SERVER
%packages
anaconda-webui
%end
EOF

cp $WORKSTATION_KS /images/logs/input.ks

#### build the live ISO ####
livemedia-creator \
--make-iso \
--iso-only \
--iso-name="Fedora-Workstation.iso" \
--macboot \
--project=Fedora-Workstation-Live \
--releasever={$ distro_release $} \
--vcpus=$proposed_cpu \
--ram=$proposed_mem \
--iso=/lorax/fedora-boot.iso \
--ks=$WORKSTATION_KS \
--logfile="$LOG_DIR/build.log" \
--resultdir=/lorax/result

stop_http_server

cp ./result/Fedora-Workstation.iso "$OUT_DIR"

# fix permissions to user permissions on the built artifacts
chown -Rv --reference="$INPUT_RPMS" "$OUT_DIR"

0 comments on commit e610539

Please sign in to comment.