From eb10cbb39cb8d292487d629dbe12b5e1d7902085 Mon Sep 17 00:00:00 2001 From: Tibor Vass Date: Tue, 6 Apr 2021 21:35:57 +0000 Subject: [PATCH 1/6] mac: build arm64 binaries Signed-off-by: Tibor Vass --- static/Makefile | 21 +++++++++++++++------ 1 file changed, 15 insertions(+), 6 deletions(-) diff --git a/static/Makefile b/static/Makefile index 6d755bc8a0..04377ea1e7 100644 --- a/static/Makefile +++ b/static/Makefile @@ -44,14 +44,23 @@ hash_files: @echo "Hashing directory $(DIR_TO_HASH)" $(HASH_CMD) "$(DIR_TO_HASH)" +.PHONY: buildx +buildx: + docker buildx inspect | grep -q 'Driver: docker-container' || docker buildx create --use + .PHONY: cross-mac -cross-mac: cross-all-cli cross-mac-plugins ## create tgz with darwin x86_64 client only - mkdir -p build/mac/docker - cp $(CLI_DIR)/build/docker-darwin-amd64 build/mac/docker/docker - tar -C build/mac -c -z -f build/mac/docker-$(GEN_STATIC_VER).tgz docker +cross-mac: buildx cross-mac-plugins + cd $(CLI_DIR) && VERSION=$(GEN_STATIC_VER) docker buildx bake --set binary.platform=darwin/amd64,darwin/arm64 binary + dest=$$PWD/build/mac; cd $(CLI_DIR)/build && for platform in *; do \ + arch=$$(echo $$platform | cut -d_ -f2); \ + mkdir -p $$dest/$$arch/docker; \ + cp $$platform/docker-darwin-* $$dest/$$arch/docker/docker && \ + tar -C $$dest/$$arch -c -z -f $$dest/$$arch/docker-$(GEN_STATIC_VER).tgz docker; \ + done .PHONY: cross-win -cross-win: cross-all-cli cross-win-engine cross-win-plugins ## create zip file with windows x86_64 client and server +cross-win: cross-win-engine cross-win-plugins + cd $(CLI_DIR) && VERSION=$(GEN_STATIC_VER) docker buildx bake --set binary.platform=windows/amd64 binary mkdir -p build/win/docker cp $(CLI_DIR)/build/docker-windows-amd64.exe build/win/docker/docker.exe cp $(ENGINE_DIR)/bundles/cross/windows/amd64/dockerd-$(GEN_STATIC_VER).exe build/win/docker/dockerd.exe @@ -101,4 +110,4 @@ cross-win-plugins: mkdir -p build/$(CLI_BUILD_DIR)/docker/cli-plugins docker run $(BUILD_PLUGIN_RUN_VARS) $(DOCKER_CLI_GOLANG_IMG) /build $(CHOWN) -R $(shell id -u):$(shell id -g) build - find build/$(CLI_BUILD_DIR)/docker -type f -not -name "*.exe" -exec mv {} {}.exe \; + find build/$(CLI_BUILD_DIR)/$*/docker -type f -not -name "*.exe" -exec mv {} {}.exe \; From 7eb0491715aa3bdc6328472be547f8054af1c6b5 Mon Sep 17 00:00:00 2001 From: Tibor Vass Date: Tue, 6 Apr 2021 21:45:49 +0000 Subject: [PATCH 2/6] plugins: support multiple architectures Signed-off-by: Tibor Vass --- static/Makefile | 33 +++++++++++++++++++-------------- 1 file changed, 19 insertions(+), 14 deletions(-) diff --git a/static/Makefile b/static/Makefile index 04377ea1e7..91a7ef1382 100644 --- a/static/Makefile +++ b/static/Makefile @@ -90,24 +90,29 @@ cross-win-engine: $(MAKE) -C $(ENGINE_DIR) VERSION=$(GEN_STATIC_VER) DOCKER_CROSSPLATFORMS=windows/amd64 cross BUILD_PLUGIN_RUN_VARS = --rm \ - -e GOOS=$(SPOOF_GOOS) \ - -v "$(CURDIR)/build/$(CLI_BUILD_DIR)/docker/cli-plugins":/out \ + -e GOOS \ + -e GOARCH \ + -v "$(CURDIR)/build/$(CLI_BUILD_DIR)/$*/docker/cli-plugins":/out \ -v "$(CURDIR)/../plugins":/plugins:ro \ -v "$(CURDIR)/scripts/build-cli-plugins":/build:ro .PHONY: cross-mac-plugins -cross-mac-plugins: SPOOF_GOOS := darwin -cross-mac-plugins: CLI_BUILD_DIR := mac -cross-mac-plugins: - mkdir -p build/$(CLI_BUILD_DIR)/docker - docker run $(BUILD_PLUGIN_RUN_VARS) $(DOCKER_CLI_GOLANG_IMG) /build - $(CHOWN) -R $(shell id -u):$(shell id -g) build +cross-mac-plugins: cross-mac-plugins-amd64 cross-mac-plugins-arm64 + +.PHONY: cross-mac-plugins-% +cross-mac-plugins-%: CLI_BUILD_DIR := mac +cross-mac-plugins-%: + mkdir -p build/$(CLI_BUILD_DIR)/$*/docker + GOOS=darwin GOARCH=$* docker run $(BUILD_PLUGIN_RUN_VARS) $(DOCKER_CLI_GOLANG_IMG) /build + $(CHOWN) -R $(shell id -u):$(shell id -g) build/$(CLI_BUILD_DIR)/$* .PHONY: cross-win-plugins -cross-win-plugins: SPOOF_GOOS := windows -cross-win-plugins: CLI_BUILD_DIR := win -cross-win-plugins: - mkdir -p build/$(CLI_BUILD_DIR)/docker/cli-plugins - docker run $(BUILD_PLUGIN_RUN_VARS) $(DOCKER_CLI_GOLANG_IMG) /build - $(CHOWN) -R $(shell id -u):$(shell id -g) build +cross-win-plugins: cross-win-plugins-amd64 + +.PHONY: cross-win-plugins-% +cross-win-plugins-%: CLI_BUILD_DIR := win +cross-win-plugins-%: + mkdir -p build/$(CLI_BUILD_DIR)/$*/docker/cli-plugins + GOOS=windows GOARCH=$* docker run $(BUILD_PLUGIN_RUN_VARS) $(DOCKER_CLI_GOLANG_IMG) /build + $(CHOWN) -R $(shell id -u):$(shell id -g) build/$(CLI_BUILD_DIR)/$* find build/$(CLI_BUILD_DIR)/$*/docker -type f -not -name "*.exe" -exec mv {} {}.exe \; From 60e28c914dbe5c0b7fe9fe73fefb24ecbd078085 Mon Sep 17 00:00:00 2001 From: Tibor Vass Date: Wed, 7 Apr 2021 03:27:37 +0000 Subject: [PATCH 3/6] plugins: update golang to 1.16.3 to build buildx on darwin/arm64 Signed-off-by: Tibor Vass --- plugins/app.installer | 2 +- static/Makefile | 7 +++---- 2 files changed, 4 insertions(+), 5 deletions(-) diff --git a/plugins/app.installer b/plugins/app.installer index b513fed948..fc4c4549e4 100644 --- a/plugins/app.installer +++ b/plugins/app.installer @@ -18,7 +18,7 @@ build() { git fetch --all git checkout -q "${COMMIT}" # There's no real versions yet, but this'll just leave it blank - make dynamic + GO111MODULE=off make dynamic ) } diff --git a/static/Makefile b/static/Makefile index 91a7ef1382..1d95393504 100644 --- a/static/Makefile +++ b/static/Makefile @@ -5,8 +5,7 @@ ENGINE_DIR=$(realpath $(CURDIR)/../src/github.com/docker/docker) GEN_STATIC_VER=$(shell ./gen-static-ver $(CLI_DIR) $(VERSION)) HASH_CMD=docker run -v $(CURDIR):/sum -w /sum debian:jessie bash hash_files DIR_TO_HASH:=build/linux -GO_VERSION=$(shell grep "ARG GO_VERSION" $(CLI_DIR)/dockerfiles/Dockerfile.dev | awk -F'=' '{print $$2}') -DOCKER_CLI_GOLANG_IMG=golang:$(GO_VERSION) +DOCKER_CLI_PLUGIN_GOLANG_IMG=golang:1.16.3 .PHONY: help help: ## show make targets @@ -103,7 +102,7 @@ cross-mac-plugins: cross-mac-plugins-amd64 cross-mac-plugins-arm64 cross-mac-plugins-%: CLI_BUILD_DIR := mac cross-mac-plugins-%: mkdir -p build/$(CLI_BUILD_DIR)/$*/docker - GOOS=darwin GOARCH=$* docker run $(BUILD_PLUGIN_RUN_VARS) $(DOCKER_CLI_GOLANG_IMG) /build + GOOS=darwin GOARCH=$* docker run $(BUILD_PLUGIN_RUN_VARS) $(DOCKER_CLI_PLUGIN_GOLANG_IMG) /build $(CHOWN) -R $(shell id -u):$(shell id -g) build/$(CLI_BUILD_DIR)/$* .PHONY: cross-win-plugins @@ -113,6 +112,6 @@ cross-win-plugins: cross-win-plugins-amd64 cross-win-plugins-%: CLI_BUILD_DIR := win cross-win-plugins-%: mkdir -p build/$(CLI_BUILD_DIR)/$*/docker/cli-plugins - GOOS=windows GOARCH=$* docker run $(BUILD_PLUGIN_RUN_VARS) $(DOCKER_CLI_GOLANG_IMG) /build + GOOS=windows GOARCH=$* docker run $(BUILD_PLUGIN_RUN_VARS) $(DOCKER_CLI_PLUGIN_GOLANG_IMG) /build $(CHOWN) -R $(shell id -u):$(shell id -g) build/$(CLI_BUILD_DIR)/$* find build/$(CLI_BUILD_DIR)/$*/docker -type f -not -name "*.exe" -exec mv {} {}.exe \; From c04ab6da6aba04710fa4650b341296b6ff486c15 Mon Sep 17 00:00:00 2001 From: Tibor Vass Date: Tue, 6 Apr 2021 04:48:43 +0000 Subject: [PATCH 4/6] arm: do not rely on host arch, specify --platform and CGO_ENABLED Since we are building arm on arm64 machines we have to specify the desired platform and not rely on the host's architecture. Also when building arm on arm64 machines, there can be issues with cgo. So this patch makes sure CGO_ENABLED env var gets passed on as a build arg. Signed-off-by: Tibor Vass --- Makefile | 2 +- static/Makefile | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/Makefile b/Makefile index 209fe66dde..8eb8f0cc9a 100644 --- a/Makefile +++ b/Makefile @@ -75,5 +75,5 @@ deb: checkout ## build deb packages static: DOCKER_BUILD_PKGS:=static-linux cross-mac cross-win cross-arm static: checkout ## build static-compiled packages for p in $(DOCKER_BUILD_PKGS); do \ - $(MAKE) -C $@ VERSION=$(VERSION) GO_VERSION=$(GO_VERSION) $${p}; \ + $(MAKE) -C $@ VERSION=$(VERSION) GO_VERSION=$(GO_VERSION) TARGETPLATFORM=$(TARGETPLATFORM) $${p}; \ done diff --git a/static/Makefile b/static/Makefile index 1d95393504..70e158097c 100644 --- a/static/Makefile +++ b/static/Makefile @@ -74,7 +74,7 @@ cross-arm: cross-all-cli ## create tgz with linux armhf client only .PHONY: static-cli static-cli: - $(MAKE) -C $(CLI_DIR) -f docker.Makefile VERSION=$(GEN_STATIC_VER) build + cd $(CLI_DIR) && VERSION=$(GEN_STATIC_VER) docker buildx bake --set binary.platform=$(TARGETPLATFORM) --set binary.args.CGO_ENABLED=$(CGO_ENABLED) binary .PHONY: static-engine static-engine: From 06c788d4782acd4702ac1fbf20cf160e04f63ec2 Mon Sep 17 00:00:00 2001 From: Tibor Vass Date: Wed, 7 Apr 2021 21:25:29 +0000 Subject: [PATCH 5/6] win: add arch in path for consistency with mac paths Signed-off-by: Tibor Vass --- static/Makefile | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/static/Makefile b/static/Makefile index 70e158097c..97e2833132 100644 --- a/static/Makefile +++ b/static/Makefile @@ -60,10 +60,10 @@ cross-mac: buildx cross-mac-plugins .PHONY: cross-win cross-win: cross-win-engine cross-win-plugins cd $(CLI_DIR) && VERSION=$(GEN_STATIC_VER) docker buildx bake --set binary.platform=windows/amd64 binary - mkdir -p build/win/docker - cp $(CLI_DIR)/build/docker-windows-amd64.exe build/win/docker/docker.exe - cp $(ENGINE_DIR)/bundles/cross/windows/amd64/dockerd-$(GEN_STATIC_VER).exe build/win/docker/dockerd.exe - docker run --rm -v $(CURDIR)/build/win:/v -w /v alpine sh -c 'apk update&&apk add zip&&zip -r docker-$(GEN_STATIC_VER).zip docker' + mkdir -p build/win/amd64/docker + cp $(CLI_DIR)/build/docker-windows-amd64.exe build/win/amd64/docker/docker.exe + cp $(ENGINE_DIR)/bundles/cross/windows/amd64/dockerd-$(GEN_STATIC_VER).exe build/win/amd64/docker/dockerd.exe + docker run --rm -v $(CURDIR)/build/win/amd64:/v -w /v alpine sh -c 'apk update&&apk add zip&&zip -r docker-$(GEN_STATIC_VER).zip docker' $(CHOWN) -R $(shell id -u):$(shell id -g) build .PHONY: cross-arm From 5d5210745d3a566b4051eb6c92d675b52cc6be65 Mon Sep 17 00:00:00 2001 From: Tibor Vass Date: Tue, 6 Apr 2021 17:48:29 +0000 Subject: [PATCH 6/6] deb/rpm: do not call cli Makefile that is changing In https://github.com/docker/cli/pull/2993, Makefile target dynbinary changed from a host script not depending on docker to a dockerized script. Instead call the underlying script directly for deb/rpm. I still think we should build deb/rpms using docker. Signed-off-by: Tibor Vass --- deb/common/rules | 3 +-- rpm/SPECS/docker-ce-cli.spec | 2 +- 2 files changed, 2 insertions(+), 3 deletions(-) diff --git a/deb/common/rules b/deb/common/rules index 2517fdbe59..331da261ec 100755 --- a/deb/common/rules +++ b/deb/common/rules @@ -10,8 +10,7 @@ override_dh_auto_build: cd engine && TMP_GOPATH="/go" hack/dockerfile/install/install.sh proxy dynamic cd engine && TMP_GOPATH="/go" hack/dockerfile/install/install.sh rootlesskit dynamic # Build the CLI - cd /go/src/github.com/docker/cli && \ - LDFLAGS='' DISABLE_WARN_OUTSIDE_CONTAINER=1 make VERSION=$(VERSION) GITCOMMIT=$(CLI_GITCOMMIT) dynbinary manpages + cd /go/src/github.com/docker/cli && VERSION=$(VERSION) GITCOMMIT=$(CLI_GITCOMMIT) LDFLAGS='' GO_LINKMODE=dynamic ./scripts/build/binary && DISABLE_WARN_OUTSIDE_CONTAINER=1 LDFLAGS='' make manpages # Build the scan-plugin # TODO change once we support scan-plugin on other architectures diff --git a/rpm/SPECS/docker-ce-cli.spec b/rpm/SPECS/docker-ce-cli.spec index 3253f6b90d..8dd6fea84e 100644 --- a/rpm/SPECS/docker-ce-cli.spec +++ b/rpm/SPECS/docker-ce-cli.spec @@ -51,7 +51,7 @@ mkdir -p /go/src/github.com/docker rm -f /go/src/github.com/docker/cli ln -s ${RPM_BUILD_DIR}/src/cli /go/src/github.com/docker/cli pushd /go/src/github.com/docker/cli -DISABLE_WARN_OUTSIDE_CONTAINER=1 make VERSION=%{_origversion} GITCOMMIT=%{_gitcommit_cli} dynbinary manpages # cli +VERSION=%{_origversion} GITCOMMIT=%{_gitcommit_cli} GO_LINKMODE=dynamic ./scripts/build/binary && DISABLE_WARN_OUTSIDE_CONTAINER=1 make manpages # cli popd # Build all associated plugins