-
Notifications
You must be signed in to change notification settings - Fork 471
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Signed-off-by: CrazyMax <[email protected]>
- Loading branch information
Showing
3 changed files
with
83 additions
and
10 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 <<EOT | ||
#!/usr/bin/env bash | ||
set -e | ||
version=$(cat /tmp/.version) | ||
if [[ $version =~ ^[a-f0-9]{7}$ ]]; then | ||
version="v0.0.0+${version}" | ||
fi | ||
mkdir -p ./docker-buildx-standalone/DEBIAN | ||
cat > ./docker-buildx-standalone/DEBIAN/control <<EOL | ||
Package: docker-buildx-standalone | ||
Version: ${version:1} | ||
Architecture: $(xx-info debian-arch) | ||
Maintainer: Docker <[email protected]> | ||
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 <<EOL | ||
Package: docker-buildx-plugin | ||
Version: ${version:1} | ||
Architecture: $(xx-info debian-arch) | ||
Enhances: docker-ce-cli | ||
Maintainer: Docker <[email protected]> | ||
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 | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters