1- FROM alpine:3.17
1+ # syntax=docker.io/docker/dockerfile:1
2+ # HereDoc (EOF) feature (avoids needing `&& \`) requires BuildKit:
3+ # https://docs.docker.com/engine/reference/builder/#here-documents
4+ ARG LEAP_VERSION=15.4
5+ ARG CACHE_ZYPPER=/tmp/cache/zypper
6+ ARG INSTALL_ROOT=/rootfs
27
3- RUN apk update && \
4- apk upgrade && \
5- apk add bash procps drill git coreutils libidn curl socat openssl xxd && \
6- rm -rf /var/cache/apk/* && \
7- adduser -D -s /bin/bash testssl && \
8- ln -s /home/testssl/testssl.sh /usr/local/bin/
8+ FROM opensuse/leap:${LEAP_VERSION} as builder
9+ ARG CACHE_ZYPPER
10+ ARG INSTALL_ROOT
11+ # --mount is only necessary for persisting the zypper cache on the build host,
12+ # Paired with --cache-dir below, RUN layer invalidation does not clear this cache.
13+ # Not useful for CI, only local builds that retain the storage.
14+ RUN --mount=type=cache,target="${CACHE_ZYPPER}" ,sharing=locked <<EOF
15+ INSTALL_DEPS=()
16+
17+ # Mandatory commands. coreutils required over busybox for date command:
18+ # https://github.com/drwetter/testssl.sh/commit/d1f03801738c87b6af39372c45e048af78c73c09
19+ INSTALL_DEPS+=(bash procps grep gawk sed coreutils)
20+
21+ # Support better performance and debugging than hexdump via xxd:
22+ # https://github.com/drwetter/testssl.sh/pull/1862
23+ # busybox-util-linux (mandatory: hexdump) + busybox-vi (optional: xxd)
24+ INSTALL_DEPS+=( busybox-util-linux busybox-vi )
25+
26+ # Support IDN (Internationalized Domain Names) lookups with drill:
27+ # https://github.com/drwetter/testssl.sh/pull/1326
28+ INSTALL_DEPS+=( ldns libidn2-0 )
29+
30+ # Support StartTLS injection:
31+ # https://github.com/drwetter/testssl.sh/pull/1810
32+ INSTALL_DEPS+=( socat openssl )
33+
34+ # Support --phone-out checks:
35+ # https://github.com/drwetter/testssl.sh/commit/a66f5cfdbcd93427f4408bdd8cfc336488c02bb8
36+ INSTALL_DEPS+=( curl )
37+
38+
39+ # Provides $VERSION_ID
40+ source /etc/os-release
41+
42+ # --releasever required due to no version info in install root.
43+ # --installroot installs to location as if it was the system root.
44+ # --cache-dir with above `RUN --mount` speeds this step up.
45+ ZYPPER_OPTIONS=(
46+ --releasever "${VERSION_ID}"
47+ --installroot "${INSTALL_ROOT}"
48+ --cache-dir "${CACHE_ZYPPER}"
49+ )
50+
51+ # Sync package repos to get latest updates:
52+ zypper ${ZYPPER_OPTIONS[@]} --gpg-auto-import-keys refresh
53+
54+ zypper ${ZYPPER_OPTIONS[@]} --non-interactive install \
55+ --download-in-advance --no-recommends ${INSTALL_DEPS[@]}
56+
57+
58+ # Clears the cache, but this is not stored in the install root location (like DNF does), thus not useful.
59+ # zypper ${ZYPPER_OPTIONS[@]} clean --all
60+
61+ # Unlike DNF, there isn't a `--nodocs` install option, manually remove some excess weight (9 MiB):
62+ rm -r "${INSTALL_ROOT}/usr/share/" {licenses,man,locale,doc,help,info}
63+ # Neither of these should be needed in the container, removes 4MiB
64+ rm "${INSTALL_ROOT}/usr/share/misc/termcap"
65+ rm -r "${INSTALL_ROOT}/usr/lib/sysimage/rpm"
66+ EOF
67+
68+
69+ # Create a new image with the contents of $INSTALL_ROOT
70+ FROM scratch
71+ ARG INSTALL_ROOT
72+ COPY --link --from=builder ${INSTALL_ROOT} /
73+
74+ # zypper package `busybox-adduser` fails to install with `--installroot`,
75+ # while the `shadow` package is too heavy just to add a user.
76+ #
77+ # Temporarily bind mount the `/bin` dir from another image that already
78+ # has the `adduser` command, and it'll update `/etc/{group,passwd,shadow}` for us:
79+ # Absolute path provided as some base images PATH would use those binaries instead,
80+ # `adduser` varies in supported args, so this should avoid any surprises:
81+ RUN --mount=type=bind,from=busybox:latest,source=/bin,target=/bin <<EOF
82+ /bin/adduser -D -s /bin/bash testssl
83+ /bin/ln -s /home/testssl/testssl.sh /usr/local/bin/
84+ EOF
985
1086USER testssl
1187WORKDIR /home/testssl/
@@ -14,5 +90,4 @@ WORKDIR /home/testssl/
1490COPY --chown=testssl:testssl . /home/testssl/
1591
1692ENTRYPOINT ["testssl.sh" ]
17-
1893CMD ["--help" ]
0 commit comments