@@ -3,7 +3,7 @@ ARG GO_VERSION=1.17
33ARG XX_VERSION=1.1.0
44
55ARG LIBGIT2_IMG=ghcr.io/fluxcd/golang-with-libgit2
6- ARG LIBGIT2_TAG=libgit2-1.1.1-2
6+ ARG LIBGIT2_TAG=libgit2-1.1.1-3
77
88FROM --platform=$BUILDPLATFORM tonistiigi/xx:${XX_VERSION} AS xx
99FROM ${LIBGIT2_IMG}:${LIBGIT2_TAG} as libgit2
@@ -16,6 +16,15 @@ FROM go-${TARGETOS} AS build-base-bullseye
1616
1717# Copy the build utilities
1818COPY --from=xx / /
19+
20+ # Align golang base image with bookworm.
21+ # TODO: Replace this with a golang bookworm variant, once that is released.
22+ RUN echo "deb http://deb.debian.org/debian bookworm main" > /etc/apt/sources.list.d/bookworm.list \
23+ && echo "deb-src http://deb.debian.org/debian bookworm main" /etc/apt/sources.list.d/bookworm.list \
24+ && xx-apt update \
25+ && xx-apt -t bookworm upgrade -y \
26+ && xx-apt -t bookworm install -y curl
27+
1928COPY --from=libgit2 /Makefile /libgit2/
2029
2130# Install the libgit2 build dependencies
@@ -28,9 +37,6 @@ FROM build-base-${BASE_VARIANT} as libgit2-bullseye
2837
2938ARG TARGETPLATFORM
3039
31- # build libgit2 in release mode
32- ARG BUILD_TYPE=Release
33-
3440# First build libgit2 statically, this ensures that all its dependencies
3541# will be statically available as well.
3642ARG BUILD_SHARED_LIBS=OFF
@@ -39,6 +45,8 @@ RUN FLAGS=$(xx-clang --print-cmake-defines) make -C /libgit2 libgit2
3945# Rebuild libgit2 this time to generate the shared libraries.
4046ARG BUILD_SHARED_LIBS=ON
4147RUN FLAGS=$(xx-clang --print-cmake-defines) make -C /libgit2 libgit2
48+ # Logs glibc version used at built time. The final image must be compatible with it.
49+ RUN ldd --version ldd > /libgit2/built-on-glibc-version
4250
4351
4452FROM libgit2-${BASE_VARIANT} as build
@@ -70,20 +78,25 @@ ARG TARGETPLATFORM
7078# Others (such as libc, librt, libdl and libpthread) are resolved at run-time.
7179# To decrease the likelihood of such dependencies being out of sync, the base build image
7280# 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;
81+ RUN FLAGS=$(pkg-config --static --libs --cflags libssh2 libgit2 libssl libcrypto zlib openssl) \
82+ xx-go build \
83+ -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 ${FLAGS} -static\" " \
84+ -tags 'netgo,osusergo,static_build' \
85+ -o source-controller -trimpath main.go;
7686
77- # Cannot use distroless/static due to lingering dependencies on libnss .
78- FROM gcr.io/distroless/base-debian11 as controller
87+ # The target image must aligned with apt sources used for libgit2 .
88+ FROM debian:bookworm-slim as controller
7989
8090# Link repo to the GitHub Container Registry image
8191LABEL org.opencontainers.image.source="https://github.com/fluxcd/source-controller"
8292
93+ ARG TARGETPLATFORM
94+ RUN apt update && apt install -y ca-certificates
95+
8396# Copy over binary from build
8497COPY --from=build /workspace/source-controller /usr/local/bin/
98+ COPY --from=libgit2-bullseye /libgit2/built-on-glibc-version /
8599COPY ATTRIBUTIONS.md /
86100
87- # leverages nonroot available in gcr.io/distroless/base-debian11
88- USER nonroot
101+ USER 65534:65534
89102ENTRYPOINT [ "source-controller" ]
0 commit comments