This proposal builds upon the existing Git labels feature (#1290) which attaches Git metadata to images via labels.
Problem Statement
Currently, there's no simple way to access Git metadata during the build process or at runtime, as the BUILDX_GIT_LABELS feature only adds labels to the final image, they are not accessible during the build process.
Proposed Solution
Add a new config variable, (e.g. BUILDX_GIT_ARGS) that would expose the same Git metadata as build args, making them available during the build process. The build args would be similar to the existing labels:
| Label |
Build Arg |
com.docker.image.source.entrypoint |
SOURCEDOCKERFILE |
org.opencontainers.image.revision |
GITREVISION |
org.opencontainers.image.source |
GITSOURCE |
This follows the same naming pattern as other automatic arguments like BUILDPLATFORM, TARGETARCH, etc.
Implementation
Similar to BUILDX_GIT_LABELS, this would be opt-in via an environment variable and would only work when building from a context with a .git directory.
Example Use Cases
- Conditional build logic based on Git state
- Skip certain build steps when building from a "dirty" Git state
- Build-time decisions based on repository information
- Include debug symbols only for development branches
- Version stamping during build process
This proposal builds upon the existing Git labels feature (#1290) which attaches Git metadata to images via labels.
Problem Statement
Currently, there's no simple way to access Git metadata during the build process or at runtime, as the
BUILDX_GIT_LABELSfeature only adds labels to the final image, they are not accessible during the build process.Proposed Solution
Add a new config variable, (e.g.
BUILDX_GIT_ARGS) that would expose the same Git metadata as build args, making them available during the build process. The build args would be similar to the existing labels:com.docker.image.source.entrypointSOURCEDOCKERFILEorg.opencontainers.image.revisionGITREVISIONorg.opencontainers.image.sourceGITSOURCEThis follows the same naming pattern as other automatic arguments like
BUILDPLATFORM,TARGETARCH, etc.Implementation
Similar to
BUILDX_GIT_LABELS, this would be opt-in via an environment variable and would only work when building from a context with a.gitdirectory.Example Use Cases