Skip to content

Commit 7607810

Browse files
authored
Merge pull request #2758 from polarathene/patch-2
ci: `Dockerfile` - Support local and git builds with the openSUSE Leap image
2 parents 5719fcc + bf89580 commit 7607810

3 files changed

Lines changed: 86 additions & 50 deletions

File tree

Dockerfile

Lines changed: 36 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -6,41 +6,57 @@ ARG INSTALL_ROOT=/rootfs
66
FROM opensuse/leap:${LEAP_VERSION} AS builder
77
ARG CACHE_ZYPPER=/tmp/cache/zypper
88
ARG INSTALL_ROOT
9-
10-
11-
# /etc/os-release provides $VERSION_ID below.
12-
# We don't need the openh264.repo and the non-oss repos, just costs build time (repo caches).
13-
14-
RUN source /etc/os-release \
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).
1513
&& zypper removerepo repo-openh264 repo-non-oss repo-update-non-oss \
1614
&& export ZYPPER_OPTIONS=( --releasever "${VERSION_ID}" --installroot "${INSTALL_ROOT}" --cache-dir "${CACHE_ZYPPER}" ) \
1715
&& zypper "${ZYPPER_OPTIONS[@]}" --gpg-auto-import-keys refresh \
1816
&& zypper "${ZYPPER_OPTIONS[@]}" --non-interactive install --download-in-advance --no-recommends \
1917
bash procps grep gawk sed coreutils busybox ldns libidn2-0 socat openssl curl \
20-
&& zypper "${ZYPPER_OPTIONS[@]}" clean --all
21-
## Cleanup (reclaim approx 13 MiB):
22-
# None of this content should be relevant to the container:
23-
RUN rm -r "${INSTALL_ROOT}/usr/share/"{licenses,man,locale,doc,help,info}
24-
# Functionality that the container doesn't need:
25-
RUN rm "${INSTALL_ROOT}/usr/share/misc/termcap" \
26-
&& rm -r "${INSTALL_ROOT}/usr/lib/sysimage/rpm"
18+
&& zypper "${ZYPPER_OPTIONS[@]}" clean --all \
19+
## Cleanup (reclaim approx 13 MiB):
20+
# 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"
2724

2825

29-
# Create a new image with the contents of $INSTALL_ROOT
30-
FROM scratch
26+
# Create a new image with the contents of ${INSTALL_ROOT}
27+
FROM scratch AS base-leap
3128
ARG INSTALL_ROOT
3229
COPY --link --from=builder ${INSTALL_ROOT} /
33-
# Link busybox to tar, see #2403. Create user + (home with SGID set):
34-
RUN ln -s /usr/bin/busybox /usr/bin/tar \
30+
RUN \
31+
# Creates symlinks for any other commands that busybox can provide that
32+
# aren't already provided by coreutils (notably hexdump + tar, see #2403):
33+
# NOTE: `busybox --install -s` is not supported via the leap package, manually symlink commands.
34+
ln -s /usr/bin/busybox /usr/bin/tar \
3535
&& ln -s /usr/bin/busybox /usr/bin/hexdump \
36+
&& ln -s /usr/bin/busybox /usr/bin/xxd \
37+
# Add a non-root user `testssl`, this is roughly equivalent to the `useradd` command:
38+
# useradd --uid 1000 --user-group --create-home --shell /bin/bash testssl
3639
&& echo 'testssl:x:1000:1000::/home/testssl:/bin/bash' >> /etc/passwd \
3740
&& echo 'testssl:x:1000:' >> /etc/group \
3841
&& echo 'testssl:!::0:::::' >> /etc/shadow \
3942
&& install --mode 2755 --owner testssl --group testssl --directory /home/testssl \
40-
&& ln -s /home/testssl/testssl.sh /usr/local/bin/
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
4145

42-
# Copy over build context (after filtered by .dockerignore): bin/ etc/ testssl.sh
43-
COPY --chown=testssl:testssl . /home/testssl/
46+
# Runtime config:
4447
USER testssl
4548
ENTRYPOINT ["testssl.sh"]
4649
CMD ["--help"]
50+
51+
# Final image stage (add `testssl.sh` project files)
52+
# Choose either one as the final stage (defaults to last stage, `dist-local`)
53+
54+
# 62MB Image (Remote repo clone, cannot filter content through `.dockerignore`):
55+
FROM base-leap AS dist-git
56+
ARG GIT_URL=https://github.com/testssl/testssl.sh.git
57+
ARG GIT_BRANCH
58+
ADD --chown=testssl:testssl ${GIT_URL}#${GIT_BRANCH?branch-required} /home/testssl
59+
60+
# 54MB Image (Local repo copy from build context, uses `.dockerignore`):
61+
FROM base-leap AS dist-local
62+
COPY --chown=testssl:testssl . /home/testssl/

Dockerfile-alpine

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,18 +4,19 @@ RUN apk add --no-cache bash procps drill coreutils libidn curl socat openssl xxd
44
&& adduser -G testssl -g "testssl user" -s /bin/bash -D testssl \
55
&& ln -s /home/testssl/testssl.sh /usr/local/bin/testssl.sh
66

7+
# Runtime config:
78
USER testssl
89
ENTRYPOINT ["testssl.sh"]
910
CMD ["--help"]
1011

11-
# Final image stage (add testssl.sh project files)
12+
# Final image stage (add `testssl.sh` project files)
1213
# Choose either one as the final stage (defaults to last stage, `dist-git`)
1314

