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 <anbraten@noreply.codeberg.org>
This commit is contained in:
6543 2022-10-08 00:58:57 +02:00
parent 10426e6a19
commit b85ee124e2
3 changed files with 12 additions and 20 deletions

2
.gitignore vendored
View File

@ -1,6 +1,6 @@
/release/ /release/
docker-buildx plugin-docker-buildx
coverage.out coverage.out
CHANGELOG.md CHANGELOG.md

View File

@ -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 COPY . /src
WORKDIR /src WORKDIR /src
@ -8,24 +12,12 @@ RUN --mount=type=cache,target=/root/.cache/go-build \
--mount=type=cache,target=/go/pkg \ --mount=type=cache,target=/go/pkg \
make build make build
FROM docker:20.10-dind FROM docker/buildx-bin:${BUILDX_VERSION} as buildx-bin
FROM docker:${DOCKER_VERSION}
ARG BUILDX_VERSION COPY --from=buildx-bin /buildx /usr/libexec/docker/cli-plugins/docker-buildx
COPY --from=build /src/plugin-docker-buildx /bin/plugin-docker-buildx
# renovate: datasource=github-releases depName=docker/buildx
ENV BUILDX_VERSION="${BUILDX_VERSION:-v0.9.1}"
ENV DOCKER_HOST=unix:///var/run/docker.sock ENV DOCKER_HOST=unix:///var/run/docker.sock
RUN \ ENTRYPOINT ["/usr/local/bin/dockerd-entrypoint.sh", "plugin-docker-buildx"]
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"]

View File

@ -3,4 +3,4 @@ TARGETARCH ?= amd64
LDFLAGS := -s -w -extldflags "-static" LDFLAGS := -s -w -extldflags "-static"
build: 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