Skip to content

Commit f371eb3

Browse files
author
Paulo Gomes
committed
Fix static build for armv7
Leverage libraries installed in base-debian11 (glibc, libssl and openssl) therefore refrain from linking libc/libdl and ignore unresolved symbols at build time. Libssl had to be kept as the behaviour without it is not consistent across all supported architectures. Signed-off-by: Paulo Gomes <[email protected]>
1 parent 7abe759 commit f371eb3

File tree

1 file changed

+7
-6
lines changed

1 file changed

+7
-6
lines changed

Dockerfile

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -66,12 +66,13 @@ COPY internal/ internal/
6666
ENV CGO_ENABLED=1
6767
ARG TARGETPLATFORM
6868

69-
# ARCH armv7 requires additional linking to build correctly.
70-
# Note that the order in which the libraries appear in -extldflags are relevant, changing them will cause the build to break.
71-
RUN if [ "$(xx-info march)" = "armv7l" ]; then export ADDITIONAL_LINKING="/lib/ld-linux-armhf.so.3"; else export ADDITIONAL_LINKING=""; fi && \
72-
xx-go build \
73-
-ldflags "-s -w -extldflags \"/usr/lib/$(xx-info triple)/libssh2.a /usr/lib/$(xx-info triple)/libssl.a /usr/lib/$(xx-info triple)/libcrypto.a /usr/lib/$(xx-info triple)/libz.a /usr/lib/$(xx-info triple)/libdl.a /usr/lib/$(xx-info triple)/libc.a ${ADDITIONAL_LINKING} -static\"" \
74-
-tags 'netgo osusergo static_build' -o source-controller -trimpath main.go;
69+
# The dependencies being statically built are: libgit2, libssh2, libssl, libcrypto and libz.
70+
# Others (such as libc, librt, libdl and libpthread) are resolved at run-time.
71+
# To decrease the likelihood of such dependencies being out of sync, the base build image
72+
# should be aligned with the target (i.e. same debian variant).
73+
RUN xx-go build \
74+
-ldflags "-s -w -extldflags \"/usr/lib/$(xx-info triple)/libssh2.a /usr/lib/$(xx-info triple)/libssl.a /usr/lib/$(xx-info triple)/libcrypto.a /usr/lib/$(xx-info triple)/libz.a -Wl,--unresolved-symbols=ignore-in-object-files -Wl,-allow-shlib-undefined -static\"" \
75+
-tags 'netgo,osusergo,static_build' -o source-controller -trimpath main.go;
7576

7677
# Cannot use distroless/static due to lingering dependencies on libnss.
7778
FROM gcr.io/distroless/base-debian11 as controller

0 commit comments

Comments
 (0)