-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathDockerfile.static
More file actions
39 lines (33 loc) · 1.32 KB
/
Copy pathDockerfile.static
File metadata and controls
39 lines (33 loc) · 1.32 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
# Builds a fully static SpeedTest binary that runs on any x86_64/aarch64 Linux,
# regardless of the distro's libcurl/libxml2/glibc versions.
#
# docker build -f Dockerfile.static -o dist .
#
# musl is used on purpose: glibc's getaddrinfo needs NSS plugins at runtime and
# cannot be linked statically in a reliable way, while musl resolves DNS in-process.
FROM alpine:3.20 AS builder
RUN apk add --no-cache \
build-base \
cmake \
pkgconf \
curl-dev curl-static \
libxml2-dev libxml2-static \
openssl-dev openssl-libs-static \
zlib-static brotli-static zstd-static nghttp2-static \
c-ares-static libidn2-static libunistring-static \
libpsl-static libssh2-static xz-static
WORKDIR /src
COPY . .
RUN cmake -B /build -S /src -DCMAKE_BUILD_TYPE=Release -DENABLE_STATIC=ON \
&& cmake --build /build --parallel \
&& strip /build/SpeedTest
# The binary must not need a single shared library, or it is not portable.
RUN file /build/SpeedTest \
&& if ldd /build/SpeedTest 2>&1 | grep -q "Not a valid dynamic program"; then \
echo "OK: fully static"; \
else \
echo "FAIL: still dynamically linked:"; ldd /build/SpeedTest; exit 1; \
fi
# `docker build -o dist .` writes the binary straight into ./dist
FROM scratch AS export
COPY --from=builder /build/SpeedTest /SpeedTest