From 746e878ffcd3e654e603528f6bc0406fed9a25bc Mon Sep 17 00:00:00 2001 From: Matti R Date: Wed, 13 Oct 2021 01:14:04 -0400 Subject: [PATCH] build go binary in docker --- .woodpecker/main.yml | 6 ------ Dockerfile | 21 +++++++++++---------- 2 files changed, 11 insertions(+), 16 deletions(-) diff --git a/.woodpecker/main.yml b/.woodpecker/main.yml index 50e50a3..8e82188 100644 --- a/.woodpecker/main.yml +++ b/.woodpecker/main.yml @@ -1,10 +1,4 @@ pipeline: - build: - image: golang:1.17 - commands: - - "[ -z \"${DRONE_TAG}\" ] && BUILD_VERSION=${DRONE_COMMIT_SHA:0:8} || BUILD_VERSION=${DRONE_TAG##v}" - - go build -v -a -tags netgo ./cmd/docker-buildx - publish: image: plugins/docker repo: foo/bar diff --git a/Dockerfile b/Dockerfile index 6914d10..2c42f30 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,11 +1,11 @@ -FROM docker:20.10-dind@sha256:d20f0866ee1aca6b0eb7bc8bdb0d0c938721c7f79219b1d3bc1aa58666928586 +FROM golang:1.17-alpine as build -LABEL maintainer="Robert Kaussow " -LABEL org.opencontainers.image.authors="Robert Kaussow " -LABEL org.opencontainers.image.title="drone-docker-buildx" -LABEL org.opencontainers.image.url="https://github.com/thegeeklab/drone-docker-buildx" -LABEL org.opencontainers.image.source="https://github.com/thegeeklab/drone-docker-buildx" -LABEL org.opencontainers.image.documentation="https://github.com/thegeeklab/drone-docker-buildx" +COPY . /src +WORKDIR /src + +RUN go build -v -a -tags netgo ./cmd/docker-buildx -o docker-buildx + +FROM docker:20.10-dind ARG BUILDX_VERSION @@ -14,7 +14,8 @@ ENV BUILDX_VERSION="${BUILDX_VERSION:-v0.6.3}" ENV DOCKER_HOST=unix:///var/run/docker.sock -RUN apk --update add --virtual .build-deps curl && \ +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 && \ @@ -22,6 +23,6 @@ RUN apk --update add --virtual .build-deps curl && \ rm -rf /var/cache/apk/* && \ rm -rf /tmp/* -ADD release/amd64/drone-docker-buildx /bin/ +COPY --from=build /src/docker-buildx /bin/docker-buildx -ENTRYPOINT ["/usr/local/bin/dockerd-entrypoint.sh", "drone-docker-buildx"] +ENTRYPOINT ["/usr/local/bin/dockerd-entrypoint.sh", "docker-buildx"]