# syntax=docker/dockerfile-upstream:master ARG RUNC_VERSION=v1.4.3 ARG CONTAINERD_VERSION=v2.3.3 # CONTAINERD_ALT_VERSION_... defines fallback containerd version for integration tests ARG CONTAINERD_ALT_VERSION_22=v2.2.6 ARG CONTAINERD_ALT_VERSION_17=v1.7.34 ARG REGISTRY_VERSION=v2.8.3 ARG ROOTLESSKIT_VERSION=v3.0.1 ARG CNI_VERSION=v1.9.1 ARG STARGZ_SNAPSHOTTER_VERSION=v0.18.2 ARG NERDCTL_VERSION=v2.3.1 ARG DNSNAME_VERSION=v1.3.1 ARG NYDUS_VERSION=v2.4.0 ARG MINIO_VERSION=RELEASE.2025-09-07T16-13-09Z ARG MINIO_MC_VERSION=RELEASE.2025-08-13T08-35-41Z ARG AZURITE_VERSION=3.35.0 ARG GOTESTSUM_VERSION=v1.13.0 ARG DELVE_VERSION=v1.26.3 ARG DOCKER_VERSION=29.6 ARG DOCKER_CLI_VERSION=${DOCKER_VERSION} ARG BUILDX_VERSION=0.34.1 ARG EXPORT_BASE=alpine ARG ALPINE_VERSION=3.23 ARG UBUNTU_VERSION=24.04 ARG GO_VERSION=1.26 ARG XX_VERSION=1.9.0 ARG BUILDKIT_DEBUG # minio for s3 integration tests FROM quay.io/minio/minio:${MINIO_VERSION} AS minio FROM quay.io/minio/mc:${MINIO_MC_VERSION} AS minio-mc # xx is a helper for cross-compilation FROM --platform=$BUILDPLATFORM tonistiigi/xx:${XX_VERSION} AS xx # golatest is alias for Go base image FROM --platform=$BUILDPLATFORM golang:${GO_VERSION}-alpine${ALPINE_VERSION} AS golatest FROM moby/moby-bin:$DOCKER_VERSION AS docker-engine FROM dockereng/cli-bin:$DOCKER_CLI_VERSION AS docker-cli FROM docker/buildx-bin:$BUILDX_VERSION AS docker-buildx # gobuild-base is base stage for compiling go/cgo FROM golatest AS gobuild-base RUN apk add --no-cache file bash clang lld musl-dev pkgconfig git make COPY --link --from=xx / / # runc builds runc binary FROM gobuild-base AS runc WORKDIR $GOPATH/src/github.com/opencontainers/runc ARG RUNC_VERSION ADD --keep-git-dir=true "https://github.com/opencontainers/runc.git#$RUNC_VERSION" . ARG TARGETPLATFORM # gcc is only installed for libgcc # lld has issues building static binaries for ppc so prefer ld for it RUN set -e; xx-apk add musl-dev gcc libseccomp-dev libseccomp-static; \ [ "$(xx-info arch)" != "ppc64le" ] || XX_CC_PREFER_LINKER=ld xx-clang --setup-target-triple RUN --mount=target=/root/.cache,type=cache <&2 "Skipping version check for worktree" # set dev stubs echo "-X github.com/moby/buildkit/version.Version=dev -X github.com/moby/buildkit/version.Revision=dev -X github.com/moby/buildkit/version.Package=github.com/moby/buildkit" > /tmp/.ldflags; echo -n "dev" > /tmp/.version; echo -n "$(date -u +%Y-%m-%dT%H:%M:%SZ)" > /tmp/.commit_date; exit 0 fi if ! git rev-parse HEAD 2>/dev/null; then echo >&2 "Failed to get git revision, make sure --build-arg BUILDKIT_CONTEXT_KEEP_GIT_DIR=1 is set when building from Git directly" exit 1 fi set -ex export PKG=github.com/moby/buildkit VERSION=$(git describe --match 'v[0-9]*' --dirty='.m' --always --tags) REVISION=$(git rev-parse HEAD)$(if ! git diff --no-ext-diff --quiet --exit-code; then echo .m; fi) COMMIT_DATE=$(git show -s --format=%cI HEAD); echo "-X ${PKG}/version.Version=${VERSION} -X ${PKG}/version.Revision=${REVISION} -X ${PKG}/version.Package=${PKG}" > /tmp/.ldflags; echo -n "${VERSION}" > /tmp/.version; echo -n "${COMMIT_DATE}" > /tmp/.commit_date; EOT # buildctl builds test cli binary FROM buildkit-base AS buildctl ENV CGO_ENABLED=0 ARG TARGETPLATFORM ARG GOBUILDFLAGS RUN --mount=target=. --mount=target=/root/.cache,type=cache \ --mount=target=/go/pkg/mod,type=cache \ --mount=source=/tmp/.ldflags,target=/tmp/.ldflags,from=buildkit-version </dev/null 2>&1; then mv bin/containerd-shim* /out fi fi EOT FROM containerd-build AS containerd WORKDIR /go/src/github.com/containerd/containerd ARG CONTAINERD_VERSION ADD --keep-git-dir=true "https://github.com/containerd/containerd.git#$CONTAINERD_VERSION" . RUN /build.sh # containerd-alt-22 builds containerd v2.2 for integration tests FROM containerd-build AS containerd-alt-22 WORKDIR /go/src/github.com/containerd/containerd ARG CONTAINERD_ALT_VERSION_22 ADD --keep-git-dir=true "https://github.com/containerd/containerd.git#$CONTAINERD_ALT_VERSION_22" . RUN /build.sh # containerd-alt-17 builds containerd v1.7 for integration tests FROM containerd-build AS containerd-alt-17 WORKDIR /go/src/github.com/containerd/containerd ARG CONTAINERD_ALT_VERSION_17 ADD --keep-git-dir=true "https://github.com/containerd/containerd.git#$CONTAINERD_ALT_VERSION_17" . RUN /build.sh FROM gobuild-base AS registry WORKDIR /go/src/github.com/docker/distribution ARG REGISTRY_VERSION ADD --keep-git-dir=true "https://github.com/distribution/distribution.git#$REGISTRY_VERSION" . ARG TARGETPLATFORM RUN --mount=target=/root/.cache,type=cache < "$coverdir/merged-report.txt" mv "$coverdir/merged-report.txt" "$GO_TEST_COVERPROFILE" rm "$coverdir/helpers-report.txt" for f in "$coverdir/helpers"/*; do rm "$f" done rmdir "$coverdir/helpers" exit $ecode EOF # dlv builds delve for debug variant images FROM gobuild-base AS dlv ARG DELVE_VERSION ARG TARGETPLATFORM RUN --mount=target=/root/.cache,type=cache\ --mount=target=/go/pkg/mod,type=cache <> /home/user/.profile \ && mkdir -m 0700 -p /run/user/1000 \ && chown -R user /run/user/1000 /home/user \ && ln -s /sbin/iptables-legacy /usr/bin/iptables \ && xx-go --wrap ARG NERDCTL_VERSION RUN curl -fsSL https://raw.githubusercontent.com/containerd/nerdctl/$NERDCTL_VERSION/extras/rootless/containerd-rootless.sh > /usr/bin/containerd-rootless.sh \ && chmod 0755 /usr/bin/containerd-rootless.sh ARG AZURITE_VERSION RUN apk add --no-cache nodejs npm \ && npm install -g azurite@${AZURITE_VERSION} # The entrypoint script is needed for enabling nested cgroup v2 (https://github.com/moby/buildkit/issues/3265#issuecomment-1309631736) RUN curl -fsSL https://raw.githubusercontent.com/moby/moby/v25.0.1/hack/dind > /docker-entrypoint.sh \ && chmod 0755 /docker-entrypoint.sh ENTRYPOINT ["/docker-entrypoint.sh"] # musl is needed to directly use the registry binary that is built on alpine ENV BUILDKIT_INTEGRATION_CONTAINERD_EXTRA="containerd-2.2=/opt/containerd-alt-22/bin,containerd-1.7=/opt/containerd-alt-17/bin" ENV BUILDKIT_INTEGRATION_SNAPSHOTTER=stargz ENV BUILDKIT_SETUP_CGROUPV2_ROOT=1 ENV BUILDKIT_TEST_SIGN_FIXTURES=/tmp/buildkit_test_sign_fixtures RUN --mount=target=/tmp/gen_gpg_test_env.sh,source=hack/fixtures/gen_gpg_test_env.sh sh /tmp/gen_gpg_test_env.sh user1 && sh /tmp/gen_gpg_test_env.sh user2 RUN --mount=target=/tmp/gen_ssh_test_env.sh,source=hack/fixtures/gen_ssh_test_env.sh sh /tmp/gen_ssh_test_env.sh user1 && sh /tmp/gen_ssh_test_env.sh user2 ENV CGO_ENABLED=0 ENV GOTESTSUM_FORMAT=standard-verbose COPY --link --from=docker-engine / /usr/bin/ RUN rm -f /usr/bin/vpnkit COPY --link --from=gotestsum /out /usr/bin/ COPY --link --from=minio /usr/bin/minio /usr/bin/ COPY --link --from=minio-mc /usr/bin/mc /usr/bin/ COPY --link --from=nydus /out/nydus-static/* /usr/bin/ COPY --link --from=stargz-snapshotter /out/* /usr/bin/ COPY --link --from=rootlesskit /rootlesskit /usr/bin/ COPY --link --from=containerd-alt-22 /out/containerd* /opt/containerd-alt-22/bin/ COPY --link --from=containerd-alt-17 /out/containerd* /opt/containerd-alt-17/bin/ COPY --link --from=registry /out /usr/bin/ COPY --link --from=runc /usr/bin/runc /usr/bin/ COPY --link --from=containerd /out/containerd* /usr/bin/ COPY --link --from=docker-cli / /usr/bin/ COPY --link --from=docker-buildx /buildx /usr/libexec/docker/cli-plugins/docker-buildx COPY --link --from=cni-plugins /opt/cni/bin/bridge /opt/cni/bin/host-local /opt/cni/bin/loopback /opt/cni/bin/firewall /opt/cni/bin/dnsname /opt/cni/bin/ COPY --link hack/fixtures/cni.json /etc/buildkit/cni.json COPY --link hack/fixtures/dns-cni.conflist /etc/buildkit/dns-cni.conflist COPY --link --from=binaries / /usr/bin/ # integration-tests prepares an image suitable for running all tests FROM integration-tests-base AS integration-tests COPY . . ENV BUILDKIT_RUN_NETWORK_INTEGRATION_TESTS=1 BUILDKIT_CNI_INIT_LOCK_PATH=/run/buildkit_cni_bridge.lock FROM integration-tests AS dev-env VOLUME /var/lib/buildkit # rootless builds a rootless variant of buildkitd image FROM alpine:${ALPINE_VERSION} AS rootless RUN apk add --no-cache fuse3 fuse-overlayfs git openssh openssl pigz shadow-uidmap xz RUN adduser -D -u 1000 user \ && mkdir -p /run/user/1000 /home/user/.local/tmp /home/user/.local/share/buildkit \ && chown -R user /run/user/1000 /home/user \ && echo user:100000:65536 | tee /etc/subuid | tee /etc/subgid COPY --link --from=rootlesskit /rootlesskit /usr/bin/ COPY --link --from=binaries / /usr/bin/ COPY --link examples/buildctl-daemonless/buildctl-daemonless.sh /usr/bin/ # Kubernetes runAsNonRoot requires USER to be numeric USER 1000:1000 ENV HOME=/home/user ENV USER=user ENV XDG_RUNTIME_DIR=/run/user/1000 ENV TMPDIR=/home/user/.local/tmp ENV BUILDKIT_HOST=unix:///run/user/1000/buildkit/buildkitd.sock VOLUME /home/user/.local/share/buildkit ENTRYPOINT ["rootlesskit", "buildkitd"] # buildkit builds the buildkit container image FROM buildkit-$TARGETOS${BUILDKIT_DEBUG:+-debug} AS buildkit