Skip to content

Commit 7e6b88e

Browse files
committed
Use Debian instead of Alpine in container image
This commit changes the base image for the build and controller container images to Debian slim. Reason for this is that it has proven to be hard to produce working executables for AMD64, ARM64 and ARMv7 at all times using Alpine, due to them being dynamically linked and compiled using CGO, and Alpine having constraints like musl that create an extra barrier, especially in combination with our exotic set of dependency constraints. There are a number of trade-offs we have to live with by doing this, not limited to: * An increased build time, the full release pipeline used to take 25-35 minutes, based on the images we have build for testing purposes this seems to have become 35-40 minutes. * An increased image size of roughly two times the (compressed) size of the Alpine based image. Signed-off-by: Hidde Beydals <hello@hidde.co>
1 parent 44dd9d7 commit 7e6b88e

File tree

1 file changed

+26
-13
lines changed

1 file changed

+26
-13
lines changed

Dockerfile

+26-13
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,15 @@
1-
# Docker buildkit multi-arch build requires golang alpine
2-
FROM golang:1.16-alpine as builder
3-
4-
RUN apk add --no-cache gcc pkgconfig libc-dev binutils-gold musl~=1.2 libgit2-dev~=1.1
1+
FROM golang:1.16-buster as builder
2+
3+
# Up-to-date libgit2 dependencies are only available in
4+
# >=bullseye (testing).
5+
RUN echo "deb http://deb.debian.org/debian testing main" >> /etc/apt/sources.list \
6+
&& echo "deb-src http://deb.debian.org/debian testing main" >> /etc/apt/sources.list
7+
RUN set -eux; \
8+
apt-get update \
9+
&& apt-get install -y libgit2-dev/testing zlib1g-dev/testing libssh2-1-dev/testing libpcre3-dev/testing \
10+
&& apt-get clean \
11+
&& apt-get autoremove --purge -y \
12+
&& rm -rf /var/lib/apt/lists/*
513

614
WORKDIR /workspace
715

@@ -24,21 +32,26 @@ COPY internal/ internal/
2432
# build without specifing the arch
2533
RUN CGO_ENABLED=1 go build -o source-controller main.go
2634

27-
FROM alpine:3.13
35+
FROM debian:buster-slim as controller
2836

2937
# link repo to the GitHub Container Registry image
3038
LABEL org.opencontainers.image.source="https://github.com/fluxcd/source-controller"
3139

32-
RUN apk add --no-cache ca-certificates tini libgit2~=1.1 musl~=1.2
40+
# Up-to-date libgit2 dependencies are only available in
41+
# >=bullseye (testing).
42+
RUN echo "deb http://deb.debian.org/debian testing main" >> /etc/apt/sources.list \
43+
&& echo "deb-src http://deb.debian.org/debian testing main" >> /etc/apt/sources.list
44+
RUN set -eux; \
45+
apt-get update \
46+
&& apt-get install -y ca-certificates libgit2-1.1 \
47+
&& apt-get clean \
48+
&& apt-get autoremove --purge -y \
49+
&& rm -rf /var/lib/apt/lists/*
3350

3451
COPY --from=builder /workspace/source-controller /usr/local/bin/
3552

36-
# Create minimal nsswitch.conf file to prioritize the usage of /etc/hosts over DNS queries.
37-
# https://github.com/gliderlabs/docker-alpine/issues/367#issuecomment-354316460
38-
RUN [ ! -e /etc/nsswitch.conf ] && echo 'hosts: files dns' > /etc/nsswitch.conf
39-
40-
RUN addgroup -S controller && adduser -S controller -G controller
53+
RUN groupadd controller && \
54+
useradd --gid controller --shell /bin/sh --create-home controller
4155

4256
USER controller
43-
44-
ENTRYPOINT [ "/sbin/tini", "--", "source-controller" ]
57+
ENTRYPOINT ["source-controller"]

0 commit comments

Comments
 (0)