Skip to content

Commit

Permalink
release debian packages
Browse files Browse the repository at this point in the history
Signed-off-by: CrazyMax <[email protected]>
  • Loading branch information
crazy-max committed Nov 13, 2021
1 parent f002608 commit 8d8c774
Show file tree
Hide file tree
Showing 3 changed files with 83 additions and 10 deletions.
63 changes: 55 additions & 8 deletions Dockerfile
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
Expand All @@ -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 \
Expand All @@ -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

Expand All @@ -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
Expand Down
5 changes: 4 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
25 changes: 24 additions & 1 deletion docker-bake.hcl
Original file line number Diff line number Diff line change
Expand Up @@ -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"]
Expand Down

0 comments on commit 8d8c774

Please sign in to comment.