Files
linuxkit/pkg/package.mk
Ian Campbell 1ea64d33f0 pkg: use Jessie-era compatible git command for calculating $(HASH)
The current rune for $(HASH) returns nothing with the Jessie version of git
(2.1.4). Using `--full-tree` works corectly but requires an absolute path (else
it produces e.g. "fatal: ../init: '../init' is outside repository").

Both `ls-tree` and `diff-index` are happy with a full absolute path, which
simplifies things since we can use `$(CURDIR)` directly.

Tested with a dirty `pkg/init` on both Jessie (git 2.1.4) and Stretch (git
2.11.0) with the following command, which produces identical output in both
cases:

$ for pkg in init containerd ; do make -C pkg/$pkg --no-print-directory show-tag; ( cd pkg/$pkg && make show-tag ); done
linuxkit/init:36c56f0664d49c5a6adc1120d1bf5ba6ac30b389-dirty
linuxkit/init:36c56f0664d49c5a6adc1120d1bf5ba6ac30b389-dirty
linuxkit/containerd:1e3e8f207421de8deac8cedc26a138d6b1661a0d
linuxkit/containerd:1e3e8f207421de8deac8cedc26a138d6b1661a0d

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

37 lines
876 B
Makefile

.PHONY: image tag show-tag
default: push
ORG?=linuxkit
HASH?=$(shell git ls-tree --full-tree HEAD -- $(CURDIR) | awk '{print $$3}')
BASE_DEPS=Dockerfile Makefile
DIRTY=$(shell git diff-index --quiet HEAD -- $(CURDIR) || echo "-dirty")
TAG=$(ORG)/$(IMAGE):$(HASH)$(DIRTY)
# 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 $(TAG)
tag: $(BASE_DEPS) $(DEPS)
DOCKER_CONTENT_TRUST=1 docker pull $(TAG) || \
docker build $(NET_OPT) -t $(TAG) .
push: tag
ifneq ($(DIRTY),)
$(error Your repository is not clean. Will not push package image.)
endif
DOCKER_CONTENT_TRUST=1 docker pull $(TAG) || \
DOCKER_CONTENT_TRUST=1 docker push $(TAG)
ifneq ($(RELEASE),)
docker tag $(TAG) $(ORG)/$(IMAGE):$(RELEASE)
DOCKER_CONTENT_TRUST=1 docker push $(ORG)/$(IMAGE):$(RELEASE)
endif