Skip to content

Commit 5b89995

Browse files
authored
chore: Dockerfile - Adopt HereDoc syntax
1 parent 0d0c5d0 commit 5b89995

2 files changed

Lines changed: 53 additions & 30 deletions

File tree

Dockerfile

Lines changed: 36 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -6,50 +6,61 @@ ARG INSTALL_ROOT=/rootfs
66
FROM opensuse/leap:${LEAP_VERSION} AS builder
77
ARG CACHE_ZYPPER=/tmp/cache/zypper
88
ARG INSTALL_ROOT
9-
RUN \
10-
# /etc/os-release provides ${VERSION_ID} for usage in ZYPPER_OPTIONS:
11-
source /etc/os-release \
12-
# We don't need the openh264.repo and the non-oss repos, just costs build time (repo caches).
13-
&& zypper removerepo repo-openh264 repo-non-oss repo-update-non-oss \
14-
&& export ZYPPER_OPTIONS=( --releasever "${VERSION_ID}" --installroot "${INSTALL_ROOT}" --cache-dir "${CACHE_ZYPPER}" ) \
15-
&& zypper "${ZYPPER_OPTIONS[@]}" --gpg-auto-import-keys refresh \
16-
&& zypper "${ZYPPER_OPTIONS[@]}" --non-interactive install --download-in-advance --no-recommends \
17-
bash procps grep gawk sed coreutils busybox ldns libidn2-0 socat openssl curl \
18-
&& zypper "${ZYPPER_OPTIONS[@]}" clean --all \
19-
## Cleanup (reclaim approx 13 MiB):
9+
RUN <<HEREDOC
10+
# Remove the `openh264` the `non-oss` repos to save on sync time, they're not needed:
11+
zypper removerepo repo-openh264 repo-non-oss repo-update-non-oss
12+
# `/etc/os-release` provides the `VERSION_ID` variable for usage in `ZYPPER_OPTIONS`:
13+
source /etc/os-release
14+
export ZYPPER_OPTIONS=( --releasever "${VERSION_ID}" --installroot "${INSTALL_ROOT}" --cache-dir "${CACHE_ZYPPER}" )
15+
16+
# Install packages to a custom root-fs location (defined in `ZYPPER_OPTIONS`):
17+
zypper "${ZYPPER_OPTIONS[@]}" --gpg-auto-import-keys refresh
18+
zypper "${ZYPPER_OPTIONS[@]}" --non-interactive install --download-in-advance --no-recommends \
19+
bash procps grep gawk sed coreutils busybox ldns libidn2-0 socat openssl curl
20+
21+
# Optional - Avoid `CACHE_ZYPPER` from being redundantly cached in this RUN layer:
22+
# (doesn't improve `INSTALL_ROOT` size thanks to `--cache-dir`)
23+
zypper "${ZYPPER_OPTIONS[@]}" clean --all
24+
25+
# Cleanup (reclaim approx 13 MiB):
2026
# None of this content should be relevant to the container:
21-
&& rm -r "${INSTALL_ROOT}/usr/share/"{licenses,man,locale,doc,help,info} \
22-
"${INSTALL_ROOT}/usr/share/misc/termcap" \
23-
"${INSTALL_ROOT}/usr/lib/sysimage/rpm"
27+
rm -r "${INSTALL_ROOT}/usr/share/"{licenses,man,locale,doc,help,info} \
28+
"${INSTALL_ROOT}/usr/share/misc/termcap" \
29+
"${INSTALL_ROOT}/usr/lib/sysimage/rpm"
30+
HEREDOC
2431

2532