14-
# 30MB Image (Local repo copy from build context, uses `.dockerignore`):
15+
# 27MB Image (Local repo copy from build context, uses `.dockerignore`):
1516
FROM base-alpine AS dist-local
1617
COPY --chown=testssl:testssl . /home/testssl/
1718

18-
# 38MB Image (Remote repo clone, cannot filter content through `.dockerignore`):
19+
# 35MB Image (Remote repo clone, cannot filter content through `.dockerignore`):
1920
FROM base-alpine AS dist-git
2021
ARG GIT_URL=https://github.com/testssl/testssl.sh.git
2122
ARG GIT_BRANCH

Dockerfile.md

Lines changed: 46 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -1,47 +1,66 @@
11
## Usage
22

3-
### From git directory
3+
Run the image with `testssl.sh` options appended (default is `--help`). The container entrypoint is already set to `testsl.sh` as the command for convenience.
44

5-
```
6-
docker build .
5+
```bash
6+
docker run --rm -it ghcr.io/testssl/testssl.sh:3.2 --fs github.com
77
```
88

9-
Catch is when you run without image tags you need to catch the ID when building
9+
### Output files
1010

11-
```
12-
[..]
13-
---> 889fa2f99933
14-
Successfully built 889fa2f99933
15-
```
11+
Keep in mind that any output file (_`--log`, `--html`, `--json`, etc._) will be created within the container.
1612

17-
More comfortable is
13+
Use a volume bind mount to a local host directory to access the files outside of the container. Set a working directory for the container and any options output prefix can then use a relative path, like this example for `--htmfile`:
1814

19-
```
20-
docker build -t mytestssl .
21-
docker run --rm -t mytestssl example.com
15+
```bash
16+
# Writes the HTML output to the host path: /tmp/example.com_p443-<date>-<time>.html
17+
docker run --rm -it -v /tmp:/data --workdir /data ghcr.io/testssl/testssl.sh:3.2 --htmlfile ./ example.com
2218
```
2319

24-
You can also supply command line options like:
20+
**NOTE:**
21+
- The UID/GID ownership of the file will be created by the container user `testssl` (`1000:1000`), with permissions `644`.
22+
- Your host directory must permit the `testssl` container user or group to write to that host volume. You could alternatively use [`docker cp`](https://docs.docker.com/reference/cli/docker/container/cp/).
2523

26-
```
27-
docker run -t mytestssl --help
28-
docker run --rm -t mytestssl -p --header example.com
29-
```
24+
### From DockerHub or GHCR
3025

31-
### From dockerhub or GHCR
26+
You can pull the image from either of these registries:
27+
- DockerHub: [`drwetter/testssl.sh`](https://hub.docker.com/r/drwetter/testssl.sh)
28+
- GHCR: [`ghcr.io/testssl/testssl.sh`](https://github.com/testssl/testssl.sh/pkgs/container/testssl.sh)
3229

33-
You can pull the image from dockerhub or ghcr.io and run:
30+
Supported tags:
31+
- `3.2` / `latest`
32+
- `3.0` is the old stable version ([soon to become EOL](https://github.com/testssl/testssl.sh/tree/3.0#status))
3433

35-
``docker run --rm -t drwetter/testssl.sh --fs example.com`` or ``docker run --rm -t ghcr.io/testssl/testssl.sh --fs example.com``
34+
### Building
3635

37-
Supported tags are: ``3.2`` and ``latest``, which are the same. ``3.0`` is the old stable version which will be retired soon.
36+
You can build with a standard `git clone` + `docker build`. Tagging the image will make it easier to reference.
3837

39-
``docker run --rm -t drwetter/testssl.sh:stable example.com`` or ``docker run --rm -t ghcr.io/testssl/testssl.sh:stable example.com``
38+
```bash
39+
mkdir /tmp/testssl && cd /tmp/testssl
40+
git clone --branch 3.2 --depth 1 https://github.com/testssl/testssl.sh .
41+
docker build --tag localhost/testssl.sh:3.2 .
42+
```
4043

41-
Keep in mind that any output file (--log, --html, --json etc.) will be created within the container. If you wish to have this created in a local directory on your host you can mount a volume into the container and change the output prefix where the container user has write access to, e.g.:
44+
There are two base images available:
45+
- `Dockerfile` (openSUSE Leap), glibc-based + faster.
46+
- `Dockerfile-alpine` (Alpine), musl-based + half the size.
4247

43-
```
44-
docker run --rm -t -v /tmp:/data drwetter/testssl.sh --htmlfile /data/ example.com
48+
Alpine is made available if you need broarder platform support or an image about 30MB smaller at the expense of speed.
49+
50+
#### Remote build context + `Dockerfile`
51+
You can build with a single command instead via:
52+
53+
```bash
54+
docker build --tag localhost/testssl.sh:3.2 https://github.com/testssl/testssl.sh.git#3.2
4555
```
4656

47-
which writes the HTML output to ``/tmp/example.com_p443-<date>-<time>.html.`` The uid/gid is the one from the docker user. Normally the file is 644. testssl.sh's docker container uses a non-root user (usually with user/groupid 1000:1000).
57+
This will produce a slightly larger image however as `.dockerignore` is not supported with remote build contexts.
58+
59+
If you would like to build the Alpine image instead this way, just provide the alternative `Dockerfile` via `--file`:
60+
61+
```bash
62+
docker build \
63+
--tag localhost/testssl.sh:3.2-alpine \
64+
--file https://raw.githubusercontent.com/testssl/testssl.sh/3.2/Dockerfile-alpine \
65+
https://github.com/testssl/testssl.sh.git#3.2
66+
```

0 commit comments

Comments
 (0)