blockblaz / blockblaz/lean-quickstart
Add git metadata labels to docker Images
- Dominant language
- Shell
- Stars
- 15
- Forks
- 28
- PR merge metrics
- No merged PRs in 30d
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:**
```dockerfile
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:**
```bash
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:**
```bash
# 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
```
Contributor guide
No contributing guide indexed for this repository
Assessment
This issue has not been assessed yet.