Repository navigation
Expand file tree
/
Copy pathDockerfile
More file actions
109 lines (97 loc) · 5.26 KB
/
Copy pathDockerfile
File metadata and controls
109 lines (97 loc) · 5.26 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
# check=error=true
# renovate: datasource=github-tags depName=radvd-project/radvd
ARG RADVD_VERSION=v2.21
# github-tags exposes the git sha, not the tarball hash, hence the repin marker.
# repin: dep=radvd-project/radvd url=https://github.com/radvd-project/radvd/releases/download/{version}/radvd-{version_nov}.tar.gz
ARG RADVD_SHA256=09e5cf7712397463fd35ebca71f3c05f7d31cff9246513f12d03a359c40b089c
FROM alpine:3.24.4@sha256:f59abe656b692d901e184be3445e084786602108599d2a51d229c0f5a48c71bf AS builder
SHELL ["/bin/ash", "-eo", "pipefail", "-c"]
RUN apk add --no-cache bison build-base curl flex linux-headers pkgconf
ARG RADVD_VERSION
ARG RADVD_SHA256
WORKDIR /build/radvd
# Fetch the release ASSET, not the auto-generated tag archive: only the asset's bytes are stable enough to SHA-pin.
# The CycloneDX fragment is emitted from this same RUN so the URL is spelled once — the bytes fetched, the digest
# verified and the published download_url cannot drift apart. CPE: the NVD dictionary carries exactly one
# vendor:product for radvd, radvd.litech:radvd; the sometimes-guessed litech:router_advertisement_daemon has no entry.
# --with-pidfile spells upstream's own default path resolved (Alpine's /var/run is a symlink to /run), so the
# file lands in a directory every Alpine image ships. `make gram.h` first works around a parallel-build race.
RUN url="https://github.com/radvd-project/radvd/releases/download/${RADVD_VERSION}/radvd-${RADVD_VERSION#v}.tar.gz" \
&& tarball="${url##*/}" \
&& curl -fsSL --connect-timeout 10 --max-time 120 --retry 7 --retry-max-time 150 --retry-all-errors -o "$tarball" "$url" \
&& echo "${RADVD_SHA256} ${tarball}" | sha256sum -c - \
&& tar xzf "$tarball" --strip-components=1 --no-same-owner \
&& rm "$tarball" \
&& ./configure \
--prefix=/usr \
--with-pidfile=/run/radvd.pid \
&& make gram.h \
&& make -j"$(nproc)" \
&& strip radvd radvdump \
&& install -D -m 755 radvd /out/usr/sbin/radvd \
&& install -D -m 755 radvdump /out/usr/sbin/radvdump \
&& install -D -m 644 COPYRIGHT /out/usr/share/licenses/radvd/COPYRIGHT \
# Syft inventories the final image from Alpine's APK database only, so this
# source-built payload is invisible to the signed release SBOM without it.
&& cat > /out/radvd.cdx.json <<EOF
{
"bomFormat": "CycloneDX",
"specVersion": "1.5",
"version": 1,
"components": [
{
"bom-ref": "pkg:generic/radvd@${RADVD_VERSION#v}",
"type": "application",
"name": "radvd",
"version": "${RADVD_VERSION#v}",
"purl": "pkg:generic/radvd@${RADVD_VERSION#v}?download_url=${url}&checksum=sha256:${RADVD_SHA256}",
"cpe": "cpe:2.3:a:radvd.litech:radvd:${RADVD_VERSION#v}:*:*:*:*:*:*:*"
}
]
}
EOF
# No --chmod: BuildKit applies it to the destination DIRECTORY it creates as well as to
# the files, so --chmod=644 shipped /usr/share/licenses/docker-radvd/ as drw-r--r-- and
# only root could traverse it. Both files are already 0644 in git.
COPY LICENSE NOTICE /out/usr/share/licenses/docker-radvd/
FROM alpine:3.24.4@sha256:f59abe656b692d901e184be3445e084786602108599d2a51d229c0f5a48c71bf AS base
ARG PKG_REFRESH=static
# The `echo` is load-bearing: BuildKit keys a RUN on the args it CONSUMES, so dropping it
# leaves the upgrade on a cached layer and the image ships stale packages, silently.
RUN echo "OS package refresh: ${PKG_REFRESH}" \
&& apk upgrade --no-cache \
&& addgroup -S radvd \
&& adduser -S -D -H -G radvd radvd
COPY --from=builder /out/usr/sbin/ /usr/sbin/
COPY --from=builder /out/radvd.cdx.json /usr/share/sbom/radvd.cdx.json
COPY --from=builder /out/usr/share/licenses /usr/share/licenses
COPY --chmod=755 entrypoint.sh /usr/local/bin/entrypoint.sh
FROM base AS test
ARG RADVD_VERSION
COPY tests/smoke.sh tests/radvd.conf tests/radvd.bad.conf /tmp/tests/
# tests/smoke.sh matches radvd's malformed-config rejection against the
# RadvdConfigError pattern in alerts/logql.yaml, so that fatal path keeps matching
# the published rule. startup_latch_test.sh and ci_contract_test.sh read README.md.
COPY alerts/logql.yaml /tmp/alerts/logql.yaml
COPY README.md /tmp/README.md
COPY tests/shell /tmp/tests/shell
# lib.sh puts REPO_ROOT at /tmp in the image and startup_latch_test.sh reads
# $REPO_ROOT/docs/how-it-works.md; without this COPY the suite exits 1 and no marker
# is written.
COPY docs/how-it-works.md /tmp/docs/how-it-works.md
# The suite's userland is the point: run.sh needs bash (installed here and discarded
# with this stage) while awk, sed, grep and tr are the image's BusyBox applets — a
# host-only run can be green while BusyBox fails.
# ${RADVD_VERSION:?} fails the build if the ARG wiring breaks, so the in-image version assertion cannot be silently skipped.
RUN apk add --no-cache bash \
&& RADVD_EXPECTED_VERSION="${RADVD_VERSION:?}" sh /tmp/tests/smoke.sh \
&& ENTRYPOINT=/usr/local/bin/entrypoint.sh bash /tmp/tests/shell/run.sh \
&& touch /tests-passed
# `final` must remain last: the CI gate builds the default target, and the marker
# COPY is what forces the test stage to build and pass first.
FROM base AS final
COPY --from=test /tests-passed /tests-passed
COPY licenses/ /usr/share/licenses/
HEALTHCHECK --interval=30s --timeout=5s --retries=3 --start-period=15s \
CMD ["pidof", "radvd"]
ENTRYPOINT ["/usr/local/bin/entrypoint.sh"]