Files
linuxkit/pkg/package.mk
Ian Campbell 55f537631a pkg: add target to print the tag
$ make --no-print-directory -C pkg/init/ show-tag
linuxkit/init:36c56f0664d49c5a6adc1120d1bf5ba6ac30b389

Useful for scripting etc.

Signed-off-by: Ian Campbell <ian.campbell@docker.com>
2017-07-03 10:27:31 +01:00

47 lines
1.2 KiB
Makefile

.PHONY: image tag show-tag
default: push
ORG?=linuxkit
HASH?=$(shell git ls-tree HEAD -- ../$(notdir $(CURDIR)) | awk '{print $$3}')
BASE_DEPS=Dockerfile Makefile
# Add '-dirty' to hash if the repository is not clean. make does not
# concatenate strings without spaces, so we use the documented trick
# of replacing the space with nothing.
DIRTY=$(shell git diff-index --quiet HEAD --; echo $$?)
ifneq ($(DIRTY),0)
HASH+=-dirty
nullstring :=
space := $(nullstring) $(nullstring)
TAG=$(subst $(space),,$(HASH))
else
TAG=$(HASH)
endif
# Get a release tag, if present
RELEASE=$(shell git tag -l --points-at HEAD)
ifdef NETWORK
NET_OPT=
else
NET_OPT=--network=none
endif
show-tag:
@echo $(ORG)/$(IMAGE):$(TAG)
tag: $(BASE_DEPS) $(DEPS)
DOCKER_CONTENT_TRUST=1 docker pull $(ORG)/$(IMAGE):$(TAG) || \
docker build $(NET_OPT) -t $(ORG)/$(IMAGE):$(TAG) .
push: tag
ifneq ($(DIRTY),0)
$(error Your repository is not clean. Will not push package image.)
endif
DOCKER_CONTENT_TRUST=1 docker pull $(ORG)/$(IMAGE):$(TAG) || \
DOCKER_CONTENT_TRUST=1 docker push $(ORG)/$(IMAGE):$(TAG)
ifneq ($(RELEASE),)
docker tag $(ORG)/$(IMAGE):$(TAG) $(ORG)/$(IMAGE):$(RELEASE)
DOCKER_CONTENT_TRUST=1 docker push $(ORG)/$(IMAGE):$(RELEASE)
endif