From b85ee124e210edd5d7e3648552397e58bc034486 Mon Sep 17 00:00:00 2001 From: 6543 <6543@obermui.de> Date: Sat, 8 Oct 2022 00:58:57 +0200 Subject: [PATCH] Ensure that the plugin binary does not conflict with the utility being used (#24) use methode described in https://docs.docker.com/build/buildx/install/ to install buildx into image. - `/usr/lib/docker/cli-plugins/docker-buildx` -> `/usr/libexec/docker/cli-plugins/docker-buildx` - fix linux/amd64 build on linux/arm64 rename plugin binary - `docker-buildx` -> `plugin-docker-buildx` Reviewed-on: https://codeberg.org/woodpecker-plugins/plugin-docker-buildx/pulls/24 Reviewed-by: anbraten --- .gitignore | 2 +- Dockerfile.multiarch | 28 ++++++++++------------------ Makefile | 2 +- 3 files changed, 12 insertions(+), 20 deletions(-) diff --git a/.gitignore b/.gitignore index 67cd426..c5e9d24 100644 --- a/.gitignore +++ b/.gitignore @@ -1,6 +1,6 @@ /release/ -docker-buildx +plugin-docker-buildx coverage.out CHANGELOG.md diff --git a/Dockerfile.multiarch b/Dockerfile.multiarch index 6509743..b9f3923 100644 --- a/Dockerfile.multiarch +++ b/Dockerfile.multiarch @@ -1,4 +1,8 @@ -FROM --platform=$BUILDPLATFORM golang:1.18 as build +ARG BUILDX_VERSION=0.9.1 +ARG DOCKER_VERSION=20.10-dind +ARG GOLANG_VERSION=1.18 + +FROM --platform=$BUILDPLATFORM golang:${GOLANG_VERSION} as build COPY . /src WORKDIR /src @@ -8,24 +12,12 @@ RUN --mount=type=cache,target=/root/.cache/go-build \ --mount=type=cache,target=/go/pkg \ make build -FROM docker:20.10-dind +FROM docker/buildx-bin:${BUILDX_VERSION} as buildx-bin +FROM docker:${DOCKER_VERSION} -ARG BUILDX_VERSION - -# renovate: datasource=github-releases depName=docker/buildx -ENV BUILDX_VERSION="${BUILDX_VERSION:-v0.9.1}" +COPY --from=buildx-bin /buildx /usr/libexec/docker/cli-plugins/docker-buildx +COPY --from=build /src/plugin-docker-buildx /bin/plugin-docker-buildx ENV DOCKER_HOST=unix:///var/run/docker.sock -RUN \ - apk --update add --virtual .build-deps curl && \ - mkdir -p /usr/lib/docker/cli-plugins/ && \ - curl -SsL -o /usr/lib/docker/cli-plugins/docker-buildx "https://github.com/docker/buildx/releases/download/v${BUILDX_VERSION##v}/buildx-v${BUILDX_VERSION##v}.linux-amd64" && \ - chmod 755 /usr/lib/docker/cli-plugins/docker-buildx && \ - apk del .build-deps && \ - rm -rf /var/cache/apk/* && \ - rm -rf /tmp/* - -COPY --from=build /src/docker-buildx /bin/docker-buildx - -ENTRYPOINT ["/usr/local/bin/dockerd-entrypoint.sh", "docker-buildx"] +ENTRYPOINT ["/usr/local/bin/dockerd-entrypoint.sh", "plugin-docker-buildx"] diff --git a/Makefile b/Makefile index 2dd7bd3..1af273c 100644 --- a/Makefile +++ b/Makefile @@ -3,4 +3,4 @@ TARGETARCH ?= amd64 LDFLAGS := -s -w -extldflags "-static" build: - CGO_ENABLED=0 GOOS=${TARGETOS} GOARCH=${TARGETARCH} go build -ldflags '${LDFLAGS}' -v -a -tags netgo -o docker-buildx ./cmd/docker-buildx + CGO_ENABLED=0 GOOS=${TARGETOS} GOARCH=${TARGETARCH} go build -ldflags '${LDFLAGS}' -v -a -tags netgo -o plugin-docker-buildx ./cmd/docker-buildx