diff --git a/Dockerfile b/Dockerfile index 1f258aae067a..ff1d361ccc81 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,4 +1,4 @@ -# syntax=docker/dockerfile:1.3 +# syntax=docker/dockerfile:1.3-labs ARG GO_VERSION=1.17 ARG DOCKERD_VERSION=20.10.8 @@ -16,24 +16,24 @@ RUN apk add --no-cache file git ENV GOFLAGS=-mod=vendor WORKDIR /src -FROM gobase AS buildx-version +FROM gobase AS version RUN --mount=target=. \ PKG=github.com/docker/buildx 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); \ echo "-X ${PKG}/version.Version=${VERSION} -X ${PKG}/version.Revision=${REVISION} -X ${PKG}/version.Package=${PKG}" | tee /tmp/.ldflags; \ echo -n "${VERSION}" | tee /tmp/.version; -FROM gobase AS buildx-build +FROM gobase AS build ENV CGO_ENABLED=0 ARG LDFLAGS="-w -s" ARG TARGETPLATFORM RUN --mount=type=bind,target=. \ --mount=type=cache,target=/root/.cache \ --mount=type=cache,target=/go/pkg/mod \ - --mount=type=bind,source=/tmp/.ldflags,target=/tmp/.ldflags,from=buildx-version \ + --mount=type=bind,source=/tmp/.ldflags,target=/tmp/.ldflags,from=version \ set -x; xx-go build -ldflags "$(cat /tmp/.ldflags) ${LDFLAGS}" -o /usr/bin/buildx ./cmd/buildx && \ xx-verify --static /usr/bin/buildx -FROM buildx-build AS test +FROM build AS test RUN --mount=type=bind,target=. \ --mount=type=cache,target=/root/.cache \ --mount=type=cache,target=/go/pkg/mod \ @@ -44,13 +44,13 @@ FROM scratch AS test-coverage COPY --from=test /tmp/coverage.txt /coverage.txt FROM scratch AS binaries-unix -COPY --from=buildx-build /usr/bin/buildx / +COPY --from=build /usr/bin/buildx / FROM binaries-unix AS binaries-darwin FROM binaries-unix AS binaries-linux FROM scratch AS binaries-windows -COPY --from=buildx-build /usr/bin/buildx /buildx.exe +COPY --from=build /usr/bin/buildx /buildx.exe FROM binaries-$TARGETOS AS binaries @@ -59,12 +59,59 @@ FROM --platform=$BUILDPLATFORM alpine AS releaser WORKDIR /work ARG TARGETPLATFORM RUN --mount=from=binaries \ - --mount=type=bind,source=/tmp/.version,target=/tmp/.version,from=buildx-version \ + --mount=type=bind,source=/tmp/.version,target=/tmp/.version,from=version \ mkdir -p /out && cp buildx* "/out/buildx-$(cat /tmp/.version).$(echo $TARGETPLATFORM | sed 's/\//-/g')$(ls buildx* | sed -e 's/^buildx//')" FROM scratch AS release COPY --from=releaser /out/ / +# Deb +FROM --platform=$BUILDPLATFORM debian:bullseye-slim AS build-deb +RUN apt-get update && apt-get install -y debhelper dh-make +WORKDIR /build +COPY --from=xx / / +COPY --from=build /usr/bin/buildx ./docker-buildx-standalone/usr/bin/ +COPY --from=build /usr/bin/buildx ./docker-buildx-plugin/usr/libexec/docker/cli-plugins/docker-buildx +ARG TARGETPLATFORM +RUN --mount=type=bind,source=/tmp/.version,target=/tmp/.version,from=version < ./docker-buildx-standalone/DEBIAN/control < +Description: Docker Buildx extends build capabilities with BuildKit. +Homepage: https://github.com/docker/buildx +Vcs-Browser: https://github.com/docker/buildx +Vcs-Git: https://github.com/docker/buildx.git +EOL +mkdir -p ./docker-buildx-plugin/DEBIAN +cat > ./docker-buildx-plugin/DEBIAN/control < +Description: Docker Buildx extends build capabilities with BuildKit. +Homepage: https://github.com/docker/buildx +Vcs-Browser: https://github.com/docker/buildx +Vcs-Git: https://github.com/docker/buildx.git +EOL +dpkg-deb --build docker-buildx-standalone +dpkg-name docker-buildx-standalone.deb +dpkg-deb --build docker-buildx-plugin +dpkg-name docker-buildx-plugin.deb +EOT + +FROM scratch AS deb +COPY --from=build-deb /build/*.deb / + # Shell FROM docker:$DOCKERD_VERSION AS dockerd-release FROM alpine AS shell diff --git a/Makefile b/Makefile index da70e877c015..d92d763deec8 100644 --- a/Makefile +++ b/Makefile @@ -20,6 +20,9 @@ binaries: binaries-cross: $(BUILDX_CMD) bake binaries-cross +deb: + $(BUILDX_CMD) bake deb + install: binaries mkdir -p ~/.docker/cli-plugins install bin/buildx ~/.docker/cli-plugins/docker-buildx @@ -59,4 +62,4 @@ authors: mod-outdated: $(BUILDX_CMD) bake mod-outdated -.PHONY: shell binaries binaries-cross install release validate-all lint validate-vendor validate-docs validate-authors vendor docs authors +.PHONY: shell binaries binaries-cross deb install release validate-all lint validate-vendor validate-docs validate-authors vendor docs authors diff --git a/docker-bake.hcl b/docker-bake.hcl index d049e4b8bb94..2f1ab0f14922 100644 --- a/docker-bake.hcl +++ b/docker-bake.hcl @@ -122,12 +122,35 @@ target "binaries-cross" { ] } -target "release" { +target "deb" { + inherits = ["binaries"] + target = "deb" + platforms = [ + "linux/amd64", + "linux/arm/v6", + "linux/arm/v7", + "linux/arm64", + "linux/ppc64le", + "linux/riscv64", + "linux/s390x" + ] +} + +group "release" { + targets = ["release-binaries", "release-deb"] +} + +target "release-binaries" { inherits = ["binaries-cross"] target = "release" output = [RELEASE_OUT] } +target "release-deb" { + inherits = ["deb"] + output = [RELEASE_OUT] +} + target "image" { inherits = ["meta-helper", "binaries"] output = ["type=image"]