diff --git a/.github/workflows/package.yml b/.github/workflows/package.yml index 37bc447..e78642f 100644 --- a/.github/workflows/package.yml +++ b/.github/workflows/package.yml @@ -71,3 +71,13 @@ jobs: done docker logs smoke exit 1 + # An orphan is reparented to the container's PID 1; without an init that + # reaps, it stays a zombie (git leaves such orphans after every fetch). + - name: Check orphaned processes are reaped + run: | + docker exec smoke sh -c 'sleep 1 & exit' + sleep 3 + if docker exec smoke ps -o stat | grep -q '^Z'; then + docker exec smoke ps -o pid,ppid,stat,args + exit 1 + fi diff --git a/Dockerfile b/Dockerfile index 8512e60..ff86f42 100644 --- a/Dockerfile +++ b/Dockerfile @@ -14,7 +14,9 @@ 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). -RUN apk add --no-cache git ca-certificates \ +# 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 \ @@ -26,4 +28,7 @@ VOLUME /var/cache/git-cache-proxy EXPOSE 8080 # Numeric, so Kubernetes `runAsNonRoot` can verify it. USER 10001:10001 -ENTRYPOINT ["/usr/local/bin/git-cache-proxy"] +# 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"]