Skip to content

Commit 573e98b

Browse files
allisonkarlitskayacgwalters
authored andcommitted
examples/bls: improve Containerfiles caching
Run the "install packages into the base image" section as the first thing that happens, before the cfsctl binary gets copied in. This means that we have to regenerate the initramfs, which is duplicated work, but it enables caching of the package installation, which takes much longer and involves downloading updated packages (which drift with time). This helps a lot with iterative local testing, and the bls images are the ones that I usually use for that. Also enable package caching for Arch and Debian by adding the appropriate bind mounts. Use `apt-get` instead of CLI-API-unstable `apt`. Use the new `kernel-install add-all` verb where applicable. We leave Ubuntu out of this change for now: I keep ending up with two initramfs files generated and I'm not sure how to workaround the weird use of dracut there. We can circle back to this later. Signed-off-by: Allison Karlitskaya <[email protected]>
1 parent a3f44ea commit 573e98b

File tree

4 files changed

+39
-18
lines changed

4 files changed

+39
-18
lines changed

examples/bls/Containerfile

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
FROM fedora:42
2-
COPY extra /
32
RUN --mount=type=cache,target=/var/cache/libdnf5 <<EOF
43
set -eux
54

@@ -12,9 +11,15 @@ RUN --mount=type=cache,target=/var/cache/libdnf5 <<EOF
1211
strace \
1312
util-linux \
1413
systemd
14+
EOF
1515

16+
# --- Everything above this line should hopefully stay cached ---
17+
18+
COPY cfsctl /usr/bin
19+
COPY extra /
20+
RUN --mount=type=cache,target=/var/cache/libdnf5 <<EOF
21+
kernel-install add-all
1622
systemctl enable systemd-networkd
1723
passwd -d root
1824
mkdir /sysroot
1925
EOF
20-
COPY cfsctl /usr/bin

examples/bls/Containerfile.arch

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,8 @@
11
FROM archlinux AS base
2-
COPY extra /
3-
RUN <<EOF
2+
RUN --mount=type=cache,target=/var/cache/pacman/pkg \
3+
--mount=type=cache,target=/var/lib/pacman/sync <<EOF
44
set -eux
55

6-
touch /etc/machine-id
7-
echo 'root=/dev/vda2' > /etc/kernel/cmdline
8-
96
pacman -Syu --noconfirm
107
pacman -Sy --noconfirm \
118
btrfs-progs \
@@ -16,11 +13,19 @@ RUN <<EOF
1613
openssh \
1714
skopeo \
1815
strace
16+
EOF
17+
18+
# --- Everything above this line should hopefully stay cached ---
1919

20-
kernel-install add "$(ls /usr/lib/modules)" /usr/lib/modules/"$(ls /usr/lib/modules)"/vmlinuz
20+
COPY cfsctl /usr/bin
21+
COPY extra /
22+
RUN <<EOF
23+
touch /etc/machine-id
24+
echo 'root=/dev/vda2' > /etc/kernel/cmdline
25+
26+
kernel-install add-all
2127

2228
systemctl enable systemd-networkd systemd-resolved sshd
2329
passwd -d root
2430
mkdir /sysroot
2531
EOF
26-
COPY cfsctl /usr/bin

examples/bls/Containerfile.rawhide

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
FROM fedora:rawhide
2-
COPY extra /
32
RUN --mount=type=cache,target=/var/cache/libdnf5 <<EOF
43
set -eux
54

@@ -12,9 +11,15 @@ RUN --mount=type=cache,target=/var/cache/libdnf5 <<EOF
1211
strace \
1312
systemd \
1413
util-linux
14+
EOF
15+
16+
# --- Everything above this line should hopefully stay cached ---
1517

18+
COPY cfsctl /usr/bin
19+
COPY extra /
20+
RUN <<EOF
1621
systemctl enable systemd-networkd
1722
passwd -d root
23+
kernel-install add-all
1824
mkdir /sysroot
1925
EOF
20-
COPY cfsctl /usr/bin

examples/bls/Containerfile.rhel9

Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,7 @@
11
# FROM docker.io/redhat/ubi9 missing: dosfstools, kernel
22
FROM quay.io/centos/centos:9
3-
COPY extra /
43
RUN --mount=type=cache,target=/var/cache/dnf <<EOF
54
set -eux
6-
mkdir -p /etc/kernel
7-
touch /etc/kernel/cmdline
8-
9-
echo layout=bls | tee /etc/kernel/install.conf
10-
115
dnf --setopt keepcache=1 install --allowerasing -y \
126
NetworkManager \
137
composefs \
@@ -19,9 +13,21 @@ RUN --mount=type=cache,target=/var/cache/dnf <<EOF
1913
strace \
2014
systemd \
2115
util-linux
16+
EOF
17+
18+
# --- Everything above this line should hopefully stay cached ---
19+
20+
COPY cfsctl /usr/bin
21+
COPY extra /
22+
RUN <<EOF
23+
set -eux
24+
mkdir -p /etc/kernel
25+
touch /etc/kernel/cmdline
26+
27+
echo layout=bls | tee /etc/kernel/install.conf
28+
kernel-install add $(ls /usr/lib/modules) /usr/lib/modules/*/vmlinuz
2229

2330
systemctl enable tmp.mount
2431
passwd -d root
2532
mkdir /sysroot
2633
EOF
27-
COPY cfsctl /usr/bin

0 commit comments

Comments
 (0)