diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 03e81047f7..ac35cb53e9 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,51 @@ jobs: name: Build run: | make ${{ matrix.target }} + + static: + runs-on: ubuntu-20.04 + strategy: + fail-fast: false + matrix: + include: + - os: linux + arch: x86_64 + - os: linux + arch: armel + - os: linux + arch: armhf + - os: linux + arch: aarch64 + - os: linux + arch: ppc64le + - os: linux + arch: s390x + - os: darwin + arch: x86_64 + - os: darwin + arch: aarch64 + - os: windows + arch: x86_64 + steps: + - + name: Checkout + uses: actions/checkout@v3 + - + name: Set up Docker Buildx + uses: docker/setup-buildx-action@v2 + - + name: Build + run: | + make STATICOS=${{ matrix.os }} STATICARCH=${{ matrix.arch }} static + - + name: List files + run: | + tree -nh ./static/build + - + name: Upload static bundle + uses: actions/upload-artifact@v3 + with: + 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 a59db1d460..b256b8a1b0 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: ["x86_64", "armel", "armhf", "aarch64", "ppc64le", "s390x"]], + [os: "darwin", arches: ["x86_64", "aarch64"]], + [os: "windows", arches: ["x86_64"]], +] + +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 = [ + x86_64: [label: "x86_64"], + aarch64: [label: "aarch64"], + armel: [label: "aarch64"], + armhf: [label: "aarch64"], + ppc64le: [label: "x86_64"], + s390x : [label: "x86_64"], + ][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 STATICOS=${pkg.os} STATICARCH=${arch} 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..83c1a4cffc 100644 --- a/static/Makefile +++ b/static/Makefile @@ -3,28 +3,34 @@ 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)) 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 COMPOSE_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_BUILDX_REF +export DOCKER_COMPOSE_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 +38,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) STATICOS=$(STATICOS) STATICARCH=$(STATICARCH) ./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..d2b3a971e7 --- /dev/null +++ b/static/README.md @@ -0,0 +1,48 @@ +# Building your own Docker static package + +Static packages can be built from root directory with the following syntax + +```console +make STATICOS=${STATICOS} STATICOS=${STATICARCH} static +``` + +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 `build/$STATICOS/$STATICARCH/`. + +### 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 STATICOS=linux STATICARCH=x86_64 static +``` + +## Supported platforms + +Here is a list of platforms that are currently supported: + +```console +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. + +But you can test building against whatever platform you want like: + +```console +make STATICOS=linux STATICARCH=riscv64 static +make STATICOS=linux STATICARCH=s390x static +``` diff --git a/static/build-static b/static/build-static new file mode 100755 index 0000000000..7c07c8b336 --- /dev/null +++ b/static/build-static @@ -0,0 +1,380 @@ +#!/usr/bin/env bash +set -e + +: "${CURDIR=}" +: "${STATICOS=}" +: "${STATICARCH=}" +: "${TARGETPLATFORM=}" +: "${TARGETOS=}" +: "${TARGETARCH=}" +: "${TARGETVARIANT=}" + +if [ -z "$CURDIR" ]; then + # shellcheck disable=SC2016 + echo 'CURDIR is required. See README.md for usage.' + exit 1 +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}" + 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 . + ) +} + +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}" + +targetPair="${TARGETOS}_${TARGETARCH}" +if [ -n "${TARGETVARIANT}" ]; then + targetPair="${targetPair}_${TARGETVARIANT}" +fi + +buildDir="${CURDIR}/build/${TARGETPLATFORM}" + +dockerCLIBuildDir="${buildDir}/docker-cli" +dockerEngineBuildDir="${buildDir}/docker-engine" +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 + +# cleanup +[ -d "${buildDir}" ] && rm -r "${buildDir}" + +# docker CLI +mkdir -p "${dockerCLIBuildDir}" +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}" +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 +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) + 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 + +# 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 + bundlesFilename="bundles-ce-static-${STATICOS}-${STATICARCH}.tar.gz" + set -x + cd "${buildDir}" + rm -r */ + tar -zvcf "${CURDIR}/build/${bundlesFilename}" . +)