Repository navigation
Expand file tree
/
Copy pathDockerfile
More file actions
34 lines (32 loc) · 1.6 KB
/
Copy pathDockerfile
File metadata and controls
34 lines (32 loc) · 1.6 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
# syntax=docker/dockerfile:1
# Two-stage build producing a small, statically linked (musl) image. The runtime
# can't be distroless: the proxy delegates the git wire protocol to the system
# `git` binary, and Alpine is the smallest base that ships one.
FROM rust:alpine AS build
# musl-dev for the static libc; build-base gives the C toolchain `ring` (rustls'
# crypto provider) compiles its assembly with.
RUN apk add --no-cache build-base
WORKDIR /src
COPY . .
RUN cargo build --release --locked --bin git-cache-proxy
FROM alpine:3.24
# The cache root is created owned by the runtime user so the image works as
# non-root on runtimes with no fsGroup equivalent (Docker, ECS).
# tini is PID 1: git leaves orphans (detached auto maintenance, descendants of a
# killed process group) that only PID 1 can reap, and the proxy does not.
RUN apk add --no-cache git ca-certificates tini \
&& rm -rf /var/cache/apk/* \
&& addgroup -S -g 10001 gitcache \
&& adduser -S -D -u 10001 -G gitcache gitcache \
&& install -d -o gitcache -g gitcache /var/cache/git-cache-proxy
COPY --from=build /src/target/release/git-cache-proxy /usr/local/bin/git-cache-proxy
# Bare mirrors live here; mount a volume for persistence across restarts.
ENV GITCACHEPROXY_CACHE_ROOT=/var/cache/git-cache-proxy
VOLUME /var/cache/git-cache-proxy
EXPOSE 8080
# Numeric, so Kubernetes `runAsNonRoot` can verify it.
USER 10001:10001
# Under another init (`docker run --init`, a shared Kubernetes PID namespace)
# tini is not PID 1; as a subreaper it still reaps instead of only warning.
ENV TINI_SUBREAPER=1
ENTRYPOINT ["/sbin/tini", "--", "/usr/local/bin/git-cache-proxy"]