build: Add the ability to only build/push/sign for specific architectures

A package makefile can specify a list of architectures ('ARCHES')
it supports. If build on a unsupported architecture, a message is
printed and make exits without an error.

Signed-off-by: Rolf Neugebauer <rolf.neugebauer@docker.com>
This commit is contained in:
Rolf Neugebauer 2017-08-03 14:18:06 +01:00
parent b271a3b91f
commit 0ebb53c491

View File

@ -17,6 +17,11 @@ DIRTY:=$(shell git update-index -q --refresh && git diff-index --quiet HEAD -- $
endif endif
endif endif
# Makefiles can specify specific architectures they compile for. Default: all
ifeq ($(ARCHES),)
ARCHES:=x86_64 aarch64
endif
ARCH := $(shell uname -m) ARCH := $(shell uname -m)
ifeq ($(ARCH), x86_64) ifeq ($(ARCH), x86_64)
SUFFIX=-amd64 SUFFIX=-amd64
@ -25,6 +30,12 @@ ifeq ($(ARCH), aarch64)
SUFFIX=-arm64 SUFFIX=-arm64
endif endif
ifneq ($(filter $(ARCH),$(ARCHES)),)
REAL:=-y
else
REAL:=-n
endif
TAG:=$(ORG)/$(IMAGE):$(HASH)$(DIRTY) TAG:=$(ORG)/$(IMAGE):$(HASH)$(DIRTY)
REPO?=https://github.com/linuxkit/linuxkit REPO?=https://github.com/linuxkit/linuxkit
@ -57,14 +68,19 @@ export DOCKER_CONTENT_TRUST=1
endif endif
endif endif
tag: tag$(REAL)
forcetag: forcetag$(REAL)
push: push$(REAL)
forcepush: forcepush$(REAL)
show-tag: show-tag:
@echo $(TAG) @echo $(TAG)
tag: $(BASE_DEPS) $(DEPS) tag-y: $(BASE_DEPS) $(DEPS)
docker pull $(TAG)$(SUFFIX) || \ docker pull $(TAG)$(SUFFIX) || \
docker build $(LABELS) $(NET_OPT) -t $(TAG)$(SUFFIX) $(SOURCE) docker build $(LABELS) $(NET_OPT) -t $(TAG)$(SUFFIX) $(SOURCE)
forcetag: $(BASE_DEPS) $(DEPS) forcetag-y: $(BASE_DEPS) $(DEPS)
docker build $(LABELS) $(NET_OPT) -t $(TAG)$(SUFFIX) $(SOURCE) docker build $(LABELS) $(NET_OPT) -t $(TAG)$(SUFFIX) $(SOURCE)
check-dirty: check-dirty:
@ -72,7 +88,7 @@ ifneq ($(DIRTY),)
$(error Your repository is not clean. Will not push package image) $(error Your repository is not clean. Will not push package image)
endif endif
push: tag check-dirty push-y: tag-y check-dirty
docker pull $(TAG)$(SUFFIX) || \ docker pull $(TAG)$(SUFFIX) || \
(docker push $(TAG)$(SUFFIX) && \ (docker push $(TAG)$(SUFFIX) && \
$(PUSH_MANIFEST) $(TAG) $(DOCKER_CONTENT_TRUST)) $(PUSH_MANIFEST) $(TAG) $(DOCKER_CONTENT_TRUST))
@ -82,7 +98,7 @@ ifneq ($(RELEASE),)
$(PUSH_MANIFEST) $(ORG)/$(IMAGE):$(RELEASE) $(DOCKER_CONTENT_TRUST) $(PUSH_MANIFEST) $(ORG)/$(IMAGE):$(RELEASE) $(DOCKER_CONTENT_TRUST)
endif endif
forcepush: forcetag check-dirty forcepush-y: forcetag-y check-dirty
docker push $(TAG)$(SUFFIX) docker push $(TAG)$(SUFFIX)
$(PUSH_MANIFEST) $(TAG) $(DOCKER_CONTENT_TRUST) $(PUSH_MANIFEST) $(TAG) $(DOCKER_CONTENT_TRUST)
ifneq ($(RELEASE),) ifneq ($(RELEASE),)
@ -90,3 +106,13 @@ ifneq ($(RELEASE),)
docker push $(ORG)/$(IMAGE):$(RELEASE)$(SUFFIX) docker push $(ORG)/$(IMAGE):$(RELEASE)$(SUFFIX)
$(PUSH_MANIFEST) $(ORG)/$(IMAGE):$(RELEASE) $(DOCKER_CONTENT_TRUST) $(PUSH_MANIFEST) $(ORG)/$(IMAGE):$(RELEASE) $(DOCKER_CONTENT_TRUST)
endif endif
# If not supported for an arch, print a message
tag-n:
$(info This package does not work on $(ARCH). Ignored)
forcetag-n:
$(info This package does not work on $(ARCH). Ignored)
push-n:
$(info This package does not work on $(ARCH). Ignored)
forcepush-n:
$(info This package does not work on $(ARCH). Ignored)