A two-stage build whose only product is one binary

Why the GTP prober image has a compiler in it, and why none of that compiler reaches production.

Containers

The whole Dockerfile

ARG CLOUDPROBER_VERSION=v0.13.7

FROM alpine:latest AS build
RUN apk add musl-dev linux-headers git gcc make
COPY fix-ifs-with-no-addr.patch .
RUN git clone https://github.com/ThomasHabets/gtping.git \
    && cd gtping \
    && git apply /fix-ifs-with-no-addr.patch \
    && sed -i '/#include"gtping.h"/a #include <time.h>' src/monotonic_generic.c \
    && ./configure \
    && make \
    && make install

FROM cloudprober/cloudprober:${CLOUDPROBER_VERSION}
LABEL GTP_PING_VERSION=gtping-0.15-master-patch
EXPOSE 9313
COPY --from=build /usr/local/bin/gtping /usr/local/bin/gtping

Seventeen lines, and the second stage adds three things to an upstream image: a label, a port (9313, for metrics), and one binary.

Why two stages, when the usual reason is weak

The familiar argument for a multi-stage build is image size, and it is weak here. Upstream cloudprober is the base either way, so the saving is the Alpine build layer alone. Real — gcc, make, git, musl-dev and a cloned source tree all stay behind — but a side effect, not the point.

The reason that matters is different. The final stage is cloudprober/cloudprober (upstream's image, upstream's contents), and we have no business rebuilding it. Compiling C inside it would be absurd; the image ships a Go binary and a config loader, with no toolchain at all. A second stage is how you add a binary to somebody else's image without taking responsibility for the rest of it — build where a toolchain is cheap, copy only the artefact, keep the base byte-identical to the published one.

So the two stages split along ownership, never along build-and-runtime. They are our toolchain (Alpine, disposable) and their image (pinned, untouched), and COPY --from is the single seam between them.

What the pinning buys, and what it misses

ARG CLOUDPROBER_VERSION=v0.13.7 pins the base. LABEL GTP_PING_VERSION=gtping-0.15-master-patch records what was built into it. Both are worth having (one fixes the base, one records the payload), and between them the build stays irreproducible:

  • FROM alpine:latest is unpinned (latest at build time, whenever that was), so the compiler moves under you.
  • git clone carries no ref, so it takes upstream's default branch at whatever commit exists that day.

That second one is why the label says master-patch instead of a version. It is honest labelling of an unpinned input (0.15-ish, plus our patch), and that is as precise as the clone allows.

The unpinned Alpine bit us in February 2026, fifteen months after the image first built. A newer gcc stopped supplying time.h transitively (through gtping.h, which had carried it), monotonic_generic.c failed to compile, and the sed line above is the repair. Nothing in the repository had changed; the base underneath it had. A digest pin would have deferred that break; it would not have prevented it, because deferral is all a pin ever does.

The build cache and the registry

The Makefile is three targets, and the build one carries the detail that matters:

build:
    docker build --build-arg BUILDKIT_INLINE_CACHE=1 -t $(IMAGE_NAME) .

BUILDKIT_INLINE_CACHE=1 writes cache metadata into the pushed image, so a later build can use the published image as a cache source. The clone-patch-compile layer is the expensive one and the one worth caching; it changes when the patch changes (twice, in fifteen months).

The test target does nothing except say so:

test:
    @echo 'Test is performed in the base images'

That is a fair description of the repository, and less of a gap than it looks. Upstream cloudprober has tests, gtping has whatever upstream gave it, and a test suite for seventeen lines of Dockerfile would be a test of Docker itself. The property worth verifying is narrower — that the binary survives a host with an unaddressed interface — and that is a property of the patch, and no build step can establish it.

What it cost

Four commits over fifteen months: the image, a Jenkins-to-GitHub-Actions migration, the time.h repair, and a promote_to_prod flag so a development build that passes is promoted instead of rebuilt. A promoted image is the same image (same digest, same bytes); a rebuilt one is a different image from the same Dockerfile. With an unpinned base and an unpinned clone (two moving inputs, one artefact), that distinction is the only thing keeping development and production on the same image.