2633
# Create a new image with the contents of ${INSTALL_ROOT}
2734
FROM scratch AS base-leap
2835
ARG INSTALL_ROOT
2936
COPY --link --from=builder ${INSTALL_ROOT} /
30-
RUN \
37+
RUN <<HEREDOC
3138
# Creates symlinks for any other commands that busybox can provide that
3239
# aren't already provided by coreutils (notably hexdump + tar, see #2403):
3340
# NOTE: `busybox --install -s` is not supported via the leap package, manually symlink commands.
34-
ln -s /usr/bin/busybox /usr/bin/tar \
35-
&& ln -s /usr/bin/busybox /usr/bin/hexdump \
36-
&& ln -s /usr/bin/busybox /usr/bin/xxd \
41+
ln -s /usr/bin/busybox /usr/bin/tar
42+
ln -s /usr/bin/busybox /usr/bin/hexdump
43+
ln -s /usr/bin/busybox /usr/bin/xxd
44+
3745
# Add a non-root user `testssl`, this is roughly equivalent to the `useradd` command:
3846
# useradd --uid 1000 --user-group --create-home --shell /bin/bash testssl
39-
&& echo 'testssl:x:1000:1000::/home/testssl:/bin/bash' >> /etc/passwd \
40-
&& echo 'testssl:x:1000:' >> /etc/group \
41-
&& echo 'testssl:!::0:::::' >> /etc/shadow \
42-
&& install --mode 2755 --owner testssl --group testssl --directory /home/testssl \
43-
# The home directory will install a copy of `testssl.sh`, symlink the script to be used as a command:
44-
&& ln -s /home/testssl/testssl.sh /usr/local/bin/testssl.sh
47+
echo 'testssl:x:1000:1000::/home/testssl:/bin/bash' >> /etc/passwd
48+
echo 'testssl:x:1000:' >> /etc/group
49+
echo 'testssl:!::0:::::' >> /etc/shadow
50+
install --mode 2755 --owner testssl --group testssl --directory /home/testssl
51+
52+
# A copy of `testssl.sh` will be added to the home directory,
53+
# symlink to that file so it can be treated as a command:
54+
ln -s /home/testssl/testssl.sh /usr/local/bin/testssl.sh
55+
HEREDOC
4556

4657
# Runtime config:
4758
USER testssl
4859
ENTRYPOINT ["testssl.sh"]
4960
CMD ["--help"]
5061

5162
# Final image stage (add `testssl.sh` project files)
52-
# Choose either one as the final stage (defaults to last stage, `dist-local`)
63+
# Choose either one as the final stage (defaults to the last stage, `dist-local`)
5364

5465
# 62MB Image (Remote repo clone, cannot filter content through `.dockerignore`):
5566
FROM base-leap AS dist-git

Dockerfile.alpine

Lines changed: 17 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,28 @@
1+
# syntax=docker.io/docker/dockerfile:1
2+
13
FROM alpine:3.21 AS base-alpine
2-
RUN apk add --no-cache bash procps drill coreutils libidn curl socat openssl xxd \
3-
&& addgroup testssl \
4-
&& adduser -G testssl -g "testssl user" -s /bin/bash -D testssl \
5-
&& ln -s /home/testssl/testssl.sh /usr/local/bin/testssl.sh
4+
RUN <<HEREDOC
5+
apk add --no-cache bash procps drill coreutils libidn curl socat openssl xxd
6+
7+
# Add a non-root user `testssl`, this is roughly equivalent to the `adduser` command:
8+
# addgroup testssl && adduser -G testssl -g "testssl user" -s /bin/bash -D testssl
9+
echo 'testssl:x:1000:1000::/home/testssl:/bin/bash' >> /etc/passwd
10+
echo 'testssl:x:1000:' >> /etc/group
11+
echo 'testssl:!::0:::::' >> /etc/shadow
12+
install --mode 2755 --owner testssl --group testssl --directory /home/testssl
13+
14+
# A copy of `testssl.sh` will be added to the home directory,
15+
# symlink to that file so it can be treated as a command:
16+
ln -s /home/testssl/testssl.sh /usr/local/bin/testssl.sh
17+
HEREDOC
618

719
# Runtime config:
820
USER testssl
921
ENTRYPOINT ["testssl.sh"]
1022
CMD ["--help"]
1123

1224
# Final image stage (add `testssl.sh` project files)
13-
# Choose either one as the final stage (defaults to last stage, `dist-git`)
25+
# Choose either one as the final stage (defaults to the last stage, `dist-local`)
1426

1527
# 35MB Image (Remote repo clone, cannot filter content through `.dockerignore`):
1628
FROM base-alpine AS dist-git

0 commit comments

Comments
 (0)