Skip to content

Commit a8c5f02

Browse files
committed
Simplify the alpine image build
This fix an issue with apk 3.0 in alpine 3.22.0, which now requires some privileges to create another db
1 parent d773280 commit a8c5f02

1 file changed

Lines changed: 13 additions & 15 deletions

File tree

Dockerfile

Lines changed: 13 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -58,14 +58,12 @@ SHELL ["/bin/ash", "-euxo", "pipefail", "-c"]
5858

5959
# install the alpine-base package (for the user space)
6060
# TODO: or a subset of the packages?
61-
RUN \
62-
mkdir -p /out/etc; \
63-
cp -R /etc/apk/ /out/etc/apk/; \
64-
apk add --no-cache --root /out --initdb alpine-base
61+
RUN apk add --no-cache alpine-base
6562

6663
# install the kernel (without installing the dependencies)
6764
ARG FLAVOR=lts
68-
RUN apk fetch --no-cache --quiet --stdout linux-$FLAVOR | tar -xz --directory=/out --exclude=.*
65+
# RUN apk add --no-cache linux-$FLAVOR linux-firmware-none && apk del mkinitfs
66+
RUN apk fetch --no-cache --quiet --stdout linux-$FLAVOR | tar -xz --directory=/ --exclude=.*
6967

7068
# setup the system
7169
# by default, we remove all the TTYs in inittab, so they should be added back with the INITTAB_TTYS argument
@@ -80,23 +78,23 @@ BOOT_SERVICES="modules sysctl hostname bootmisc syslog networking hwclock" \
8078
DEFAULT_SERVICES="acpid ntpd" \
8179
SHUTDOWN_SERVICES="mount-ro killprocs savecache"
8280

83-
RUN \
84-
echo "$HOSTNAME" >/out/etc/hostname; \
85-
mv /out/etc/hosts /out/etc/hosts.target; \
86-
printf "127.0.1.1\t%s\n" "$HOSTNAME" >>/out/etc/hosts.target; \
87-
printf "%b\n" "$CMDLINE" >/out/boot/cmdline; \
88-
sed -i -E '/tty/d;/^#/d;/^$/d' /out/etc/inittab; \
89-
printf "%b\n" "$INITTAB_TTYS" >>/out/etc/inittab; \
90-
printf "%b\n" "$NETWORK_INTERFACES" >/out/etc/network/interfaces; \
91-
rc_add() { for svc in $2; do ln -s "/etc/init.d/$svc" "/out/etc/runlevels/$1/$svc"; done; }; \
81+
RUN --mount=type=bind,from=alpine-base,source=/,destination=/base \
82+
echo "$HOSTNAME" >/etc/hostname; \
83+
cp /base/etc/hosts /etc/hosts.target; \
84+
printf "127.0.1.1\t%s\n" "$HOSTNAME" >>/etc/hosts.target; \
85+
printf "%b\n" "$CMDLINE" >/boot/cmdline; \
86+
sed -i -E '/tty/d;/^#/d;/^$/d' /etc/inittab; \
87+
printf "%b\n" "$INITTAB_TTYS" >>/etc/inittab; \
88+
printf "%b\n" "$NETWORK_INTERFACES" >/etc/network/interfaces; \
89+
rc_add() { for svc in $2; do rc-update add $svc $1; done; }; \
9290
rc_add sysinit "$SYSINIT_SERVICES"; \
9391
rc_add boot "$BOOT_SERVICES"; \
9492
rc_add default "$DEFAULT_SERVICES"; \
9593
rc_add shutdown "$SHUTDOWN_SERVICES"
9694

9795
# =========================================================
9896
FROM scratch AS bootable-alpine
99-
COPY --from=bootable-alpine-rootfs /out /
97+
COPY --from=bootable-alpine-rootfs / /
10098
ENTRYPOINT ["/bin/sh"]
10199

102100
# =========================================================

0 commit comments

Comments
 (0)