Skip to content

Proposal: Expose Git information via build args #2784

Description

@mschfh

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels
    No fields configured for Enhancement.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions