Browse files

Inject Git source commit metadata into the image

These values are useful for looking up the state of code when examining
images at a particular tag. When setting LABEL values, we can easily
pull them out of an image through inspection:

    docker inspect --format '{{.Config.Labels}}' tiddlywiki

The default value of `unknown` is meant to catch the accidental case
where an image was pushed manually. The naming of the `SOURCE_COMMIT`
variable itself comes from the convention used by Docker Cloud [1] (but
might still be undocumented). Labels seemed more appropriate than using
ENV variables.

[1] docker/hub-feedback#600 (comment)
  • Loading branch information...
elasticdog committed Jul 23, 2018
1 parent 9dcdf82 commit 993c7e9e8d5207d110270458f0f18839656ca126
Showing with 9 additions and 2 deletions.
  1. +5 −1 5/Dockerfile
  2. +4 −1 Makefile
@@ -1,8 +1,12 @@
FROM node:alpine
LABEL maintainer="Aaron Bull Schaefer <>"
LABEL maintainer="Aaron Bull Schaefer <>"
LABEL source=""
LABEL source-commit="${SOURCE_COMMIT:-unknown}"
RUN apk add --no-cache tini
RUN npm install -g tiddlywiki@${TIDDLYWIKI_VERSION}
@@ -4,8 +4,9 @@ DOCKER_HUB_REPOSITORY ?= elasticdog
all: build
.PHONY: build
build: SOURCE_COMMIT := $(shell git rev-parse HEAD)
docker build --tag tiddlywiki .
docker build --build-arg "SOURCE_COMMIT=${SOURCE_COMMIT}" --tag tiddlywiki .
.PHONY: test
@@ -16,7 +17,9 @@ tag: PATCH_VERSION := $(shell docker run -it --rm tiddlywiki --version | sed 's/
tag: MINOR_VERSION := $(shell echo "${PATCH_VERSION}" | awk -F. '{ print $$1"."$$2 }')
tag: MAJOR_VERSION := $(shell echo "${PATCH_VERSION}" | awk -F. '{ print $$1 }')
# unique tag
if [ "$$CI" = true ]; then docker tag tiddlywiki "${DOCKER_HUB_REPOSITORY}/tiddlywiki:$$(date +%Y%m%d).$${CIRCLE_BUILD_NUM}"; fi
# stable tags
docker tag tiddlywiki "${DOCKER_HUB_REPOSITORY}/tiddlywiki:latest"
docker tag tiddlywiki "${DOCKER_HUB_REPOSITORY}/tiddlywiki:${PATCH_VERSION}"
docker tag tiddlywiki "${DOCKER_HUB_REPOSITORY}/tiddlywiki:${MINOR_VERSION}"

0 comments on commit 993c7e9

Please sign in to comment.