4444# => either add the git-sync GID or else set --root, mount a volume,
4545# and manage volume permissions to access that volume
4646
47- FROM {ARG_FROM}
47+ #############################################################################
48+ # First we prepare the image that we want, regardless of build layers.
49+ #############################################################################
50+ FROM {ARG_FROM} as prep
4851
4952RUN echo "deb http://deb.debian.org/debian/ buster-backports main contrib" > \
50- /etc/apt/sources.list.d/backports.list \
51- && apt update \
52- && apt -y upgrade \
53- && apt -y install \
53+ /etc/apt/sources.list.d/backports.list
54+ RUN apt-get update
55+ RUN apt-get -y upgrade
56+ RUN apt-get -y install --no-install-recommends \
5457 ca-certificates \
5558 coreutils \
5659 socat \
57- openssh-client \
58- && apt -y -t buster-backports install git \
59- && rm -rf /var/lib/apt/lists/*
60+ openssh-client
61+ # We want a newer git than the norm.
62+ RUN apt-get -y -t buster-backports install --no-install-recommends \
63+ git
64+ # libcurl3-gnutls=7.74.0-1.2~bpo10+1 is broken. We can downgrade for now until
65+ # the fix reaches upstream.
66+ # https://github.com/kubernetes/git-sync/issues/395
67+ RUN apt-get -y install --no-install-recommends --allow-downgrades \
68+ libcurl3-gnutls:amd64=7.64.0-4+deb10u2
69+ RUN apt-get -y autoremove
70+ RUN rm -rf /var/lib/apt/lists/*
6071
6172# By default we will run as this user...
6273RUN echo "git-sync:x:65533:65533::/tmp:/sbin/nologin" >> /etc/passwd
@@ -73,21 +84,29 @@ RUN echo "git-sync:x:65533:git-sync" >> /etc/group
7384# they use our git-sync group. If the user needs a different group or sets
7485# $GIT_SYNC_ROOT or --root, their values will override this, and we assume they
7586# are handling permissions themselves.
76- ENV GIT_SYNC_ROOT=/tmp/git
7787RUN mkdir -m 02775 /tmp/git && chown 65533:65533 /tmp/git
7888
89+ # Add the platform-specific binary.
90+ COPY bin/{ARG_OS}_{ARG_ARCH}/{ARG_BIN} /{ARG_BIN}
91+
92+ # Add third-party licenses.
93+ COPY .licenses/ /LICENSES/
94+
95+ #############################################################################
96+ # Now we make a "clean" final image.
97+ #############################################################################
98+ FROM scratch
99+ COPY --from=prep / /
100+
79101# Run as non-root by default. There's simply no reason to run as root.
80102USER 65533:65533
81103
82104# Setting HOME ensures that whatever UID this ultimately runs as can write to
83105# files like ~/.gitconfig.
84106ENV HOME=/tmp
107+ WORKDIR /tmp
85108
86- # Add the platform-specific binary.
87- COPY bin/{ARG_OS}_{ARG_ARCH}/{ARG_BIN} /{ARG_BIN}
88-
89- # Add third-party licenses.
90- COPY .licenses/ /LICENSES/
109+ # Default values for flags.
110+ ENV GIT_SYNC_ROOT=/tmp/git
91111
92- WORKDIR /tmp
93112ENTRYPOINT ["/{ARG_BIN}"]
0 commit comments