From f2bff6b04a9f69e322a61ddc7665028caee57185 Mon Sep 17 00:00:00 2001 From: CrazyMax Date: Wed, 25 Jan 2023 13:09:10 +0100 Subject: [PATCH 1/7] refactor static packages Signed-off-by: CrazyMax --- Jenkinsfile | 101 +++++++--------- Makefile | 7 +- static/Makefile | 116 +++++------------- static/README.md | 55 +++++++++ static/build-static | 278 ++++++++++++++++++++++++++++++++++++++++++++ 5 files changed, 401 insertions(+), 156 deletions(-) create mode 100644 static/README.md create mode 100755 static/build-static diff --git a/Jenkinsfile b/Jenkinsfile index a59db1d460..1bd93cf476 100644 --- a/Jenkinsfile +++ b/Jenkinsfile @@ -1,7 +1,5 @@ #!groovy -def branch = env.CHANGE_TARGET ?: env.BRANCH_NAME - def pkgs = [ [target: "centos-7", image: "centos:7", arches: ["amd64", "aarch64"]], // (EOL: June 30, 2024) [target: "centos-8", image: "quay.io/centos/centos:stream8", arches: ["amd64", "aarch64"]], @@ -20,15 +18,16 @@ def pkgs = [ [target: "ubuntu-kinetic", image: "ubuntu:kinetic", arches: ["amd64", "aarch64", "armhf"]], // Ubuntu 22.10 (EOL: July, 2023) ] -def genBuildStep(LinkedHashMap pkg, String arch) { +def statics = [ + [os: "linux", arches: ["amd64", "armv6", "armv7", "aarch64"]], + [os: "darwin", arches: ["amd64", "aarch64"]], + [os: "windows", arches: ["amd64"]], +] + +def genPkgStep(LinkedHashMap pkg, String arch) { def nodeLabel = "linux&&${arch}" - def platform = "" def branch = env.CHANGE_TARGET ?: env.BRANCH_NAME - if (arch == 'armhf') { - // Running armhf builds on EC2 requires --platform parameter - // Otherwise it accidentally pulls armel images which then breaks the verify step - platform = "--platform=linux/${arch}" nodeLabel = "${nodeLabel}&&ubuntu" } else { nodeLabel = "${nodeLabel}&&ubuntu-2004" @@ -43,6 +42,7 @@ def genBuildStep(LinkedHashMap pkg, String arch) { stage("info") { sh 'docker version' sh 'docker info' + sh 'env|sort' } stage("build") { checkout scm @@ -56,52 +56,29 @@ def genBuildStep(LinkedHashMap pkg, String arch) { } } -def build_package_steps = [ - 'static-linux': { -> - wrappedNode(label: 'ubuntu-2004 && x86_64', cleanWorkspace: true) { - stage("static-linux") { - // This is just a "dummy" stage to make the distro/arch visible - // in Jenkins' BlueOcean view, which truncates names.... - sh 'echo starting...' - } - stage("info") { - sh 'docker version' - sh 'docker info' - } - stage("build") { - try { - checkout scm - sh "make REF=$branch DOCKER_BUILD_PKGS='static-linux' static" - } finally { - sh "make clean" - } - } - } - }, - 'cross-mac': { -> - wrappedNode(label: 'ubuntu-2004 && x86_64', cleanWorkspace: true) { - stage("cross-mac") { - // This is just a "dummy" stage to make the distro/arch visible - // in Jenkins' BlueOcean view, which truncates names.... - sh 'echo starting...' - } - stage("info") { - sh 'docker version' - sh 'docker info' - } - stage("build") { - try { - checkout scm - sh "make REF=$branch DOCKER_BUILD_PKGS='cross-mac' static" - } finally { - sh "make clean" - } - } - } - }, - 'cross-win': { -> - wrappedNode(label: 'ubuntu-2004 && x86_64', cleanWorkspace: true) { - stage("cross-win") { +def genPkgSteps(opts) { + return opts.arches.collectEntries { + ["${opts.image}-${it}": genPkgStep(opts, it)] + } +} + +def genStaticStep(LinkedHashMap pkg, String arch) { + def config = [ + amd64: [label: "x86_64", targetarch: "amd64"], + aarch64: [label: "aarch64", targetarch: "arm64"], + armv6: [label: "aarch64", targetarch: "arm/v6"], + armv7: [label: "aarch64", targetarch: "arm/v7"], + ppc64le: [label: "ppc64le", targetarch: "ppc64le"], + s390x : [label: "s390x", targetarch: "s390x"], + ][arch] + def nodeLabel = "linux&&${config.label}" + if (config.label == 'x86_64') { + nodeLabel = "${nodeLabel}&&ubuntu" + } + def branch = env.CHANGE_TARGET ?: env.BRANCH_NAME + return { -> + wrappedNode(label: nodeLabel, cleanWorkspace: true) { + stage("static-${pkg.os}-${arch}") { // This is just a "dummy" stage to make the distro/arch visible // in Jenkins' BlueOcean view, which truncates names.... sh 'echo starting...' @@ -109,25 +86,27 @@ def build_package_steps = [ stage("info") { sh 'docker version' sh 'docker info' + sh 'env|sort' } stage("build") { try { checkout scm - sh "make REF=$branch DOCKER_BUILD_PKGS='cross-win' static" + sh "make REF=$branch TARGETPLATFORM=${pkg.os}/${config.targetarch} static" } finally { sh "make clean" } } } - }, -] + } +} -def genPackageSteps(opts) { +def genStaticSteps(opts) { return opts.arches.collectEntries { - ["${opts.image}-${it}": genBuildStep(opts, it)] + ["static-${opts.os}-${it}": genStaticStep(opts, it)] } } -build_package_steps << pkgs.collectEntries { genPackageSteps(it) } +def parallelStages = pkgs.collectEntries { genPkgSteps(it) } +parallelStages << statics.collectEntries { genStaticSteps(it) } -parallel(build_package_steps) +parallel(parallelStages) diff --git a/Makefile b/Makefile index 80cdae1386..9457304140 100644 --- a/Makefile +++ b/Makefile @@ -92,11 +92,8 @@ debian-% raspbian-% ubuntu-%: checkout ## build deb packages for the specified d $(MAKE) -C deb VERSION=$(VERSION) GO_VERSION=$(GO_VERSION) $@ .PHONY: static -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) TARGETPLATFORM=$(TARGETPLATFORM) CONTAINERD_VERSION=$(CONTAINERD_VERSION) RUNC_VERSION=$(RUNC_VERSION) $${p}; \ - done +static: checkout ## build static package + $(MAKE) -C static build .PHONY: verify verify: ## verify installation of packages diff --git a/static/Makefile b/static/Makefile index e1e3efa016..d8ca222314 100644 --- a/static/Makefile +++ b/static/Makefile @@ -5,26 +5,30 @@ ENGINE_DIR=$(realpath $(CURDIR)/../src/github.com/docker/docker) BUILDX_DIR=$(realpath $(CURDIR)/../src/github.com/docker/buildx) ENGINE_GITCOMMIT?=$(shell cd $(realpath $(CURDIR)/../src/github.com/docker/docker) && git rev-parse --short HEAD) - 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 -DOCKER_CLI_GOLANG_IMG=golang:$(GO_VERSION) -DOCKER_BUILD_OPTS= +# Select the default version of containerd and runc based on the docker engine +# source we need this variable here for naming the produced .tgz file. +CONTAINERD_VERSION?=$(shell grep "ARG CONTAINERD_VERSION" "$(ENGINE_DIR)/Dockerfile" | awk -F'=' '{print $$2}') +RUNC_VERSION?=$(shell grep "ARG RUNC_VERSION" "$(ENGINE_DIR)/Dockerfile" | awk -F'=' '{print $$2}') -ifneq ($(strip $(CONTAINERD_VERSION)),) -# Set custom build-args to override the containerd version to build for static -# packages. -DOCKER_BUILD_OPTS +=--build-arg=CONTAINERD_VERSION=$(CONTAINERD_VERSION) -endif +export CLI_DIR +export ENGINE_DIR +export BUILDX_DIR +export GEN_STATIC_VER +export CONTAINERD_VERSION +export RUNC_VERSION -ifneq ($(strip $(RUNC_VERSION)),) -# Set custom build-args to override the runc version to build for static packages. -DOCKER_BUILD_OPTS +=--build-arg=RUNC_VERSION=$(RUNC_VERSION) -endif +export REF +export DOCKER_CLI_REF +export DOCKER_ENGINE_REF +export DOCKER_SCAN_REF +export DOCKER_COMPOSE_REF +export DOCKER_BUILDX_REF -ENGINE_BUILD_OPTS=--build-arg VERSION=$(GEN_STATIC_VER) --build-arg DOCKER_GITCOMMIT=$(ENGINE_GITCOMMIT) --build-arg DEFAULT_PRODUCT_LICENSE --build-arg PACKAGER_NAME --build-arg PLATFORM $(DOCKER_BUILD_OPTS) +export GO_VERSION .PHONY: help help: ## show make targets @@ -32,85 +36,17 @@ help: ## show make targets .PHONY: clean clean: ## remove build artifacts - [ ! -d build ] || $(CHOWN) -R $(shell id -u):$(shell id -g) build - $(RM) -r build - -docker builder prune -f --filter until=24h - -.PHONY: static -static: static-linux cross-mac cross-win cross-arm ## create all static packages - -.PHONY: static-linux -static-linux: static-cli static-engine static-buildx-plugin ## create tgz - mkdir -p build/linux/docker - cp $(CLI_DIR)/build/docker build/linux/docker/ - for f in dockerd containerd ctr containerd-shim containerd-shim-runc-v2 docker-init docker-proxy runc; do \ - cp -L $(ENGINE_DIR)/bundles/binary/$$f build/linux/docker/$$f; \ - done - tar -C build/linux -c -z -f build/linux/docker-$(GEN_STATIC_VER).tgz docker + @[ ! -d build ] || $(CHOWN) -R $(shell id -u):$(shell id -g) build + @$(RM) -r build - # extra binaries for running rootless - mkdir -p build/linux/docker-rootless-extras - for f in rootlesskit rootlesskit-docker-proxy dockerd-rootless.sh dockerd-rootless-setuptool.sh vpnkit; do \ - if [ -f $(ENGINE_DIR)/bundles/binary/$$f ]; then \ - cp -L $(ENGINE_DIR)/bundles/binary/$$f build/linux/docker-rootless-extras/$$f; \ - fi \ - done - tar -C build/linux -c -z -f build/linux/docker-rootless-extras-$(GEN_STATIC_VER).tgz docker-rootless-extras +.PHONY: create_builder +create_builder: # create docker-container builder + docker buildx inspect | tr -d ' ' | grep -q 'Driver:docker-container' || docker buildx create --use --bootstrap - # buildx - tar -C $(BUILDX_DIR)/bin -c -z -f build/linux/docker-buildx-plugin-$(DOCKER_BUILDX_REF:v%=%).tgz docker-buildx +.PHONY: build +build: create_builder ## build static package + CURDIR=$(CURDIR) TARGETPLATFORM=$(TARGETPLATFORM) ./build-static .PHONY: hash_files -hash_files: - @echo "Hashing directory $(DIR_TO_HASH)" +hash_files: ## hash files $(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: buildx - 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-win-engine - cd $(CLI_DIR) && VERSION=$(GEN_STATIC_VER) docker buildx bake --set binary.platform=windows/amd64 binary - 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/win/dockerd.exe build/win/amd64/docker/dockerd.exe - cp $(ENGINE_DIR)/bundles/cross/win/docker-proxy.exe build/win/amd64/docker/docker-proxy.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 -cross-arm: cross-all-cli ## create tgz with linux armhf client only - mkdir -p build/arm/docker - cp $(CLI_DIR)/build/docker-linux-arm build/arm/docker/docker - tar -C build/arm -c -z -f build/arm/docker-$(GEN_STATIC_VER).tgz docker - -.PHONY: static-cli -static-cli: - 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: - cd $(ENGINE_DIR) && docker buildx build --target all $(ENGINE_BUILD_OPTS) --output "./bundles/binary" . - -.PHONY: static-buildx-plugin -static-buildx-plugin: - cd $(BUILDX_DIR) && docker buildx bake --set binaries.platform=$(TARGETPLATFORM) binaries && mv ./bin/build/buildx ./bin/docker-buildx - -.PHONY: cross-all-cli -cross-all-cli: - $(MAKE) -C $(CLI_DIR) -f docker.Makefile VERSION=$(GEN_STATIC_VER) cross - -.PHONY: cross-win-engine -cross-win-engine: - cd $(ENGINE_DIR) && docker buildx build --target binary $(ENGINE_BUILD_OPTS) --platform windows/amd64 --output "./bundles/cross/win" . diff --git a/static/README.md b/static/README.md new file mode 100644 index 0000000000..1f25007cd9 --- /dev/null +++ b/static/README.md @@ -0,0 +1,55 @@ +# Building your own Docker static package + +Static packages can be built from root directory with the following syntax + +```console +make TARGETPLATFORM=${TARGETOS}/${TARGETARCH}/${TARGETVARIANT} static +``` + +Format of `TARGETOS`, `TARGETARCH`, `TARGETVARIANT` is the same as the [platform ARGs in the global scope](https://docs.docker.com/engine/reference/builder/#automatic-platform-args-in-the-global-scope) +for a Dockerfile like `linux/arm/v7`. + +Artifacts will be located in `build` under the following directory structure: +`build/$os/$arch/$variant/` or `build/$os/$arch/` if there is no variant being +used. + +### Building from local source + +Specify the location of the source repositories for the engine and cli when +building packages + +* `ENGINE_DIR` -> Specifies the directory where the engine code is located, eg: `$GOPATH/src/github.com/docker/docker` +* `CLI_DIR` -> Specifies the directory where the cli code is located, eg: `$GOPATH/src/github.com/docker/cli` + +```shell +make ENGINE_DIR=/path/to/engine CLI_DIR=/path/to/cli TARGETPLATFORM=linux/amd64 static +``` + +## Supported platforms + +Here is a list of platforms that are currently supported: + +```console +make TARGETPLATFORM=linux/amd64 static +make TARGETPLATFORM=linux/arm/v6 static +make TARGETPLATFORM=linux/arm/v7 static +make TARGETPLATFORM=linux/arm64 static +make TARGETPLATFORM=darwin/amd64 static +make TARGETPLATFORM=darwin/arm64 static +make TARGETPLATFORM=windows/amd64 static +``` + +> note: `darwin` only packages the docker cli and plugins. + +But you can test building against whatever platform you want like: + +```console +make TARGETPLATFORM=linux/riscv64 static +make TARGETPLATFORM=linux/s390x static +``` + +Or the current one matching your host if not defined: + +```console +make static +``` diff --git a/static/build-static b/static/build-static new file mode 100755 index 0000000000..8b50fd7ca2 --- /dev/null +++ b/static/build-static @@ -0,0 +1,278 @@ +#!/usr/bin/env bash +set -e + +: "${CURDIR=}" +: "${TARGETPLATFORM=}" +: "${TARGETOS=}" +: "${TARGETARCH=}" +: "${TARGETVARIANT=}" + +if [ -z "$CURDIR" ]; then + # shellcheck disable=SC2016 + echo 'CURDIR is required. See README.md for usage.' + exit 1 +fi + +# break up TARGETPLATFORM +if [ -n "$TARGETPLATFORM" ]; then + os="$(echo "$TARGETPLATFORM" | cut -d"/" -f1)" + arch="$(echo "$TARGETPLATFORM" | cut -d"/" -f2)" + if [ -n "$os" ] && [ -n "$arch" ]; then + TARGETOS="$os" + TARGETARCH="$arch" + case "$arch" in + "arm") + case "$(echo "$TARGETPLATFORM" | cut -d"/" -f3)" in + "v5") + TARGETVARIANT="v5" + ;; + "v6") + TARGETVARIANT="v6" + ;; + "v8") + TARGETVARIANT="v8" + ;; + *) + TARGETVARIANT="v7" + ;; + esac + ;; + "mips"*) + TARGETVARIANT="$(echo "$TARGETPLATFORM" | cut -d"/" -f3)" + ;; + esac + fi +fi + +build_cli() { + ( + cd "${CLI_DIR}" + set -x + docker buildx build \ + --build-arg BUILDKIT_MULTI_PLATFORM=true \ + --build-arg GO_VERSION \ + --build-arg GO_LINKMODE=static \ + --build-arg DEFAULT_PRODUCT_LICENSE \ + --build-arg PACKAGER_NAME \ + --build-arg PLATFORM \ + --build-arg PRODUCT \ + --build-arg VERSION="${GEN_STATIC_VER}" \ + --output ./build \ + --platform "${TARGETPLATFORM}" \ + --target binary . + ) +} + +build_engine() { + ( + cd "${ENGINE_DIR}" + set -x + docker buildx build \ + --build-arg BUILDKIT_MULTI_PLATFORM=true \ + --build-arg GO_VERSION \ + --build-arg DOCKER_STATIC=1 \ + --build-arg CONTAINERD_VERSION \ + --build-arg RUNC_VERSION \ + --build-arg DEFAULT_PRODUCT_LICENSE \ + --build-arg PACKAGER_NAME \ + --build-arg PLATFORM \ + --build-arg PRODUCT \ + --build-arg VERSION="${GEN_STATIC_VER}" \ + --output ./build \ + --platform "${TARGETPLATFORM}" \ + --target all . + ) +} + +build_buildx() { + ( + cd "${BUILDX_DIR}" + set -x + docker buildx build \ + --platform "${TARGETPLATFORM}" \ + --build-arg BUILDKIT_MULTI_PLATFORM=true \ + --build-arg GO_VERSION \ + --output ./bin \ + --target binaries . + ) +} + +echo "TARGETPLATFORM=${TARGETPLATFORM}" +echo "CONTAINERD_VERSION=${CONTAINERD_VERSION}" +echo "RUNC_VERSION=${RUNC_VERSION}" + +targetPair="${TARGETOS}_${TARGETARCH}" +if [ -n "${TARGETVARIANT}" ]; then + targetPair="${targetPair}_${TARGETVARIANT}" +fi + +buildDir="${CURDIR}/build/${TARGETPLATFORM}" + +dockerCLIBuildDir="${buildDir}/docker-cli" +dockerBuildDir="${buildDir}/docker-engine" +containerdBuildDir="${buildDir}/containerd" +rootlessExtrasBuildDir="${buildDir}/docker-rootless-extras" +buildxBuildDir="${buildDir}/docker-buildx" + +# clean up previous build output dirs +[ -d "${CLI_DIR:?}/build" ] && rm -r "${CLI_DIR:?}/build" +[ -d "${ENGINE_DIR:?}/build" ] && rm -r "${ENGINE_DIR:?}/build" +[ -d "${BUILDX_DIR:?}/bin" ] && rm -r "${BUILDX_DIR:?}/bin" + +case ${TARGETOS} in + linux) + build_cli + build_engine + build_buildx + ;; + darwin) + build_cli + build_buildx + ;; + windows) + build_cli + build_engine + build_buildx + ;; +esac + +# cleanup +[ -d "${buildDir}" ] && rm -r "${buildDir}" + +# docker CLI +mkdir -p "${dockerCLIBuildDir}" +case ${TARGETOS} in + linux | darwin) + cp "${CLI_DIR}"/build/"${targetPair}"/docker-"${TARGETOS}"-* "${dockerCLIBuildDir}/docker" + ;; + windows) + cp "${CLI_DIR}"/build/"${targetPair}"/docker-"${TARGETOS}"-*.exe "${dockerCLIBuildDir}/docker.exe" + ;; +esac +# package docker CLI +case ${TARGETOS} in + linux | darwin) + ( + set -x + tar -C "${buildDir}" -c -z -f "${buildDir}/docker-cli-${GEN_STATIC_VER}.tgz" docker-cli + ) + ;; + windows) + ( + cd "${buildDir}" + set -x + zip -r "docker-cli-${GEN_STATIC_VER}.zip" docker-cli + ) + ;; +esac + +# docker, containerd, and runc +mkdir -p "${dockerBuildDir}" +case ${TARGETOS} in + linux) + for f in dockerd docker-init docker-proxy; do + if [ -f "${ENGINE_DIR}/build/${targetPair}/$f" ]; then + cp -L "${ENGINE_DIR}/build/${targetPair}/$f" "${dockerBuildDir}/$f" + fi + done + # TODO containerd binaries should be built as part of containerd-packaging, not as part of docker/docker-ce-packaging + mkdir -p "${containerdBuildDir}" + for f in containerd ctr containerd-shim containerd-shim-runc-v2 runc; do + if [ -f "${ENGINE_DIR}/build/${targetPair}/$f" ]; then + cp -L "${ENGINE_DIR}/build/${targetPair}/$f" "${containerdBuildDir}/$f" + fi + done + ;; + windows) + for f in dockerd.exe docker-proxy.exe; do + if [ -f "${ENGINE_DIR}/build/${targetPair}/$f" ]; then + cp -L "${ENGINE_DIR}/build/${targetPair}/$f" "${dockerBuildDir}/$f" + fi + done + ;; +esac +# package docker, containerd, and runc +case ${TARGETOS} in + darwin) + ( + set -x + tar -C "${buildDir}" -c -z -f "${buildDir}/docker-engine-${GEN_STATIC_VER}.tgz" docker-engine + ) + ;; + linux) + ( + set -x + tar -C "${buildDir}" -c -z -f "${buildDir}/docker-engine-${GEN_STATIC_VER}.tgz" docker-engine + tar -C "${buildDir}" -c -z -f "${buildDir}/containerd-${CONTAINERD_VERSION#v}.tgz" containerd + ) + ;; + windows) + ( + cd "${buildDir}" + set -x + zip -r "docker-engine-${GEN_STATIC_VER}.zip" docker-engine + ) + ;; +esac + +# rootless extras +case ${TARGETOS} in + linux) + for f in rootlesskit rootlesskit-docker-proxy dockerd-rootless.sh dockerd-rootless-setuptool.sh vpnkit; do + if [ -f "${ENGINE_DIR}/bundles/${TARGETPLATFORM}/$f" ]; then + mkdir -p "${rootlessExtrasBuildDir}" + cp -L "${ENGINE_DIR}/bundles/${TARGETPLATFORM}/$f" "${rootlessExtrasBuildDir}/$f" + fi + done + ;; +esac +# package rootless extras +if [ -d "${rootlessExtrasBuildDir}" ]; then + case ${TARGETOS} in + linux) + ( + set -x + tar -C "${buildDir}" -c -z -f "${buildDir}/docker-rootless-extras-${GEN_STATIC_VER}.tgz" docker-rootless-extras + ) + ;; + esac +fi + +# buildx +if [ -d "${BUILDX_DIR}/bin" ]; then + mkdir -p "${buildxBuildDir}" + case ${TARGETOS} in + linux | darwin) + cp "${BUILDX_DIR}/bin/${targetPair}/buildx" "${buildxBuildDir}/docker-buildx" + ;; + windows) + cp "${BUILDX_DIR}/bin/${targetPair}/buildx.exe" "${buildxBuildDir}/docker-buildx.exe" + ;; + esac + # package buildx + case ${TARGETOS} in + linux | darwin) + ( + set -x + tar -C "${buildDir}" -c -z -f "${buildDir}/docker-buildx-plugin-${DOCKER_BUILDX_REF#v}.tgz" docker-buildx + ) + ;; + windows) + ( + cd "${buildDir}" + set -x + zip -r "docker-buildx-plugin-${DOCKER_BUILDX_REF#v}.zip" docker-buildx + ) + ;; + esac +fi + +# create bundle +( + # bundle is expected to have a tar.gz extension, unlike the other archives, which use .tgz + bundlesFilename="bundles-ce-static-${TARGETOS}-${TARGETARCH}${TARGETVARIANT}.tar.gz" + set -x + cd "${buildDir}" + rm -r */ + tar -zvcf "${CURDIR}/build/${bundlesFilename}" . +) From 9e0583552e162dd5b591b96883386ba6003e727f Mon Sep 17 00:00:00 2001 From: CrazyMax Date: Wed, 25 Jan 2023 13:22:00 +0100 Subject: [PATCH 2/7] ci: static job Signed-off-by: CrazyMax --- .github/workflows/ci.yml | 44 +++++++++++++++++++++++++++++++++++++++- 1 file changed, 43 insertions(+), 1 deletion(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 03e81047f7..cc857c757b 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -11,7 +11,7 @@ on: pull_request: jobs: - build: + pkg: runs-on: ubuntu-20.04 strategy: fail-fast: false @@ -29,3 +29,45 @@ jobs: name: Build run: | make ${{ matrix.target }} + + static: + runs-on: ubuntu-20.04 + strategy: + fail-fast: false + matrix: + platform: + - linux/amd64 + - linux/arm/v6 + - linux/arm/v7 + - linux/arm64 + - darwin/amd64 + - darwin/arm64 + - windows/amd64 + steps: + - + name: Prepare + run: | + platform=${{ matrix.platform }} + echo "PLATFORM_PAIR=${platform//\//-}" >> $GITHUB_ENV + - + name: Checkout + uses: actions/checkout@v3 + - + name: Set up Docker Buildx + uses: docker/setup-buildx-action@v2 + - + name: Build + run: | + make TARGETPLATFORM=${{ matrix.platform }} static + - + name: List files + run: | + tree -nh ./static/build + - + name: Upload static bundle + uses: actions/upload-artifact@v3 + with: + name: static-${{ env.PLATFORM_PAIR }} + path: static/build/*.tar.gz + if-no-files-found: error + retention-days: 2 From a416ee1265dc7342ccd7282cd901ca2862a0cada Mon Sep 17 00:00:00 2001 From: CrazyMax Date: Wed, 25 Jan 2023 14:56:04 +0100 Subject: [PATCH 3/7] static: keep old arches to match folder structure Signed-off-by: CrazyMax --- .github/workflows/ci.yml | 32 +++++++------- Jenkinsfile | 20 ++++----- static/Makefile | 2 +- static/README.md | 37 +++++++---------- static/build-static | 90 ++++++++++++++++++++++++++-------------- 5 files changed, 102 insertions(+), 79 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index cc857c757b..4bddb9f3ee 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -35,20 +35,22 @@ jobs: strategy: fail-fast: false matrix: - platform: - - linux/amd64 - - linux/arm/v6 - - linux/arm/v7 - - linux/arm64 - - darwin/amd64 - - darwin/arm64 - - windows/amd64 + include: + - os: linux + arch: x86_64 + - os: linux + arch: armel + - os: linux + arch: armhf + - os: linux + arch: aarch64 + - os: darwin + arch: x86_64 + - os: darwin + arch: aarch64 + - os: windows + arch: x86_64 steps: - - - name: Prepare - run: | - platform=${{ matrix.platform }} - echo "PLATFORM_PAIR=${platform//\//-}" >> $GITHUB_ENV - name: Checkout uses: actions/checkout@v3 @@ -58,7 +60,7 @@ jobs: - name: Build run: | - make TARGETPLATFORM=${{ matrix.platform }} static + make STATICOS=${{ matrix.os }} STATICARCH=${{ matrix.arch }} static - name: List files run: | @@ -67,7 +69,7 @@ jobs: name: Upload static bundle uses: actions/upload-artifact@v3 with: - name: static-${{ env.PLATFORM_PAIR }} + name: static-${{ matrix.os }}-${{ matrix.arch }} path: static/build/*.tar.gz if-no-files-found: error retention-days: 2 diff --git a/Jenkinsfile b/Jenkinsfile index 1bd93cf476..597bc0f462 100644 --- a/Jenkinsfile +++ b/Jenkinsfile @@ -19,9 +19,9 @@ def pkgs = [ ] def statics = [ - [os: "linux", arches: ["amd64", "armv6", "armv7", "aarch64"]], - [os: "darwin", arches: ["amd64", "aarch64"]], - [os: "windows", arches: ["amd64"]], + [os: "linux", arches: ["x86_64", "armel", "armhf", "aarch64"]], + [os: "darwin", arches: ["x86_64", "aarch64"]], + [os: "windows", arches: ["x86_64"]], ] def genPkgStep(LinkedHashMap pkg, String arch) { @@ -64,12 +64,12 @@ def genPkgSteps(opts) { def genStaticStep(LinkedHashMap pkg, String arch) { def config = [ - amd64: [label: "x86_64", targetarch: "amd64"], - aarch64: [label: "aarch64", targetarch: "arm64"], - armv6: [label: "aarch64", targetarch: "arm/v6"], - armv7: [label: "aarch64", targetarch: "arm/v7"], - ppc64le: [label: "ppc64le", targetarch: "ppc64le"], - s390x : [label: "s390x", targetarch: "s390x"], + x86_64: [label: "x86_64"], + aarch64: [label: "aarch64"], + armel: [label: "aarch64"], + armhf: [label: "aarch64"], + ppc64le: [label: "ppc64le"], + s390x : [label: "s390x"], ][arch] def nodeLabel = "linux&&${config.label}" if (config.label == 'x86_64') { @@ -91,7 +91,7 @@ def genStaticStep(LinkedHashMap pkg, String arch) { stage("build") { try { checkout scm - sh "make REF=$branch TARGETPLATFORM=${pkg.os}/${config.targetarch} static" + sh "make REF=$branch STATICOS=${pkg.os} STATICARCH=${arch} static" } finally { sh "make clean" } diff --git a/static/Makefile b/static/Makefile index d8ca222314..21730a4bb9 100644 --- a/static/Makefile +++ b/static/Makefile @@ -45,7 +45,7 @@ create_builder: # create docker-container builder .PHONY: build build: create_builder ## build static package - CURDIR=$(CURDIR) TARGETPLATFORM=$(TARGETPLATFORM) ./build-static + CURDIR=$(CURDIR) STATICOS=$(STATICOS) STATICARCH=$(STATICARCH) ./build-static .PHONY: hash_files hash_files: ## hash files diff --git a/static/README.md b/static/README.md index 1f25007cd9..d2b3a971e7 100644 --- a/static/README.md +++ b/static/README.md @@ -3,15 +3,14 @@ Static packages can be built from root directory with the following syntax ```console -make TARGETPLATFORM=${TARGETOS}/${TARGETARCH}/${TARGETVARIANT} static +make STATICOS=${STATICOS} STATICOS=${STATICARCH} static ``` -Format of `TARGETOS`, `TARGETARCH`, `TARGETVARIANT` is the same as the [platform ARGs in the global scope](https://docs.docker.com/engine/reference/builder/#automatic-platform-args-in-the-global-scope) -for a Dockerfile like `linux/arm/v7`. +Format of `STATICOS`, `STATICARCH` should respect the current folder structure on +[download.docker.com](https://download-stage.docker.com/linux/static/stable/) like +`STATICOS=linux STATICARCH=armhf`. -Artifacts will be located in `build` under the following directory structure: -`build/$os/$arch/$variant/` or `build/$os/$arch/` if there is no variant being -used. +Artifacts will be located in `build` under `build/$STATICOS/$STATICARCH/`. ### Building from local source @@ -22,7 +21,7 @@ building packages * `CLI_DIR` -> Specifies the directory where the cli code is located, eg: `$GOPATH/src/github.com/docker/cli` ```shell -make ENGINE_DIR=/path/to/engine CLI_DIR=/path/to/cli TARGETPLATFORM=linux/amd64 static +make ENGINE_DIR=/path/to/engine CLI_DIR=/path/to/cli STATICOS=linux STATICARCH=x86_64 static ``` ## Supported platforms @@ -30,13 +29,13 @@ make ENGINE_DIR=/path/to/engine CLI_DIR=/path/to/cli TARGETPLATFORM=linux/amd64 Here is a list of platforms that are currently supported: ```console -make TARGETPLATFORM=linux/amd64 static -make TARGETPLATFORM=linux/arm/v6 static -make TARGETPLATFORM=linux/arm/v7 static -make TARGETPLATFORM=linux/arm64 static -make TARGETPLATFORM=darwin/amd64 static -make TARGETPLATFORM=darwin/arm64 static -make TARGETPLATFORM=windows/amd64 static +make STATICOS=linux STATICARCH=x86_64 static +make STATICOS=linux STATICARCH=armel static +make STATICOS=linux STATICARCH=armhf static +make STATICOS=linux STATICARCH=aarch64 static +make STATICOS=darwin STATICARCH=x86_64 static +make STATICOS=darwin STATICARCH=aarch64 static +make STATICOS=windows STATICARCH=x86_64 static ``` > note: `darwin` only packages the docker cli and plugins. @@ -44,12 +43,6 @@ make TARGETPLATFORM=windows/amd64 static But you can test building against whatever platform you want like: ```console -make TARGETPLATFORM=linux/riscv64 static -make TARGETPLATFORM=linux/s390x static -``` - -Or the current one matching your host if not defined: - -```console -make static +make STATICOS=linux STATICARCH=riscv64 static +make STATICOS=linux STATICARCH=s390x static ``` diff --git a/static/build-static b/static/build-static index 8b50fd7ca2..2cbb18ac7a 100755 --- a/static/build-static +++ b/static/build-static @@ -2,6 +2,8 @@ set -e : "${CURDIR=}" +: "${STATICOS=}" +: "${STATICARCH=}" : "${TARGETPLATFORM=}" : "${TARGETOS=}" : "${TARGETARCH=}" @@ -12,38 +14,64 @@ if [ -z "$CURDIR" ]; then echo 'CURDIR is required. See README.md for usage.' exit 1 fi - -# break up TARGETPLATFORM -if [ -n "$TARGETPLATFORM" ]; then - os="$(echo "$TARGETPLATFORM" | cut -d"/" -f1)" - arch="$(echo "$TARGETPLATFORM" | cut -d"/" -f2)" - if [ -n "$os" ] && [ -n "$arch" ]; then - TARGETOS="$os" - TARGETARCH="$arch" - case "$arch" in - "arm") - case "$(echo "$TARGETPLATFORM" | cut -d"/" -f3)" in - "v5") - TARGETVARIANT="v5" - ;; - "v6") - TARGETVARIANT="v6" - ;; - "v8") - TARGETVARIANT="v8" - ;; - *) - TARGETVARIANT="v7" - ;; - esac - ;; - "mips"*) - TARGETVARIANT="$(echo "$TARGETPLATFORM" | cut -d"/" -f3)" - ;; - esac - fi +if [[ -z "$STATICOS" ]] || [[ -z "$STATICARCH" ]]; then + # shellcheck disable=SC2016 + echo 'STATICOS and STATICARCH are required. See README.md for usage.' + exit 1 fi +# TODO: remove this once we support TARGETPLATFORM in download.docker.com folder structure +TARGETOS="$STATICOS" +# STATICARCH reverse lookup for compat with TARGETPLATFORM +case "$STATICARCH" in + "x86_64") + TARGETARCH="amd64" + ;; + "i386") + TARGETARCH="386" + ;; + "aarch64") + TARGETARCH="arm64" + ;; + "armhf") + TARGETARCH="arm" + TARGETVARIANT="v7" + ;; + "armel") + TARGETARCH="arm" + TARGETVARIANT="v6" + ;; +# "armel") +# TARGETARCH="arm" +# TARGETVARIANT="v5" +# ;; + "riscv64") + TARGETARCH="riscv64" + ;; + "ppc64le") + TARGETARCH="ppc64le" + ;; + "s390x") + TARGETARCH="s390x" + ;; + "mips") + TARGETARCH="mips" + ;; + "mipsle") + TARGETARCH="mipsle" + ;; + "mips64") + TARGETARCH="mips64" + ;; + "mips64le") + TARGETARCH="mips64le" + ;; + *) + TARGETARCH="$STATICARCH" + ;; +esac +TARGETPLATFORM="${TARGETOS}/${TARGETARCH}${TARGETVARIANT:+/${TARGETVARIANT}}" + build_cli() { ( cd "${CLI_DIR}" @@ -270,7 +298,7 @@ fi # create bundle ( # bundle is expected to have a tar.gz extension, unlike the other archives, which use .tgz - bundlesFilename="bundles-ce-static-${TARGETOS}-${TARGETARCH}${TARGETVARIANT}.tar.gz" + bundlesFilename="bundles-ce-static-${STATICOS}-${STATICARCH}.tar.gz" set -x cd "${buildDir}" rm -r */ From 7c6ddc99bfc242400a6ac120865e134b78be7c3c Mon Sep 17 00:00:00 2001 From: CrazyMax Date: Wed, 25 Jan 2023 16:23:21 +0100 Subject: [PATCH 4/7] static: for backward compat keep docker.tgz Signed-off-by: CrazyMax --- static/build-static | 37 +++++++++++++++++++++++++++++++++---- 1 file changed, 33 insertions(+), 4 deletions(-) diff --git a/static/build-static b/static/build-static index 2cbb18ac7a..9e28ad9155 100755 --- a/static/build-static +++ b/static/build-static @@ -137,7 +137,8 @@ fi buildDir="${CURDIR}/build/${TARGETPLATFORM}" dockerCLIBuildDir="${buildDir}/docker-cli" -dockerBuildDir="${buildDir}/docker-engine" +dockerEngineBuildDir="${buildDir}/docker-engine" +dockerBuildDir="${buildDir}/docker" containerdBuildDir="${buildDir}/containerd" rootlessExtrasBuildDir="${buildDir}/docker-rootless-extras" buildxBuildDir="${buildDir}/docker-buildx" @@ -195,12 +196,12 @@ case ${TARGETOS} in esac # docker, containerd, and runc -mkdir -p "${dockerBuildDir}" +mkdir -p "${dockerEngineBuildDir}" case ${TARGETOS} in linux) for f in dockerd docker-init docker-proxy; do if [ -f "${ENGINE_DIR}/build/${targetPair}/$f" ]; then - cp -L "${ENGINE_DIR}/build/${targetPair}/$f" "${dockerBuildDir}/$f" + cp -L "${ENGINE_DIR}/build/${targetPair}/$f" "${dockerEngineBuildDir}/$f" fi done # TODO containerd binaries should be built as part of containerd-packaging, not as part of docker/docker-ce-packaging @@ -214,7 +215,7 @@ case ${TARGETOS} in windows) for f in dockerd.exe docker-proxy.exe; do if [ -f "${ENGINE_DIR}/build/${targetPair}/$f" ]; then - cp -L "${ENGINE_DIR}/build/${targetPair}/$f" "${dockerBuildDir}/$f" + cp -L "${ENGINE_DIR}/build/${targetPair}/$f" "${dockerEngineBuildDir}/$f" fi done ;; @@ -243,6 +244,34 @@ case ${TARGETOS} in ;; esac +# docker CLI + docker engine +# TODO: for backward compat keep a copy of the old docker.tgz for now +mkdir -p "${dockerBuildDir}" +if [ "$(ls -A "${dockerCLIBuildDir}")" ]; then + cp "${dockerCLIBuildDir}"/* "${dockerBuildDir}/" +fi +if [ "$(ls -A "${dockerEngineBuildDir}")" ]; then + cp "${dockerEngineBuildDir}"/* "${dockerBuildDir}/" +fi +# package docker +if [ "$(ls -A "${dockerBuildDir}")" ]; then + case ${TARGETOS} in + linux | darwin) + ( + set -x + tar -C "${buildDir}" -c -z -f "${buildDir}/docker-${GEN_STATIC_VER}.tgz" docker + ) + ;; + windows) + ( + cd "${buildDir}" + set -x + zip -r "docker-${GEN_STATIC_VER}.zip" docker + ) + ;; + esac +fi + # rootless extras case ${TARGETOS} in linux) From 097a8a35b9b8e8092eb72993c479818260ae9322 Mon Sep 17 00:00:00 2001 From: CrazyMax Date: Wed, 25 Jan 2023 16:35:25 +0100 Subject: [PATCH 5/7] static: skip packaging if platform not supported Signed-off-by: CrazyMax --- static/build-static | 138 ++++++++++++++++++++++---------------------- 1 file changed, 68 insertions(+), 70 deletions(-) diff --git a/static/build-static b/static/build-static index 9e28ad9155..5e1531ad88 100755 --- a/static/build-static +++ b/static/build-static @@ -170,79 +170,77 @@ esac # docker CLI mkdir -p "${dockerCLIBuildDir}" -case ${TARGETOS} in - linux | darwin) - cp "${CLI_DIR}"/build/"${targetPair}"/docker-"${TARGETOS}"-* "${dockerCLIBuildDir}/docker" - ;; - windows) - cp "${CLI_DIR}"/build/"${targetPair}"/docker-"${TARGETOS}"-*.exe "${dockerCLIBuildDir}/docker.exe" - ;; -esac -# package docker CLI -case ${TARGETOS} in - linux | darwin) - ( - set -x - tar -C "${buildDir}" -c -z -f "${buildDir}/docker-cli-${GEN_STATIC_VER}.tgz" docker-cli - ) - ;; - windows) - ( - cd "${buildDir}" - set -x - zip -r "docker-cli-${GEN_STATIC_VER}.zip" docker-cli - ) - ;; -esac +if [ -d "${CLI_DIR}/build" ]; then + case ${TARGETOS} in + linux | darwin) + cp "${CLI_DIR}"/build/"${targetPair}"/docker-"${TARGETOS}"-* "${dockerCLIBuildDir}/docker" + ;; + windows) + cp "${CLI_DIR}"/build/"${targetPair}"/docker-"${TARGETOS}"-*.exe "${dockerCLIBuildDir}/docker.exe" + ;; + esac + # package docker CLI + case ${TARGETOS} in + linux | darwin) + ( + set -x + tar -C "${buildDir}" -c -z -f "${buildDir}/docker-cli-${GEN_STATIC_VER}.tgz" docker-cli + ) + ;; + windows) + ( + cd "${buildDir}" + set -x + zip -r "docker-cli-${GEN_STATIC_VER}.zip" docker-cli + ) + ;; + esac +fi # docker, containerd, and runc mkdir -p "${dockerEngineBuildDir}" -case ${TARGETOS} in - linux) - for f in dockerd docker-init docker-proxy; do - if [ -f "${ENGINE_DIR}/build/${targetPair}/$f" ]; then - cp -L "${ENGINE_DIR}/build/${targetPair}/$f" "${dockerEngineBuildDir}/$f" - fi - done - # TODO containerd binaries should be built as part of containerd-packaging, not as part of docker/docker-ce-packaging - mkdir -p "${containerdBuildDir}" - for f in containerd ctr containerd-shim containerd-shim-runc-v2 runc; do - if [ -f "${ENGINE_DIR}/build/${targetPair}/$f" ]; then - cp -L "${ENGINE_DIR}/build/${targetPair}/$f" "${containerdBuildDir}/$f" - fi - done - ;; - windows) - for f in dockerd.exe docker-proxy.exe; do - if [ -f "${ENGINE_DIR}/build/${targetPair}/$f" ]; then - cp -L "${ENGINE_DIR}/build/${targetPair}/$f" "${dockerEngineBuildDir}/$f" - fi - done - ;; -esac -# package docker, containerd, and runc -case ${TARGETOS} in - darwin) - ( - set -x - tar -C "${buildDir}" -c -z -f "${buildDir}/docker-engine-${GEN_STATIC_VER}.tgz" docker-engine - ) - ;; - linux) - ( - set -x - tar -C "${buildDir}" -c -z -f "${buildDir}/docker-engine-${GEN_STATIC_VER}.tgz" docker-engine - tar -C "${buildDir}" -c -z -f "${buildDir}/containerd-${CONTAINERD_VERSION#v}.tgz" containerd - ) - ;; - windows) - ( - cd "${buildDir}" - set -x - zip -r "docker-engine-${GEN_STATIC_VER}.zip" docker-engine - ) - ;; -esac +if [ -d "${ENGINE_DIR}/build" ]; then + case ${TARGETOS} in + linux) + for f in dockerd docker-init docker-proxy; do + if [ -f "${ENGINE_DIR}/build/${targetPair}/$f" ]; then + cp -L "${ENGINE_DIR}/build/${targetPair}/$f" "${dockerEngineBuildDir}/$f" + fi + done + # TODO containerd binaries should be built as part of containerd-packaging, not as part of docker/docker-ce-packaging + mkdir -p "${containerdBuildDir}" + for f in containerd ctr containerd-shim containerd-shim-runc-v2 runc; do + if [ -f "${ENGINE_DIR}/build/${targetPair}/$f" ]; then + cp -L "${ENGINE_DIR}/build/${targetPair}/$f" "${containerdBuildDir}/$f" + fi + done + ;; + windows) + for f in dockerd.exe docker-proxy.exe; do + if [ -f "${ENGINE_DIR}/build/${targetPair}/$f" ]; then + cp -L "${ENGINE_DIR}/build/${targetPair}/$f" "${dockerEngineBuildDir}/$f" + fi + done + ;; + esac + # package docker, containerd, and runc + case ${TARGETOS} in + linux) + ( + set -x + tar -C "${buildDir}" -c -z -f "${buildDir}/docker-engine-${GEN_STATIC_VER}.tgz" docker-engine + tar -C "${buildDir}" -c -z -f "${buildDir}/containerd-${CONTAINERD_VERSION#v}.tgz" containerd + ) + ;; + windows) + ( + cd "${buildDir}" + set -x + zip -r "docker-engine-${GEN_STATIC_VER}.zip" docker-engine + ) + ;; + esac +fi # docker CLI + docker engine # TODO: for backward compat keep a copy of the old docker.tgz for now From 30762f1581b6df7ff383b03820669cb988829bf1 Mon Sep 17 00:00:00 2001 From: CrazyMax Date: Sat, 4 Feb 2023 16:18:05 +0100 Subject: [PATCH 6/7] static: add compose Signed-off-by: CrazyMax --- static/Makefile | 4 +++- static/build-static | 47 +++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 50 insertions(+), 1 deletion(-) diff --git a/static/Makefile b/static/Makefile index 21730a4bb9..83c1a4cffc 100644 --- a/static/Makefile +++ b/static/Makefile @@ -3,6 +3,7 @@ include ../common.mk CLI_DIR=$(realpath $(CURDIR)/../src/github.com/docker/cli) ENGINE_DIR=$(realpath $(CURDIR)/../src/github.com/docker/docker) BUILDX_DIR=$(realpath $(CURDIR)/../src/github.com/docker/buildx) +COMPOSE_DIR=$(realpath $(CURDIR)/../src/github.com/docker/compose) ENGINE_GITCOMMIT?=$(shell cd $(realpath $(CURDIR)/../src/github.com/docker/docker) && git rev-parse --short HEAD) GEN_STATIC_VER=$(shell ./gen-static-ver $(CLI_DIR) $(VERSION)) @@ -17,6 +18,7 @@ RUNC_VERSION?=$(shell grep "ARG RUNC_VERSION" "$(ENGINE_DIR)/Dockerfile" | awk - export CLI_DIR export ENGINE_DIR export BUILDX_DIR +export COMPOSE_DIR export GEN_STATIC_VER export CONTAINERD_VERSION export RUNC_VERSION @@ -25,8 +27,8 @@ export REF export DOCKER_CLI_REF export DOCKER_ENGINE_REF export DOCKER_SCAN_REF -export DOCKER_COMPOSE_REF export DOCKER_BUILDX_REF +export DOCKER_COMPOSE_REF export GO_VERSION diff --git a/static/build-static b/static/build-static index 5e1531ad88..7c07c8b336 100755 --- a/static/build-static +++ b/static/build-static @@ -125,6 +125,19 @@ build_buildx() { ) } +build_compose() { + ( + cd "${COMPOSE_DIR}" + set -x + docker buildx build \ + --platform "${TARGETPLATFORM}" \ + --build-arg BUILDKIT_MULTI_PLATFORM=true \ + --build-arg GO_VERSION \ + --output ./bin \ + --target binary . + ) +} + echo "TARGETPLATFORM=${TARGETPLATFORM}" echo "CONTAINERD_VERSION=${CONTAINERD_VERSION}" echo "RUNC_VERSION=${RUNC_VERSION}" @@ -142,26 +155,31 @@ dockerBuildDir="${buildDir}/docker" containerdBuildDir="${buildDir}/containerd" rootlessExtrasBuildDir="${buildDir}/docker-rootless-extras" buildxBuildDir="${buildDir}/docker-buildx" +composeBuildDir="${buildDir}/docker-compose" # clean up previous build output dirs [ -d "${CLI_DIR:?}/build" ] && rm -r "${CLI_DIR:?}/build" [ -d "${ENGINE_DIR:?}/build" ] && rm -r "${ENGINE_DIR:?}/build" [ -d "${BUILDX_DIR:?}/bin" ] && rm -r "${BUILDX_DIR:?}/bin" +[ -d "${COMPOSE_DIR:?}/bin" ] && rm -r "${COMPOSE_DIR:?}/bin" case ${TARGETOS} in linux) build_cli build_engine build_buildx + build_compose ;; darwin) build_cli build_buildx + build_compose ;; windows) build_cli build_engine build_buildx + build_compose ;; esac @@ -322,6 +340,35 @@ if [ -d "${BUILDX_DIR}/bin" ]; then esac fi +# compose +if [ -d "${COMPOSE_DIR}/bin" ]; then + mkdir -p "${composeBuildDir}" + case ${TARGETOS} in + linux | darwin) + cp "${COMPOSE_DIR}/bin/${targetPair}/docker-compose" "${composeBuildDir}/docker-compose" + ;; + windows) + cp "${COMPOSE_DIR}/bin/${targetPair}/docker-compose.exe" "${composeBuildDir}/docker-compose.exe" + ;; + esac + # package compose + case ${TARGETOS} in + linux | darwin) + ( + set -x + tar -C "${buildDir}" -c -z -f "${buildDir}/docker-compose-plugin-${DOCKER_COMPOSE_REF#v}.tgz" docker-compose + ) + ;; + windows) + ( + cd "${buildDir}" + set -x + zip -r "docker-compose-plugin-${DOCKER_COMPOSE_REF#v}.zip" docker-compose + ) + ;; + esac +fi + # create bundle ( # bundle is expected to have a tar.gz extension, unlike the other archives, which use .tgz From 228bcada6d4f8a7a9ddcdeb665b47342263bd3ca Mon Sep 17 00:00:00 2001 From: CrazyMax Date: Thu, 2 Feb 2023 12:17:50 +0100 Subject: [PATCH 7/7] static: build ppc64le and s390x packages Signed-off-by: CrazyMax --- .github/workflows/ci.yml | 4 ++++ Jenkinsfile | 6 +++--- 2 files changed, 7 insertions(+), 3 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 4bddb9f3ee..ac35cb53e9 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -44,6 +44,10 @@ jobs: arch: armhf - os: linux arch: aarch64 + - os: linux + arch: ppc64le + - os: linux + arch: s390x - os: darwin arch: x86_64 - os: darwin diff --git a/Jenkinsfile b/Jenkinsfile index 597bc0f462..b256b8a1b0 100644 --- a/Jenkinsfile +++ b/Jenkinsfile @@ -19,7 +19,7 @@ def pkgs = [ ] def statics = [ - [os: "linux", arches: ["x86_64", "armel", "armhf", "aarch64"]], + [os: "linux", arches: ["x86_64", "armel", "armhf", "aarch64", "ppc64le", "s390x"]], [os: "darwin", arches: ["x86_64", "aarch64"]], [os: "windows", arches: ["x86_64"]], ] @@ -68,8 +68,8 @@ def genStaticStep(LinkedHashMap pkg, String arch) { aarch64: [label: "aarch64"], armel: [label: "aarch64"], armhf: [label: "aarch64"], - ppc64le: [label: "ppc64le"], - s390x : [label: "s390x"], + ppc64le: [label: "x86_64"], + s390x : [label: "x86_64"], ][arch] def nodeLabel = "linux&&${config.label}" if (config.label == 'x86_64') {