Skip to content

Commit 1212ad8

Browse files
committed
refactor: Support syntax without BuildKit features
These have been available via opt-in prior to v23 of Docker Engine with `DOCKER_BUILDKIT=1` ENV as a prefix to running `docker build`, however it's been requested to avoid the syntax. No HereDoc (multi-line RUN with EOF marker) or `RUN --mount` available. This makes the `busybox` approach a hassle, so I've brought back the explicit creation of user and home dir. Without the cache mounts, bring back `zypper clean`. It's not doing much as the `--cache-dir` is still set, but should reduce disk space for the `builder` layer. Local builds will be slower as a result when this layer is invalidated. AFAIK, this also makes it tricky to use the `ZYPPER_OPTIONS`? So no longer DRY.
1 parent 718eb34 commit 1212ad8

1 file changed

Lines changed: 22 additions & 32 deletions

File tree

Dockerfile

Lines changed: 22 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -6,44 +6,34 @@ ARG INSTALL_ROOT=/rootfs
66
FROM opensuse/leap:${LEAP_VERSION} as builder
77
ARG CACHE_ZYPPER=/tmp/cache/zypper
88
ARG INSTALL_ROOT
9-
# --mount is only necessary for persisting the zypper cache on the build host,
10-
# Paired with --cache-dir below, RUN layer invalidation does not clear this cache.
11-
# Not useful for CI, only local builds that retain the storage.
12-
RUN --mount=type=cache,target="${CACHE_ZYPPER}",sharing=locked <<EOF
13-
# Provides $VERSION_ID
14-
source /etc/os-release
15-
ZYPPER_OPTIONS=(
16-
--releasever "${VERSION_ID}"
17-
--installroot "${INSTALL_ROOT}"
18-
--cache-dir "${CACHE_ZYPPER}"
19-
)
20-
21-
# Sync package repos:
22-
zypper ${ZYPPER_OPTIONS[@]} --gpg-auto-import-keys refresh
23-
24-
zypper ${ZYPPER_OPTIONS[@]} --non-interactive install \
25-
--download-in-advance --no-recommends \
26-
bash procps grep gawk sed coreutils busybox-util-linux busybox-vi ldns libidn2-0 socat openssl curl
27-
28-
29-
## Cleanup (reclaim approx 13 MiB):
30-
# None of this content should be relevant to the container:
31-
rm -r "${INSTALL_ROOT}/usr/share/"{licenses,man,locale,doc,help,info}
32-
# Functionality that the container doesn't need:
33-
rm "${INSTALL_ROOT}/usr/share/misc/termcap"
34-
rm -r "${INSTALL_ROOT}/usr/lib/sysimage/rpm"
35-
EOF
9+
# Usually you could source this from /etc/os-release
10+
# Might not always match the image tag:
11+
ARG VERSION_ID=15.4
12+
RUN zypper --releasever "${VERSION_ID}" --installroot "${INSTALL_ROOT}" --cache-dir "${CACHE_ZYPPER}" \
13+
--gpg-auto-import-keys refresh \
14+
&& zypper --releasever "${VERSION_ID}" --installroot "${INSTALL_ROOT}" --cache-dir "${CACHE_ZYPPER}" \
15+
--non-interactive install --download-in-advance --no-recommends \
16+
bash procps grep gawk sed coreutils busybox-util-linux busybox-vi ldns libidn2-0 socat openssl curl \
17+
&& zypper --releasever "${VERSION_ID}" --installroot "${INSTALL_ROOT}" --cache-dir "${CACHE_ZYPPER}" \
18+
clean --all
19+
## Cleanup (reclaim approx 13 MiB):
20+
# None of this content should be relevant to the container:
21+
RUN rm -r "${INSTALL_ROOT}/usr/share/"{licenses,man,locale,doc,help,info}
22+
# Functionality that the container doesn't need:
23+
RUN rm "${INSTALL_ROOT}/usr/share/misc/termcap" \
24+
&& rm -r "${INSTALL_ROOT}/usr/lib/sysimage/rpm"
3625

3726

3827
# Create a new image with the contents of $INSTALL_ROOT
3928
FROM scratch
4029
ARG INSTALL_ROOT
4130
COPY --link --from=builder ${INSTALL_ROOT} /
42-
WORKDIR /home/testssl
43-
RUN --mount=type=bind,from=busybox:latest,source=/bin,target=/bin <<EOF
44-
/bin/adduser -D -s /bin/bash testssl
45-
/bin/ln -s /home/testssl/testssl.sh /usr/local/bin/
46-
EOF
31+
# Create user + (home with SGID set):
32+
RUN echo 'testssl:x:1000:1000::/home/testssl:/bin/bash' >> /etc/passwd \
33+
&& echo 'testssl:x:1000:' >> /etc/group \
34+
&& echo 'testssl:!::0:::::' >> /etc/shadow \
35+
&& install --mode 2755 --owner testssl --group testssl --directory /home/testssl \
36+
&& ln -s /home/testssl/testssl.sh /usr/local/bin/
4737

4838
# Copy over build context (after filtered by .dockerignore): bin/ etc/ testssl.sh
4939
COPY --chown=testssl:testssl . /home/testssl/

0 commit comments

Comments
 (0)