Add labels for repo and commit to packages

- use image spec metadata https://github.com/opencontainers/image-spec/blob/master/annotations.md
- omit commit if dirty

Signed-off-by: Justin Cormack <justin.cormack@docker.com>
This commit is contained in:
Justin Cormack 2017-07-11 13:55:24 +01:00
parent 9ee7b23d1e
commit ed38adbc90
2 changed files with 23 additions and 2 deletions

View File

@ -28,6 +28,16 @@ endif
TAG=$(HASH)$(DIRTY) TAG=$(HASH)$(DIRTY)
REPO?=https://github.com/linuxkit/linuxkit
ifneq ($(REPO),)
REPO_LABEL=--label org.opencontainers.image.source=$(REPO)
endif
ifeq ($(DIRTY),)
REPO_COMMIT=$(shell git rev-parse HEAD)
COMMIT_LABEL=--label org.opencontainers.image.revision=$(REPO_COMMIT)
endif
LABELS=$(REPO_LABEL) $(COMMIT_LABEL)
.PHONY: check tag push .PHONY: check tag push
# Targets: # Targets:
# build: builds all kernels # build: builds all kernels
@ -52,6 +62,7 @@ build_$(2)$(3): Dockerfile Makefile $(wildcard patches-$(2)/*) kernel_config-$(2
--build-arg KERNEL_VERSION=$(1) \ --build-arg KERNEL_VERSION=$(1) \
--build-arg KERNEL_SERIES=$(2) \ --build-arg KERNEL_SERIES=$(2) \
--build-arg DEBUG=$(3) \ --build-arg DEBUG=$(3) \
$(LABELS) \
--no-cache -t $(ORG)/$(IMAGE):$(1)$(3)-$(TAG) . --no-cache -t $(ORG)/$(IMAGE):$(1)$(3)-$(TAG) .
push_$(2)$(3): build_$(2)$(3) push_$(2)$(3): build_$(2)$(3)
@ -73,7 +84,7 @@ build_perf_$(2)$(3): build_$(2)$(3)
docker pull $(ORG)/$(IMAGE_PERF):$(1)$(3)-$(TAG) || \ docker pull $(ORG)/$(IMAGE_PERF):$(1)$(3)-$(TAG) || \
docker build -f Dockerfile.perf \ docker build -f Dockerfile.perf \
--build-arg IMAGE=$(ORG)/$(IMAGE):$(1)$(3)-$(TAG) \ --build-arg IMAGE=$(ORG)/$(IMAGE):$(1)$(3)-$(TAG) \
--no-cache --network=none -t $(ORG)/$(IMAGE_PERF):$(1)$(3)-$(TAG) . --no-cache --network=none $(LABEL) -t $(ORG)/$(IMAGE_PERF):$(1)$(3)-$(TAG) .
push_perf_$(2)$(3): build_perf_$(2)$(3) push_perf_$(2)$(3): build_perf_$(2)$(3)
@if [ x"$(DIRTY)" != x ]; then echo "Your repository is not clean. Will not push image"; exit 1; fi @if [ x"$(DIRTY)" != x ]; then echo "Your repository is not clean. Will not push image"; exit 1; fi

View File

@ -13,6 +13,16 @@ endif
TAG:=$(ORG)/$(IMAGE):$(HASH)$(DIRTY) TAG:=$(ORG)/$(IMAGE):$(HASH)$(DIRTY)
REPO?=https://github.com/linuxkit/linuxkit
ifneq ($(REPO),)
REPO_LABEL=--label org.opencontainers.image.source=$(REPO)
endif
ifeq ($(DIRTY),)
REPO_COMMIT=$(shell git rev-parse HEAD)
COMMIT_LABEL=--label org.opencontainers.image.revision=$(REPO_COMMIT)
endif
LABELS=$(REPO_LABEL) $(COMMIT_LABEL)
BASE_DEPS=Dockerfile Makefile BASE_DEPS=Dockerfile Makefile
# Get a release tag, if present # Get a release tag, if present
@ -34,7 +44,7 @@ show-tag:
@echo $(TAG) @echo $(TAG)
tag: $(BASE_DEPS) $(DEPS) tag: $(BASE_DEPS) $(DEPS)
docker pull $(TAG) || docker build $(NET_OPT) -t $(TAG) . docker pull $(TAG) || docker build $(LABELS) $(NET_OPT) -t $(TAG) .
push: tag push: tag
ifneq ($(DIRTY),) ifneq ($(DIRTY),)