@@ -3,7 +3,7 @@ ARG GO_VERSION=1.17
3
3
ARG XX_VERSION=1.1.0
4
4
5
5
ARG 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
7
7
8
8
FROM --platform=$BUILDPLATFORM tonistiigi/xx:${XX_VERSION} AS xx
9
9
FROM ${LIBGIT2_IMG}:${LIBGIT2_TAG} as libgit2
@@ -16,6 +16,15 @@ FROM go-${TARGETOS} AS build-base-bullseye
16
16
17
17
# Copy the build utilities
18
18
COPY --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
+
19
28
COPY --from=libgit2 /Makefile /libgit2/
20
29
21
30
# Install the libgit2 build dependencies
@@ -28,9 +37,6 @@ FROM build-base-${BASE_VARIANT} as libgit2-bullseye
28
37
29
38
ARG TARGETPLATFORM
30
39
31
- # build libgit2 in release mode
32
- ARG BUILD_TYPE=Release
33
-
34
40
# First build libgit2 statically, this ensures that all its dependencies
35
41
# will be statically available as well.
36
42
ARG BUILD_SHARED_LIBS=OFF
@@ -39,6 +45,8 @@ RUN FLAGS=$(xx-clang --print-cmake-defines) make -C /libgit2 libgit2
39
45
# Rebuild libgit2 this time to generate the shared libraries.
40
46
ARG BUILD_SHARED_LIBS=ON
41
47
RUN 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
42
50
43
51
44
52
FROM libgit2-${BASE_VARIANT} as build
@@ -70,20 +78,25 @@ ARG TARGETPLATFORM
70
78
# Others (such as libc, librt, libdl and libpthread) are resolved at run-time.
71
79
# To decrease the likelihood of such dependencies being out of sync, the base build image
72
80
# 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;
76
86
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
79
89
80
90
# Link repo to the GitHub Container Registry image
81
91
LABEL org.opencontainers.image.source="https://github.com/fluxcd/source-controller"
82
92
93
+ ARG TARGETPLATFORM
94
+ RUN apt update && apt install -y ca-certificates
95
+
83
96
# Copy over binary from build
84
97
COPY --from=build /workspace/source-controller /usr/local/bin/
98
+ COPY --from=libgit2-bullseye /libgit2/built-on-glibc-version /
85
99
COPY ATTRIBUTIONS.md /
86
100
87
- # leverages nonroot available in gcr.io/distroless/base-debian11
88
- USER nonroot
101
+ USER 65534:65534
89
102
ENTRYPOINT [ "source-controller" ]
0 commit comments