Better support for cross compilation so we can fully rely
on `--platform` flag of buildx for a seamless integration.
This removes unnecessary extra cross logic in the Dockerfile,
DOCKER_CROSSPLATFORMS and CROSS vars and some hack scripts as well.
Non-sandboxed build invocation is still supported and dev stages
in the Dockerfile have been updated accordingly.
Bake definition and GitHub Actions workflows have been updated
accordingly as well.
Signed-off-by: CrazyMax <crazy-max@users.noreply.github.com>
| ... | ... |
@@ -54,23 +54,36 @@ jobs: |
| 54 | 54 |
if-no-files-found: error |
| 55 | 55 |
retention-days: 7 |
| 56 | 56 |
|
| 57 |
+ prepare-cross: |
|
| 58 |
+ runs-on: ubuntu-latest |
|
| 59 |
+ needs: |
|
| 60 |
+ - validate-dco |
|
| 61 |
+ outputs: |
|
| 62 |
+ matrix: ${{ steps.platforms.outputs.matrix }}
|
|
| 63 |
+ steps: |
|
| 64 |
+ - |
|
| 65 |
+ name: Checkout |
|
| 66 |
+ uses: actions/checkout@v3 |
|
| 67 |
+ - |
|
| 68 |
+ name: Create matrix |
|
| 69 |
+ id: platforms |
|
| 70 |
+ run: | |
|
| 71 |
+ matrix="$(docker buildx bake binary-cross --print | jq -cr '.target."binary-cross".platforms')" |
|
| 72 |
+ echo "matrix=$matrix" >> $GITHUB_OUTPUT |
|
| 73 |
+ - |
|
| 74 |
+ name: Show matrix |
|
| 75 |
+ run: | |
|
| 76 |
+ echo ${{ steps.platforms.outputs.matrix }}
|
|
| 77 |
+ |
|
| 57 | 78 |
cross: |
| 58 | 79 |
runs-on: ubuntu-20.04 |
| 59 | 80 |
needs: |
| 60 | 81 |
- validate-dco |
| 82 |
+ - prepare-cross |
|
| 61 | 83 |
strategy: |
| 62 | 84 |
fail-fast: false |
| 63 | 85 |
matrix: |
| 64 |
- platform: |
|
| 65 |
- - linux/amd64 |
|
| 66 |
- - linux/arm/v5 |
|
| 67 |
- - linux/arm/v6 |
|
| 68 |
- - linux/arm/v7 |
|
| 69 |
- - linux/arm64 |
|
| 70 |
- - linux/ppc64le |
|
| 71 |
- - linux/s390x |
|
| 72 |
- - windows/amd64 |
|
| 73 |
- - windows/arm64 |
|
| 86 |
+ platform: ${{ fromJson(needs.prepare-cross.outputs.matrix) }}
|
|
| 74 | 87 |
steps: |
| 75 | 88 |
- |
| 76 | 89 |
name: Checkout |
| ... | ... |
@@ -89,9 +102,9 @@ jobs: |
| 89 | 89 |
name: Build |
| 90 | 90 |
uses: docker/bake-action@v2 |
| 91 | 91 |
with: |
| 92 |
- targets: cross |
|
| 93 |
- env: |
|
| 94 |
- DOCKER_CROSSPLATFORMS: ${{ matrix.platform }}
|
|
| 92 |
+ targets: binary |
|
| 93 |
+ set: | |
|
| 94 |
+ *.platform=${{ matrix.platform }}
|
|
| 95 | 95 |
- |
| 96 | 96 |
name: Upload artifacts |
| 97 | 97 |
uses: actions/upload-artifact@v3 |
| ... | ... |
@@ -8,7 +8,6 @@ ARG XX_VERSION=1.1.2 |
| 8 | 8 |
ARG VPNKIT_VERSION=0.5.0 |
| 9 | 9 |
ARG DOCKERCLI_VERSION=v17.06.2-ce |
| 10 | 10 |
|
| 11 |
-ARG CROSS="false" |
|
| 12 | 11 |
ARG SYSTEMD="false" |
| 13 | 12 |
ARG DEBIAN_FRONTEND=noninteractive |
| 14 | 13 |
ARG DOCKER_STATIC=1 |
| ... | ... |
@@ -128,60 +127,6 @@ RUN /download-frozen-image-v2.sh /build \ |
| 128 | 128 |
hello-world:latest@sha256:d58e752213a51785838f9eed2b7a498ffa1cb3aa7f946dda11af39286c3db9a9 \ |
| 129 | 129 |
arm32v7/hello-world:latest@sha256:50b8560ad574c779908da71f7ce370c0a2471c098d44d1c8f6b513c5a55eeeb1 |
| 130 | 130 |
|
| 131 |
-FROM base AS cross-false |
|
| 132 |
- |
|
| 133 |
-FROM --platform=linux/amd64 base AS cross-true |
|
| 134 |
-ARG DEBIAN_FRONTEND |
|
| 135 |
-RUN dpkg --add-architecture arm64 |
|
| 136 |
-RUN dpkg --add-architecture armel |
|
| 137 |
-RUN dpkg --add-architecture armhf |
|
| 138 |
-RUN dpkg --add-architecture ppc64el |
|
| 139 |
-RUN dpkg --add-architecture s390x |
|
| 140 |
-RUN --mount=type=cache,sharing=locked,id=moby-cross-true-aptlib,target=/var/lib/apt \ |
|
| 141 |
- --mount=type=cache,sharing=locked,id=moby-cross-true-aptcache,target=/var/cache/apt \ |
|
| 142 |
- apt-get update && apt-get install -y --no-install-recommends \ |
|
| 143 |
- crossbuild-essential-arm64 \ |
|
| 144 |
- crossbuild-essential-armel \ |
|
| 145 |
- crossbuild-essential-armhf \ |
|
| 146 |
- crossbuild-essential-ppc64el \ |
|
| 147 |
- crossbuild-essential-s390x |
|
| 148 |
- |
|
| 149 |
-FROM cross-${CROSS} AS dev-base
|
|
| 150 |
- |
|
| 151 |
-FROM dev-base AS runtime-dev-cross-false |
|
| 152 |
-ARG DEBIAN_FRONTEND |
|
| 153 |
-RUN --mount=type=cache,sharing=locked,id=moby-cross-false-aptlib,target=/var/lib/apt \ |
|
| 154 |
- --mount=type=cache,sharing=locked,id=moby-cross-false-aptcache,target=/var/cache/apt \ |
|
| 155 |
- apt-get update && apt-get install -y --no-install-recommends \ |
|
| 156 |
- binutils-mingw-w64 \ |
|
| 157 |
- g++-mingw-w64-x86-64 \ |
|
| 158 |
- libapparmor-dev \ |
|
| 159 |
- libbtrfs-dev \ |
|
| 160 |
- libdevmapper-dev \ |
|
| 161 |
- libseccomp-dev \ |
|
| 162 |
- libsystemd-dev \ |
|
| 163 |
- libudev-dev |
|
| 164 |
- |
|
| 165 |
-FROM --platform=linux/amd64 runtime-dev-cross-false AS runtime-dev-cross-true |
|
| 166 |
-ARG DEBIAN_FRONTEND |
|
| 167 |
-# These crossbuild packages rely on gcc-<arch>, but this doesn't want to install |
|
| 168 |
-# on non-amd64 systems, so other architectures cannot crossbuild amd64. |
|
| 169 |
-RUN --mount=type=cache,sharing=locked,id=moby-cross-true-aptlib,target=/var/lib/apt \ |
|
| 170 |
- --mount=type=cache,sharing=locked,id=moby-cross-true-aptcache,target=/var/cache/apt \ |
|
| 171 |
- apt-get update && apt-get install -y --no-install-recommends \ |
|
| 172 |
- libapparmor-dev:arm64 \ |
|
| 173 |
- libapparmor-dev:armel \ |
|
| 174 |
- libapparmor-dev:armhf \ |
|
| 175 |
- libapparmor-dev:ppc64el \ |
|
| 176 |
- libapparmor-dev:s390x \ |
|
| 177 |
- libseccomp-dev:arm64 \ |
|
| 178 |
- libseccomp-dev:armel \ |
|
| 179 |
- libseccomp-dev:armhf \ |
|
| 180 |
- libseccomp-dev:ppc64el \ |
|
| 181 |
- libseccomp-dev:s390x |
|
| 182 |
- |
|
| 183 |
-FROM runtime-dev-cross-${CROSS} AS runtime-dev
|
|
| 184 |
- |
|
| 185 | 131 |
# delve |
| 186 | 132 |
FROM base AS delve-src |
| 187 | 133 |
WORKDIR /usr/src/delve |
| ... | ... |
@@ -494,8 +439,44 @@ FROM containerutil-build AS containerutil-windows-amd64 |
| 494 | 494 |
FROM containerutil-windows-${TARGETARCH} AS containerutil-windows
|
| 495 | 495 |
FROM containerutil-${TARGETOS} AS containerutil
|
| 496 | 496 |
|
| 497 |
-# TODO: Some of this is only really needed for testing, it would be nice to split this up |
|
| 498 |
-FROM runtime-dev AS dev-systemd-false |
|
| 497 |
+FROM base AS dev-systemd-false |
|
| 498 |
+COPY --from=dockercli /build/ /usr/local/cli |
|
| 499 |
+COPY --from=frozen-images /build/ /docker-frozen-images |
|
| 500 |
+COPY --from=swagger /build/ /usr/local/bin/ |
|
| 501 |
+COPY --from=delve /build/ /usr/local/bin/ |
|
| 502 |
+COPY --from=tomll /build/ /usr/local/bin/ |
|
| 503 |
+COPY --from=gowinres /build/ /usr/local/bin/ |
|
| 504 |
+COPY --from=tini /build/ /usr/local/bin/ |
|
| 505 |
+COPY --from=registry /build/ /usr/local/bin/ |
|
| 506 |
+COPY --from=criu /build/ /usr/local/bin/ |
|
| 507 |
+COPY --from=gotestsum /build/ /usr/local/bin/ |
|
| 508 |
+COPY --from=golangci_lint /build/ /usr/local/bin/ |
|
| 509 |
+COPY --from=shfmt /build/ /usr/local/bin/ |
|
| 510 |
+COPY --from=runc /build/ /usr/local/bin/ |
|
| 511 |
+COPY --from=containerd /build/ /usr/local/bin/ |
|
| 512 |
+COPY --from=rootlesskit /build/ /usr/local/bin/ |
|
| 513 |
+COPY --from=vpnkit / /usr/local/bin/ |
|
| 514 |
+COPY --from=containerutil /build/ /usr/local/bin/ |
|
| 515 |
+COPY --from=crun /build/ /usr/local/bin/ |
|
| 516 |
+COPY hack/dockerfile/etc/docker/ /etc/docker/ |
|
| 517 |
+ENV PATH=/usr/local/cli:$PATH |
|
| 518 |
+WORKDIR /go/src/github.com/docker/docker |
|
| 519 |
+VOLUME /var/lib/docker |
|
| 520 |
+VOLUME /home/unprivilegeduser/.local/share/docker |
|
| 521 |
+# Wrap all commands in the "docker-in-docker" script to allow nested containers |
|
| 522 |
+ENTRYPOINT ["hack/dind"] |
|
| 523 |
+ |
|
| 524 |
+FROM dev-systemd-false AS dev-systemd-true |
|
| 525 |
+RUN --mount=type=cache,sharing=locked,id=moby-dev-aptlib,target=/var/lib/apt \ |
|
| 526 |
+ --mount=type=cache,sharing=locked,id=moby-dev-aptcache,target=/var/cache/apt \ |
|
| 527 |
+ apt-get update && apt-get install -y --no-install-recommends \ |
|
| 528 |
+ dbus \ |
|
| 529 |
+ dbus-user-session \ |
|
| 530 |
+ systemd \ |
|
| 531 |
+ systemd-sysv |
|
| 532 |
+ENTRYPOINT ["hack/dind-systemd"] |
|
| 533 |
+ |
|
| 534 |
+FROM dev-systemd-${SYSTEMD} AS dev
|
|
| 499 | 535 |
ARG DEBIAN_FRONTEND |
| 500 | 536 |
RUN groupadd -r docker |
| 501 | 537 |
RUN useradd --create-home --gid docker unprivilegeduser \ |
| ... | ... |
@@ -540,115 +521,84 @@ RUN --mount=type=cache,sharing=locked,id=moby-dev-aptlib,target=/var/lib/apt \ |
| 540 | 540 |
xz-utils \ |
| 541 | 541 |
zip \ |
| 542 | 542 |
zstd |
| 543 |
- |
|
| 544 |
- |
|
| 545 | 543 |
# Switch to use iptables instead of nftables (to match the CI hosts) |
| 546 | 544 |
# TODO use some kind of runtime auto-detection instead if/when nftables is supported (https://github.com/moby/moby/issues/26824) |
| 547 | 545 |
RUN update-alternatives --set iptables /usr/sbin/iptables-legacy || true \ |
| 548 | 546 |
&& update-alternatives --set ip6tables /usr/sbin/ip6tables-legacy || true \ |
| 549 | 547 |
&& update-alternatives --set arptables /usr/sbin/arptables-legacy || true |
| 550 |
- |
|
| 551 | 548 |
ARG YAMLLINT_VERSION=1.27.1 |
| 552 | 549 |
RUN pip3 install yamllint==${YAMLLINT_VERSION}
|
| 553 |
- |
|
| 554 |
-COPY --from=dockercli /build/ /usr/local/cli |
|
| 555 |
-COPY --from=frozen-images /build/ /docker-frozen-images |
|
| 556 |
-COPY --from=swagger /build/ /usr/local/bin/ |
|
| 557 |
-COPY --from=delve /build/ /usr/local/bin/ |
|
| 558 |
-COPY --from=tomll /build/ /usr/local/bin/ |
|
| 559 |
-COPY --from=gowinres /build/ /usr/local/bin/ |
|
| 560 |
-COPY --from=tini /build/ /usr/local/bin/ |
|
| 561 |
-COPY --from=registry /build/ /usr/local/bin/ |
|
| 562 |
-COPY --from=criu /build/ /usr/local/bin/ |
|
| 563 |
-COPY --from=gotestsum /build/ /usr/local/bin/ |
|
| 564 |
-COPY --from=golangci_lint /build/ /usr/local/bin/ |
|
| 565 |
-COPY --from=shfmt /build/ /usr/local/bin/ |
|
| 566 |
-COPY --from=runc /build/ /usr/local/bin/ |
|
| 567 |
-COPY --from=containerd /build/ /usr/local/bin/ |
|
| 568 |
-COPY --from=rootlesskit /build/ /usr/local/bin/ |
|
| 569 |
-COPY --from=vpnkit / /usr/local/bin/ |
|
| 570 |
-COPY --from=containerutil /build/ /usr/local/bin/ |
|
| 571 |
-COPY --from=crun /build/ /usr/local/bin/ |
|
| 572 |
-COPY hack/dockerfile/etc/docker/ /etc/docker/ |
|
| 573 |
-ENV PATH=/usr/local/cli:$PATH |
|
| 574 |
-ARG DOCKER_BUILDTAGS |
|
| 575 |
-ENV DOCKER_BUILDTAGS="${DOCKER_BUILDTAGS}"
|
|
| 576 |
-WORKDIR /go/src/github.com/docker/docker |
|
| 577 |
-VOLUME /var/lib/docker |
|
| 578 |
-VOLUME /home/unprivilegeduser/.local/share/docker |
|
| 579 |
-# Wrap all commands in the "docker-in-docker" script to allow nested containers |
|
| 580 |
-ENTRYPOINT ["hack/dind"] |
|
| 581 |
- |
|
| 582 |
-FROM dev-systemd-false AS dev-systemd-true |
|
| 583 | 550 |
RUN --mount=type=cache,sharing=locked,id=moby-dev-aptlib,target=/var/lib/apt \ |
| 584 | 551 |
--mount=type=cache,sharing=locked,id=moby-dev-aptcache,target=/var/cache/apt \ |
| 585 |
- apt-get update && apt-get install -y --no-install-recommends \ |
|
| 586 |
- dbus \ |
|
| 587 |
- dbus-user-session \ |
|
| 588 |
- systemd \ |
|
| 589 |
- systemd-sysv |
|
| 590 |
-ENTRYPOINT ["hack/dind-systemd"] |
|
| 591 |
- |
|
| 592 |
-FROM dev-systemd-${SYSTEMD} AS dev
|
|
| 552 |
+ apt-get update && apt-get install --no-install-recommends -y \ |
|
| 553 |
+ gcc \ |
|
| 554 |
+ pkg-config \ |
|
| 555 |
+ dpkg-dev \ |
|
| 556 |
+ libapparmor-dev \ |
|
| 557 |
+ libbtrfs-dev \ |
|
| 558 |
+ libdevmapper-dev \ |
|
| 559 |
+ libseccomp-dev \ |
|
| 560 |
+ libsecret-1-dev \ |
|
| 561 |
+ libsystemd-dev \ |
|
| 562 |
+ libudev-dev |
|
| 593 | 563 |
|
| 594 |
-FROM runtime-dev AS binary-base |
|
| 564 |
+FROM base AS build |
|
| 565 |
+COPY --from=gowinres /build/ /usr/local/bin/ |
|
| 566 |
+WORKDIR /go/src/github.com/docker/docker |
|
| 567 |
+ENV GO111MODULE=off |
|
| 568 |
+ENV CGO_ENABLED=1 |
|
| 569 |
+ARG DEBIAN_FRONTEND |
|
| 570 |
+ARG TARGETPLATFORM |
|
| 571 |
+RUN --mount=type=cache,sharing=locked,id=moby-build-aptlib,target=/var/lib/apt \ |
|
| 572 |
+ --mount=type=cache,sharing=locked,id=moby-build-aptcache,target=/var/cache/apt \ |
|
| 573 |
+ xx-apt-get install --no-install-recommends -y \ |
|
| 574 |
+ gcc \ |
|
| 575 |
+ libapparmor-dev \ |
|
| 576 |
+ libbtrfs-dev \ |
|
| 577 |
+ libc6-dev \ |
|
| 578 |
+ libdevmapper-dev \ |
|
| 579 |
+ libseccomp-dev \ |
|
| 580 |
+ libsecret-1-dev \ |
|
| 581 |
+ libsystemd-dev \ |
|
| 582 |
+ libudev-dev |
|
| 583 |
+ARG DOCKER_BUILDTAGS |
|
| 584 |
+ARG DOCKER_DEBUG |
|
| 595 | 585 |
ARG DOCKER_GITCOMMIT=HEAD |
| 596 |
-ENV DOCKER_GITCOMMIT=${DOCKER_GITCOMMIT}
|
|
| 586 |
+ARG DOCKER_LDFLAGS |
|
| 587 |
+ARG DOCKER_STATIC |
|
| 597 | 588 |
ARG VERSION |
| 598 |
-ENV VERSION=${VERSION}
|
|
| 599 | 589 |
ARG PLATFORM |
| 600 |
-ENV PLATFORM=${PLATFORM}
|
|
| 601 | 590 |
ARG PRODUCT |
| 602 |
-ENV PRODUCT=${PRODUCT}
|
|
| 603 | 591 |
ARG DEFAULT_PRODUCT_LICENSE |
| 604 |
-ENV DEFAULT_PRODUCT_LICENSE=${DEFAULT_PRODUCT_LICENSE}
|
|
| 605 | 592 |
ARG PACKAGER_NAME |
| 606 |
-ENV PACKAGER_NAME=${PACKAGER_NAME}
|
|
| 607 |
-ARG DOCKER_BUILDTAGS |
|
| 608 |
-ENV DOCKER_BUILDTAGS="${DOCKER_BUILDTAGS}"
|
|
| 609 |
-ENV PREFIX=/build |
|
| 610 |
-# TODO: This is here because hack/make.sh binary copies these extras binaries |
|
| 611 |
-# from $PATH into the bundles dir. |
|
| 612 |
-# It would be nice to handle this in a different way. |
|
| 613 |
-COPY --from=tini /build/ /usr/local/bin/ |
|
| 614 |
-COPY --from=runc /build/ /usr/local/bin/ |
|
| 615 |
-COPY --from=containerd /build/ /usr/local/bin/ |
|
| 616 |
-COPY --from=rootlesskit /build/ /usr/local/bin/ |
|
| 617 |
-COPY --from=vpnkit / /usr/local/bin/ |
|
| 618 |
-COPY --from=containerutil /build/ /usr/local/bin/ |
|
| 619 |
-COPY --from=gowinres /build/ /usr/local/bin/ |
|
| 620 |
-WORKDIR /go/src/github.com/docker/docker |
|
| 621 |
- |
|
| 622 |
-FROM binary-base AS build-binary |
|
| 623 |
-RUN --mount=type=cache,target=/root/.cache \ |
|
| 624 |
- --mount=type=bind,target=.,ro \ |
|
| 625 |
- --mount=type=tmpfs,target=cli/winresources/dockerd \ |
|
| 626 |
- --mount=type=tmpfs,target=cli/winresources/docker-proxy \ |
|
| 627 |
- hack/make.sh binary |
|
| 628 |
- |
|
| 629 |
-FROM binary-base AS build-dynbinary |
|
| 630 |
-RUN --mount=type=cache,target=/root/.cache \ |
|
| 631 |
- --mount=type=bind,target=.,ro \ |
|
| 632 |
- --mount=type=tmpfs,target=cli/winresources/dockerd \ |
|
| 633 |
- --mount=type=tmpfs,target=cli/winresources/docker-proxy \ |
|
| 634 |
- hack/make.sh dynbinary |
|
| 635 |
- |
|
| 636 |
-FROM binary-base AS build-cross |
|
| 637 |
-ARG DOCKER_CROSSPLATFORMS |
|
| 638 |
-RUN --mount=type=cache,target=/root/.cache \ |
|
| 639 |
- --mount=type=bind,target=.,ro \ |
|
| 593 |
+# PREFIX overrides DEST dir in make.sh script otherwise it fails because of |
|
| 594 |
+# read only mount in current work dir |
|
| 595 |
+ENV PREFIX=/tmp |
|
| 596 |
+RUN --mount=type=bind,target=. \ |
|
| 640 | 597 |
--mount=type=tmpfs,target=cli/winresources/dockerd \ |
| 641 | 598 |
--mount=type=tmpfs,target=cli/winresources/docker-proxy \ |
| 642 |
- hack/make.sh cross |
|
| 599 |
+ --mount=type=cache,target=/root/.cache/go-build,id=moby-build-$TARGETPLATFORM <<EOT |
|
| 600 |
+ set -e |
|
| 601 |
+ target=$([ "$DOCKER_STATIC" = "1" ] && echo "binary" || echo "dynbinary") |
|
| 602 |
+ xx-go --wrap |
|
| 603 |
+ ./hack/make.sh $target |
|
| 604 |
+ xx-verify /tmp/bundles/${target}-daemon/dockerd$([ "$(xx-info os)" = "windows" ] && echo ".exe")
|
|
| 605 |
+ xx-verify /tmp/bundles/${target}-daemon/docker-proxy$([ "$(xx-info os)" = "windows" ] && echo ".exe")
|
|
| 606 |
+ mkdir /build |
|
| 607 |
+ mv /tmp/bundles/${target}-daemon/* /build/
|
|
| 608 |
+EOT |
|
| 643 | 609 |
|
| 610 |
+# usage: |
|
| 611 |
+# > docker buildx bake binary |
|
| 612 |
+# > DOCKER_STATIC=0 docker buildx bake binary |
|
| 613 |
+# or |
|
| 614 |
+# > make binary |
|
| 615 |
+# > make dynbinary |
|
| 644 | 616 |
FROM scratch AS binary |
| 645 |
-COPY --from=build-binary /build/bundles/ / |
|
| 646 |
- |
|
| 647 |
-FROM scratch AS dynbinary |
|
| 648 |
-COPY --from=build-dynbinary /build/bundles/ / |
|
| 649 |
- |
|
| 650 |
-FROM scratch AS cross |
|
| 651 |
-COPY --from=build-cross /build/bundles/ / |
|
| 617 |
+COPY --from=build /build/ / |
|
| 652 | 618 |
|
| 619 |
+# usage: |
|
| 620 |
+# > make shell |
|
| 621 |
+# > SYSTEMD=true make shell |
|
| 653 | 622 |
FROM dev AS final |
| 654 |
-COPY . /go/src/github.com/docker/docker |
|
| 623 |
+COPY . . |
| ... | ... |
@@ -31,7 +31,6 @@ export VALIDATE_ORIGIN_BRANCH |
| 31 | 31 |
# make DOCKER_LDFLAGS="-X github.com/docker/docker/daemon/graphdriver.priority=overlay2,devicemapper" dynbinary |
| 32 | 32 |
# |
| 33 | 33 |
DOCKER_ENVS := \ |
| 34 |
- -e DOCKER_CROSSPLATFORMS \ |
|
| 35 | 34 |
-e BUILD_APT_MIRROR \ |
| 36 | 35 |
-e BUILDFLAGS \ |
| 37 | 36 |
-e KEEPBUNDLE \ |
| ... | ... |
@@ -143,17 +142,7 @@ endif |
| 143 | 143 |
|
| 144 | 144 |
BUILD_OPTS := ${BUILD_APT_MIRROR} ${DOCKER_BUILD_ARGS} ${DOCKER_BUILD_OPTS} -f "$(DOCKERFILE)"
|
| 145 | 145 |
BUILD_CMD := $(BUILDX) build |
| 146 |
- |
|
| 147 |
-# This is used for the legacy "build" target and anything still depending on it |
|
| 148 |
-BUILD_CROSS = |
|
| 149 |
-ifdef DOCKER_CROSS |
|
| 150 |
-BUILD_CROSS = --build-arg CROSS=$(DOCKER_CROSS) |
|
| 151 |
-endif |
|
| 152 |
-ifdef DOCKER_CROSSPLATFORMS |
|
| 153 |
-BUILD_CROSS = --build-arg CROSS=true |
|
| 154 |
-endif |
|
| 155 |
- |
|
| 156 |
-VERSION_AUTOGEN_ARGS = --build-arg VERSION --build-arg DOCKER_GITCOMMIT --build-arg PRODUCT --build-arg PLATFORM --build-arg DEFAULT_PRODUCT_LICENSE --build-arg PACKAGER_NAME |
|
| 146 |
+BAKE_CMD := $(BUILDX) bake |
|
| 157 | 147 |
|
| 158 | 148 |
default: binary |
| 159 | 149 |
|
| ... | ... |
@@ -161,14 +150,13 @@ all: build ## validate all checks, build linux binaries, run all tests,\ncross b |
| 161 | 161 |
$(DOCKER_RUN_DOCKER) bash -c 'hack/validate/default && hack/make.sh' |
| 162 | 162 |
|
| 163 | 163 |
binary: bundles ## build statically linked linux binaries |
| 164 |
- $(BUILD_CMD) $(BUILD_OPTS) --output=bundles/ --target=$@ $(VERSION_AUTOGEN_ARGS) . |
|
| 164 |
+ $(BAKE_CMD) binary |
|
| 165 | 165 |
|
| 166 | 166 |
dynbinary: bundles ## build dynamically linked linux binaries |
| 167 |
- $(BUILD_CMD) $(BUILD_OPTS) --output=bundles/ --target=$@ $(VERSION_AUTOGEN_ARGS) . |
|
| 167 |
+ $(BAKE_CMD) dynbinary |
|
| 168 | 168 |
|
| 169 |
-cross: BUILD_OPTS += --build-arg CROSS=true --build-arg DOCKER_CROSSPLATFORMS |
|
| 170 |
-cross: bundles ## cross build the binaries for darwin, freebsd and\nwindows |
|
| 171 |
- $(BUILD_CMD) $(BUILD_OPTS) --output=bundles/ --target=$@ $(VERSION_AUTOGEN_ARGS) . |
|
| 169 |
+cross: bundles ## cross build the binaries |
|
| 170 |
+ $(BAKE_CMD) binary-cross |
|
| 172 | 171 |
|
| 173 | 172 |
bundles: |
| 174 | 173 |
mkdir bundles |
| ... | ... |
@@ -196,13 +184,13 @@ else |
| 196 | 196 |
build: shell_target := --target=final |
| 197 | 197 |
endif |
| 198 | 198 |
build: bundles |
| 199 |
- $(BUILD_CMD) $(BUILD_OPTS) $(shell_target) --load $(BUILD_CROSS) -t "$(DOCKER_IMAGE)" . |
|
| 199 |
+ $(BUILD_CMD) $(BUILD_OPTS) $(shell_target) --load -t "$(DOCKER_IMAGE)" . |
|
| 200 | 200 |
|
| 201 | 201 |
shell: build ## start a shell inside the build env |
| 202 | 202 |
$(DOCKER_RUN_DOCKER) bash |
| 203 | 203 |
|
| 204 | 204 |
test: build test-unit ## run the unit, integration and docker-py tests |
| 205 |
- $(DOCKER_RUN_DOCKER) hack/make.sh dynbinary cross test-integration test-docker-py |
|
| 205 |
+ $(DOCKER_RUN_DOCKER) hack/make.sh dynbinary test-integration test-docker-py |
|
| 206 | 206 |
|
| 207 | 207 |
test-docker-py: build ## run the docker-py tests |
| 208 | 208 |
$(DOCKER_RUN_DOCKER) hack/make.sh dynbinary test-docker-py |
| ... | ... |
@@ -229,8 +217,8 @@ validate: build ## validate DCO, Seccomp profile generation, gofmt,\n./pkg/ isol |
| 229 | 229 |
validate-%: build ## validate specific check |
| 230 | 230 |
$(DOCKER_RUN_DOCKER) hack/validate/$* |
| 231 | 231 |
|
| 232 |
-win: build ## cross build the binary for windows |
|
| 233 |
- $(DOCKER_RUN_DOCKER) DOCKER_CROSSPLATFORMS=windows/amd64 hack/make.sh cross |
|
| 232 |
+win: bundles ## cross build the binary for windows |
|
| 233 |
+ $(BAKE_CMD) --set *.platform=windows/amd64 binary |
|
| 234 | 234 |
|
| 235 | 235 |
.PHONY: swagger-gen |
| 236 | 236 |
swagger-gen: |
| ... | ... |
@@ -4,9 +4,6 @@ variable "BUNDLES_OUTPUT" {
|
| 4 | 4 |
variable "DOCKER_STATIC" {
|
| 5 | 5 |
default = "1" |
| 6 | 6 |
} |
| 7 |
-variable "DOCKER_CROSSPLATFORMS" {
|
|
| 8 |
- default = "" |
|
| 9 |
-} |
|
| 10 | 7 |
|
| 11 | 8 |
target "_common" {
|
| 12 | 9 |
args = {
|
| ... | ... |
@@ -20,6 +17,23 @@ group "default" {
|
| 20 | 20 |
targets = ["binary"] |
| 21 | 21 |
} |
| 22 | 22 |
|
| 23 |
+target "_platforms" {
|
|
| 24 |
+ platforms = [ |
|
| 25 |
+ "linux/amd64", |
|
| 26 |
+ "linux/arm/v5", |
|
| 27 |
+ "linux/arm/v6", |
|
| 28 |
+ "linux/arm/v7", |
|
| 29 |
+ "linux/arm64", |
|
| 30 |
+ "linux/ppc64le", |
|
| 31 |
+ "linux/s390x", |
|
| 32 |
+ "windows/amd64" |
|
| 33 |
+ ] |
|
| 34 |
+} |
|
| 35 |
+ |
|
| 36 |
+# |
|
| 37 |
+# build dockerd and docker-proxy |
|
| 38 |
+# |
|
| 39 |
+ |
|
| 23 | 40 |
target "binary" {
|
| 24 | 41 |
inherits = ["_common"] |
| 25 | 42 |
target = "binary" |
| ... | ... |
@@ -28,16 +42,13 @@ target "binary" {
|
| 28 | 28 |
|
| 29 | 29 |
target "dynbinary" {
|
| 30 | 30 |
inherits = ["binary"] |
| 31 |
- target = "dynbinary" |
|
| 32 |
-} |
|
| 33 |
- |
|
| 34 |
-target "cross" {
|
|
| 35 |
- inherits = ["binary"] |
|
| 36 | 31 |
args = {
|
| 37 |
- CROSS = "true" |
|
| 38 |
- DOCKER_CROSSPLATFORMS = DOCKER_CROSSPLATFORMS |
|
| 32 |
+ DOCKER_STATIC = "0" |
|
| 39 | 33 |
} |
| 40 |
- target = "cross" |
|
| 34 |
+} |
|
| 35 |
+ |
|
| 36 |
+target "binary-cross" {
|
|
| 37 |
+ inherits = ["binary", "_platforms"] |
|
| 41 | 38 |
} |
| 42 | 39 |
|
| 43 | 40 |
# |
| ... | ... |
@@ -150,10 +150,10 @@ can take over 15 minutes to complete. |
| 150 | 150 |
Removing bundles/ |
| 151 | 151 |
|
| 152 | 152 |
---> Making bundle: binary (in bundles/binary) |
| 153 |
- Building: bundles/binary-daemon/dockerd-17.06.0-dev |
|
| 154 |
- Created binary: bundles/binary-daemon/dockerd-17.06.0-dev |
|
| 155 |
- Copying nested executables into bundles/binary-daemon |
|
| 156 |
- |
|
| 153 |
+ Building bundles/binary-daemon/dockerd (linux/amd64)... |
|
| 154 |
+ Created binary: bundles/binary-daemon/dockerd |
|
| 155 |
+ Building bundles/binary-daemon/docker-proxy (linux/amd64)... |
|
| 156 |
+ Created binary:bundles/binary-daemon/docker-proxy |
|
| 157 | 157 |
``` |
| 158 | 158 |
|
| 159 | 159 |
7. Run `make install`, which copies the binary to the container's |
| ... | ... |
@@ -123,7 +123,7 @@ Try this now. |
| 123 | 123 |
4. Run the tests using the `hack/make.sh` script. |
| 124 | 124 |
|
| 125 | 125 |
```bash |
| 126 |
- # hack/make.sh dynbinary binary cross test-integration test-docker-py |
|
| 126 |
+ # hack/make.sh dynbinary binary test-integration test-docker-py |
|
| 127 | 127 |
``` |
| 128 | 128 |
|
| 129 | 129 |
The tests run just as they did within your local host. |
| ... | ... |
@@ -132,11 +132,11 @@ Try this now. |
| 132 | 132 |
just the integration tests: |
| 133 | 133 |
|
| 134 | 134 |
```bash |
| 135 |
- # hack/make.sh dynbinary binary cross test-integration |
|
| 135 |
+ # hack/make.sh dynbinary binary test-integration |
|
| 136 | 136 |
``` |
| 137 | 137 |
|
| 138 | 138 |
Most test targets require that you build these precursor targets first: |
| 139 |
- `dynbinary binary cross` |
|
| 139 |
+ `dynbinary binary` |
|
| 140 | 140 |
|
| 141 | 141 |
|
| 142 | 142 |
## Run unit tests |
| ... | ... |
@@ -44,7 +44,7 @@ all of the tests. |
| 44 | 44 |
- When running inside a Docker development container, `hack/make.sh` does |
| 45 | 45 |
not have a single target that runs all the tests. You need to provide a |
| 46 | 46 |
single command line with multiple targets that performs the same thing. |
| 47 |
-An example referenced from [Run targets inside a development container](https://docs.docker.com/opensource/project/test-and-docs/#run-targets-inside-a-development-container): `root@5f8630b873fe:/go/src/github.com/moby/moby# hack/make.sh dynbinary binary cross test-unit test-integration test-docker-py` |
|
| 47 |
+An example referenced from [Run targets inside a development container](https://docs.docker.com/opensource/project/test-and-docs/#run-targets-inside-a-development-container): `root@5f8630b873fe:/go/src/github.com/moby/moby# hack/make.sh dynbinary binary test-unit test-integration test-docker-py` |
|
| 48 | 48 |
- For more information related to testing outside the scope of this README, |
| 49 | 49 |
refer to |
| 50 | 50 |
[Run tests and test documentation](https://docs.docker.com/opensource/project/test-and-docs/) |
| ... | ... |
@@ -16,56 +16,59 @@ source "${MAKEDIR}/.go-autogen"
|
| 16 | 16 |
( |
| 17 | 17 |
export GOGC=${DOCKER_BUILD_GOGC:-1000}
|
| 18 | 18 |
|
| 19 |
- if [ "$(go env GOOS)/$(go env GOARCH)" != "$(go env GOHOSTOS)/$(go env GOHOSTARCH)" ]; then |
|
| 20 |
- # must be cross-compiling! |
|
| 21 |
- case "$(go env GOOS)/$(go env GOARCH)" in |
|
| 22 |
- windows/amd64) |
|
| 23 |
- export CC="${CC:-x86_64-w64-mingw32-gcc}"
|
|
| 24 |
- export CGO_ENABLED=1 |
|
| 25 |
- ;; |
|
| 26 |
- linux/arm) |
|
| 27 |
- case "${GOARM}" in
|
|
| 28 |
- 5) |
|
| 29 |
- export CC="${CC:-arm-linux-gnueabi-gcc}"
|
|
| 30 |
- export CGO_ENABLED=1 |
|
| 31 |
- export CGO_CFLAGS="-march=armv5t" |
|
| 32 |
- export CGO_CXXFLAGS="-march=armv5t" |
|
| 33 |
- ;; |
|
| 34 |
- 6) |
|
| 35 |
- export CC="${CC:-arm-linux-gnueabi-gcc}"
|
|
| 36 |
- export CGO_ENABLED=1 |
|
| 37 |
- export CGO_CFLAGS="-march=armv6" |
|
| 38 |
- export CGO_CXXFLAGS="-march=armv6" |
|
| 39 |
- ;; |
|
| 40 |
- 7) |
|
| 41 |
- export CC="${CC:-arm-linux-gnueabihf-gcc}"
|
|
| 42 |
- export CGO_ENABLED=1 |
|
| 43 |
- export CGO_CFLAGS="-march=armv7-a" |
|
| 44 |
- export CGO_CXXFLAGS="-march=armv7-a" |
|
| 45 |
- ;; |
|
| 46 |
- *) |
|
| 47 |
- export CC="${CC:-arm-linux-gnueabihf-gcc}"
|
|
| 48 |
- export CGO_ENABLED=1 |
|
| 49 |
- ;; |
|
| 50 |
- esac |
|
| 51 |
- ;; |
|
| 52 |
- linux/arm64) |
|
| 53 |
- export CC="${CC:-aarch64-linux-gnu-gcc}"
|
|
| 54 |
- export CGO_ENABLED=1 |
|
| 55 |
- ;; |
|
| 56 |
- linux/amd64) |
|
| 57 |
- export CC="${CC:-x86_64-linux-gnu-gcc}"
|
|
| 58 |
- export CGO_ENABLED=1 |
|
| 59 |
- ;; |
|
| 60 |
- linux/ppc64le) |
|
| 61 |
- export CC="${CC:-powerpc64le-linux-gnu-gcc}"
|
|
| 62 |
- export CGO_ENABLED=1 |
|
| 63 |
- ;; |
|
| 64 |
- linux/s390x) |
|
| 65 |
- export CC="${CC:-s390x-linux-gnu-gcc}"
|
|
| 66 |
- export CGO_ENABLED=1 |
|
| 67 |
- ;; |
|
| 68 |
- esac |
|
| 19 |
+ # for non-sandboxed invocation |
|
| 20 |
+ if ! command -v xx-go > /dev/null 2>&1; then |
|
| 21 |
+ if [ "$(go env GOOS)/$(go env GOARCH)" != "$(go env GOHOSTOS)/$(go env GOHOSTARCH)" ]; then |
|
| 22 |
+ # must be cross-compiling! |
|
| 23 |
+ case "$(go env GOOS)/$(go env GOARCH)" in |
|
| 24 |
+ windows/amd64) |
|
| 25 |
+ export CC="${CC:-x86_64-w64-mingw32-gcc}"
|
|
| 26 |
+ export CGO_ENABLED=1 |
|
| 27 |
+ ;; |
|
| 28 |
+ linux/arm) |
|
| 29 |
+ case "${GOARM}" in
|
|
| 30 |
+ 5) |
|
| 31 |
+ export CC="${CC:-arm-linux-gnueabi-gcc}"
|
|
| 32 |
+ export CGO_ENABLED=1 |
|
| 33 |
+ export CGO_CFLAGS="-march=armv5t" |
|
| 34 |
+ export CGO_CXXFLAGS="-march=armv5t" |
|
| 35 |
+ ;; |
|
| 36 |
+ 6) |
|
| 37 |
+ export CC="${CC:-arm-linux-gnueabi-gcc}"
|
|
| 38 |
+ export CGO_ENABLED=1 |
|
| 39 |
+ export CGO_CFLAGS="-march=armv6" |
|
| 40 |
+ export CGO_CXXFLAGS="-march=armv6" |
|
| 41 |
+ ;; |
|
| 42 |
+ 7) |
|
| 43 |
+ export CC="${CC:-arm-linux-gnueabihf-gcc}"
|
|
| 44 |
+ export CGO_ENABLED=1 |
|
| 45 |
+ export CGO_CFLAGS="-march=armv7-a" |
|
| 46 |
+ export CGO_CXXFLAGS="-march=armv7-a" |
|
| 47 |
+ ;; |
|
| 48 |
+ *) |
|
| 49 |
+ export CC="${CC:-arm-linux-gnueabihf-gcc}"
|
|
| 50 |
+ export CGO_ENABLED=1 |
|
| 51 |
+ ;; |
|
| 52 |
+ esac |
|
| 53 |
+ ;; |
|
| 54 |
+ linux/arm64) |
|
| 55 |
+ export CC="${CC:-aarch64-linux-gnu-gcc}"
|
|
| 56 |
+ export CGO_ENABLED=1 |
|
| 57 |
+ ;; |
|
| 58 |
+ linux/amd64) |
|
| 59 |
+ export CC="${CC:-x86_64-linux-gnu-gcc}"
|
|
| 60 |
+ export CGO_ENABLED=1 |
|
| 61 |
+ ;; |
|
| 62 |
+ linux/ppc64le) |
|
| 63 |
+ export CC="${CC:-powerpc64le-linux-gnu-gcc}"
|
|
| 64 |
+ export CGO_ENABLED=1 |
|
| 65 |
+ ;; |
|
| 66 |
+ linux/s390x) |
|
| 67 |
+ export CC="${CC:-s390x-linux-gnu-gcc}"
|
|
| 68 |
+ export CGO_ENABLED=1 |
|
| 69 |
+ ;; |
|
| 70 |
+ esac |
|
| 71 |
+ fi |
|
| 69 | 72 |
fi |
| 70 | 73 |
|
| 71 | 74 |
# -buildmode=pie is not supported on Windows and Linux on mips, riscv64 and ppc64be. |
| ... | ... |
@@ -80,8 +83,18 @@ source "${MAKEDIR}/.go-autogen"
|
| 80 | 80 |
;; |
| 81 | 81 |
esac |
| 82 | 82 |
|
| 83 |
- echo "Building: $DEST/$BINARY_FULLNAME" |
|
| 84 |
- echo "GOOS=\"${GOOS}\" GOARCH=\"${GOARCH}\" GOARM=\"${GOARM}\""
|
|
| 83 |
+ # only necessary for non-sandboxed invocation where TARGETPLATFORM is empty |
|
| 84 |
+ PLATFORM_NAME=$TARGETPLATFORM |
|
| 85 |
+ if [ -z "$PLATFORM_NAME" ]; then |
|
| 86 |
+ PLATFORM_NAME="$(go env GOOS)/$(go env GOARCH)" |
|
| 87 |
+ if [ -n "$(go env GOARM)" ]; then |
|
| 88 |
+ PLATFORM_NAME+="/$(go env GOARM)" |
|
| 89 |
+ elif [ -n "$(go env GOAMD64)" ] && [ "$(go env GOAMD64)" != "v1" ]; then |
|
| 90 |
+ PLATFORM_NAME+="/$(go env GOAMD64)" |
|
| 91 |
+ fi |
|
| 92 |
+ fi |
|
| 93 |
+ |
|
| 94 |
+ echo "Building $DEST/$BINARY_FULLNAME ($PLATFORM_NAME)..." |
|
| 85 | 95 |
go build \ |
| 86 | 96 |
-o "$DEST/$BINARY_FULLNAME" \ |
| 87 | 97 |
"${BUILDFLAGS[@]}" \
|
| ... | ... |
@@ -1,35 +1,10 @@ |
| 1 | 1 |
#!/usr/bin/env bash |
| 2 | 2 |
set -e |
| 3 | 3 |
|
| 4 |
-copy_binaries() {
|
|
| 5 |
- local dir="$1" |
|
| 6 |
- |
|
| 7 |
- # Add nested executables to bundle dir so we have complete set of |
|
| 8 |
- # them available, but only if the native OS/ARCH is the same as the |
|
| 9 |
- # OS/ARCH of the build target |
|
| 10 |
- if [ "$(go env GOOS)/$(go env GOARCH)" != "$(go env GOHOSTOS)/$(go env GOHOSTARCH)" ]; then |
|
| 11 |
- return |
|
| 12 |
- fi |
|
| 13 |
- if [ ! -x /usr/local/bin/runc ]; then |
|
| 14 |
- return |
|
| 15 |
- fi |
|
| 16 |
- echo "Copying nested executables into $dir" |
|
| 17 |
- for file in containerd containerd-shim-runc-v2 ctr runc docker-init rootlesskit rootlesskit-docker-proxy dockerd-rootless.sh dockerd-rootless-setuptool.sh; do |
|
| 18 |
- cp -f "$(command -v "$file")" "$dir/" |
|
| 19 |
- done |
|
| 20 |
- # vpnkit might not be available for the target platform, see vpnkit stage in |
|
| 21 |
- # the Dockerfile for more information. |
|
| 22 |
- if command -v vpnkit > /dev/null 2>&1; then |
|
| 23 |
- cp -f "$(command -v vpnkit)" "$dir/" |
|
| 24 |
- fi |
|
| 25 |
-} |
|
| 26 |
- |
|
| 27 | 4 |
[ -z "$KEEPDEST" ] && rm -rf "$DEST" |
| 28 | 5 |
|
| 29 | 6 |
( |
| 30 | 7 |
GO_PACKAGE='github.com/docker/docker/cmd/dockerd' |
| 31 | 8 |
BINARY_NAME='dockerd' |
| 32 |
- |
|
| 33 | 9 |
source "${MAKEDIR}/.binary"
|
| 34 |
- copy_binaries "$DEST" |
|
| 35 | 10 |
) |
| 36 | 11 |
deleted file mode 100644 |
| ... | ... |
@@ -1,37 +0,0 @@ |
| 1 |
-#!/usr/bin/env bash |
|
| 2 |
-set -e |
|
| 3 |
- |
|
| 4 |
-# if we have our linux/amd64 version compiled, let's symlink it in |
|
| 5 |
-if [ -x "${DEST}/../binary-daemon/dockerd" ]; then
|
|
| 6 |
- arch=$(go env GOHOSTARCH) |
|
| 7 |
- mkdir -p "$DEST/linux/${arch}"
|
|
| 8 |
- ( |
|
| 9 |
- cd "${DEST}/linux/${arch}"
|
|
| 10 |
- ln -sf ../../../binary-daemon/* ./ |
|
| 11 |
- ) |
|
| 12 |
- echo "Created symlinks:" "${DEST}/linux/${arch}/"*
|
|
| 13 |
-fi |
|
| 14 |
- |
|
| 15 |
-DOCKER_CROSSPLATFORMS=${DOCKER_CROSSPLATFORMS:-"linux/amd64 windows/amd64 linux/ppc64le linux/s390x"}
|
|
| 16 |
- |
|
| 17 |
-for platform in ${DOCKER_CROSSPLATFORMS}; do
|
|
| 18 |
- ( |
|
| 19 |
- export KEEPDEST=1 |
|
| 20 |
- export DEST="${DEST}/${platform}" # bundles/VERSION/cross/GOOS/GOARCH/docker-VERSION
|
|
| 21 |
- export GOOS=${platform%%/*}
|
|
| 22 |
- export GOARCH=${platform#*/}
|
|
| 23 |
- |
|
| 24 |
- if [[ "${GOARCH}" = "arm/"* ]]; then
|
|
| 25 |
- GOARM=${GOARCH##*/v}
|
|
| 26 |
- GOARCH=${GOARCH%/v*}
|
|
| 27 |
- export GOARM |
|
| 28 |
- fi |
|
| 29 |
- |
|
| 30 |
- echo "Cross building: ${DEST}"
|
|
| 31 |
- mkdir -p "${DEST}"
|
|
| 32 |
- ABS_DEST="$(cd "${DEST}" && pwd -P)"
|
|
| 33 |
- source "${MAKEDIR}/binary"
|
|
| 34 |
- |
|
| 35 |
- source "${MAKEDIR}/cross-platform-dependent"
|
|
| 36 |
- ) |
|
| 37 |
-done |