-
Notifications
You must be signed in to change notification settings - Fork 18
Open
Description
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_BRANCHBuild 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}}' | jqMetadata
Metadata
Assignees
Labels
No labels