Our pipeline builds every service image with docker build --build-arg GIT_SHA set to the commit being built. The Dockerfile turns that into a label, org.opencontainers.image.revision, and into an environment variable that the service prints at /version. In May someone tidied our shared Dockerfile template. The base image tag became an argument too, and all the ARG lines were gathered at the top of the file, above FROM, where they looked neat.
In October an order export started writing dates in the wrong format, and the first question in the incident channel was which commit was running. docker inspect showed the revision label as an empty string. /version returned an empty string. So did every image we had built since May, across nineteen services. We worked the commit out from deploy timestamps, which took forty minutes we did not have.
An ARG declared before the first FROM belongs to the global scope of the Dockerfile, and the only lines that can use it there are FROM lines.…