From 46906a5687cfc83046f6c6e03b34b61e11c2be95 Mon Sep 17 00:00:00 2001 From: Jose Bigio Date: Thu, 2 Aug 2018 11:32:44 -0700 Subject: [PATCH] Build docker image with engine binary on multiple arches Signed-off-by: Jose Bigio Upstream-commit: 2dfaf0dd0fa7b7a7aef76d1254b2b48dc04d0211 Component: packaging --- components/packaging/Jenkinsfile | 30 +++++++++++++++++++ components/packaging/Makefile | 15 +++++++++- .../image/{Dockerfile => Dockerfile.engine} | 0 components/packaging/image/Makefile | 17 +++++++---- 4 files changed, 56 insertions(+), 6 deletions(-) rename components/packaging/image/{Dockerfile => Dockerfile.engine} (100%) diff --git a/components/packaging/Jenkinsfile b/components/packaging/Jenkinsfile index 5ef5a94f2a..0e1b4dc760 100644 --- a/components/packaging/Jenkinsfile +++ b/components/packaging/Jenkinsfile @@ -1,5 +1,23 @@ #!groovy + +def genBranch(String arch) { + return [ + "${arch}": { -> + stage("Build engine image on ${arch}") { + wrappedNode(label: "linux&&${arch}", cleanWorkspace: true) { + try { + checkout scm + sh("git clone https://github.com/moby/moby.git engine") + sh('make ENGINE_DIR=$(pwd)/engine image') + } finally { + sh('make ENGINE_DIR=$(pwd)/engine clean-image clean-engine') + } + } + } + }] +} + test_steps = [ 'deb': { -> stage('Ubuntu Xenial Debian Package') { @@ -33,4 +51,16 @@ test_steps = [ }, ] +arches = [ + "x86_64", + "s390x", + "ppc64le", + "aarch64", + "armhf" +] + +arches.each { + test_steps << genBranch(it) +} + parallel(test_steps) diff --git a/components/packaging/Makefile b/components/packaging/Makefile index ff8d0e876a..2a8f0fb9c9 100644 --- a/components/packaging/Makefile +++ b/components/packaging/Makefile @@ -3,14 +3,27 @@ ENGINE_DIR:=$(CURDIR)/../engine CLI_DIR:=$(CURDIR)/../cli VERSION?=0.0.0-dev DOCKER_GITCOMMIT:=abcdefg +STATIC_VERSION=$(shell ../static/gen-static-ver $(ENGINE_DIR) $(VERSION)) GO_VERSION:=1.10.3 +# Taken from: https://www.cmcrossroads.com/article/printing-value-makefile-variable +print-% : ; @echo $($*) + .PHONY: help help: ## show make targets @awk 'BEGIN {FS = ":.*?## "} /^[a-zA-Z_-]+:.*?## / {sub("\\\\n",sprintf("\n%22c"," "), $$2);printf " \033[36m%-20s\033[0m %s\n", $$1, $$2}' $(MAKEFILE_LIST) +.PHONY: clean-engine +clean-engine: + rm -rf $(ENGINE_DIR) + +.PHONY: clean-image +clean-image: + $(MAKE) ENGINE_DIR=$(ENGINE_DIR) -C image clean + + .PHONY: clean -clean: ## remove build artifacts +clean: clean-engine clean-image ## remove build artifacts $(MAKE) -C rpm clean $(MAKE) -C deb clean $(MAKE) -C static clean diff --git a/components/packaging/image/Dockerfile b/components/packaging/image/Dockerfile.engine similarity index 100% rename from components/packaging/image/Dockerfile rename to components/packaging/image/Dockerfile.engine diff --git a/components/packaging/image/Makefile b/components/packaging/image/Makefile index eee5ce1aaf..01b3842243 100644 --- a/components/packaging/image/Makefile +++ b/components/packaging/image/Makefile @@ -4,6 +4,7 @@ CLI_DIR:=$(CURDIR)/../../cli VERSION?=0.0.0-dev STATIC_VERSION=$(shell ../static/gen-static-ver $(ENGINE_DIR) $(VERSION)) DOCKER_HUB_ORG?=docker +ARCH=$(uname -m) ENGINE_IMAGE?=engine-community .PHONY: help @@ -12,18 +13,24 @@ help: ## show make targets .PHONY: clean clean: ## remove build artifacts - docker rmi $(DOCKER_HUB_ORG)/$(ENGINE_IMAGE):$(STATIC_VERSION) + -docker rmi $(DOCKER_HUB_ORG)/$(ENGINE_IMAGE):$(STATIC_VERSION) .PHONY: image image: image-linux + +$(ENGINE_DIR)/Dockerfile.engine: + cp Dockerfile.engine $(ENGINE_DIR) + +# builds across multiple archs because the base images +# utilize manifests .PHONY: image-linux -image-linux: - docker build -t $(DOCKER_HUB_ORG)/$(ENGINE_IMAGE):$(STATIC_VERSION) \ +image-linux: $(ENGINE_DIR)/Dockerfile.engine + docker build -t $(DOCKER_HUB_ORG)/$(ENGINE_IMAGE):$(STATIC_VERSION).$(ARCH) \ --build-arg VERSION=$(STATIC_VERSION) \ --build-arg DOCKER_GITCOMMIT=$(cd $(ENGINE_DIR) && git rev-parse --short=7 HEAD) \ - --file ./Dockerfile $(ENGINE_DIR) + --file $< $(ENGINE_DIR) .PHONY: release release: - docker push $(DOCKER_HUB_ORG)/$(ENGINE_IMAGE):$(STATIC_VERSION) + docker push $(DOCKER_HUB_ORG)/$(ENGINE_IMAGE):$(STATIC_VERSION).$(ARCH)