Skip to content

Add git metadata labels to docker Images #91

@KatyaRyazantseva

Description

@KatyaRyazantseva

Currently it's difficult to identify the exact build context of a client docker image. Tags like devnet1 can be reused for different builds. It makes debugging and version tracking challenging.

Solution

Add Git commit and branch information to image metadata using OCI (Open Container Initiative) standard labels.

Dockerfile changes:

ARG GIT_COMMIT=unknown
ARG GIT_BRANCH=unknown

LABEL org.opencontainers.image.revision=$GIT_COMMIT
LABEL org.opencontainers.image.ref.name=$GIT_BRANCH

Build command example:

docker build \
  --build-arg GIT_COMMIT=$(git rev-parse HEAD) \
  --build-arg GIT_BRANCH=$(git rev-parse --abbrev-ref HEAD) \
  -t blockblaz/zeam:latest .

Usage example:

# Inspect the git commit
docker inspect blockblaz/zeam:devnet1 \
  --format='{{index .Config.Labels "org.opencontainers.image.revision"}}'
# Output: a3f5c8e9d2b1f4e6c8a7d3b5e9f1c4a8b2d6e3f7

# View all labels
docker inspect blockblaz/zeam:devnet1 --format='{{json .Config.Labels}}' | jq

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions