From 16dbe9606fb6d0978f5fd1ac42250a0e51fa2006 Mon Sep 17 00:00:00 2001 From: Tom Wiesing Date: Mon, 13 Jul 2020 12:18:47 +0200 Subject: [PATCH 1/2] Enable multi-architecture docker image builds Previously, the Dockerfile downloaded a 'docker-gen' binary during build time. This caused a problem as it hard-coded the amd64 architecture for the image. This commit updates the Dockerfile to build the docker-gen executable from source instead of downloading a binary. This updated Dockerfile uses a multi-stage build [1]. The first stage downloads a source tarball from github and produces a binary out of it. The second stage corresponds to the old Dockerfile, with the sole change being that is fetches the binary from the first stage instead of GitHub. This has the advantage that the build process no longer assumes a certain architecture and enables building the image for any architecture that both the golang and alpine base images support. [1] https://docs.docker.com/develop/develop-images/multistage-build/ --- Dockerfile | 21 +++++++++++++++++++-- 1 file changed, 19 insertions(+), 2 deletions(-) diff --git a/Dockerfile b/Dockerfile index 2277a2fb..1f0d43ff 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,12 +1,29 @@ +# Build docker-gen from scratch +FROM golang:1.14-alpine as dockergen +RUN apk add --no-cache git + +# Download the sources for the given version +ENV VERSION 0.7.3 +ADD https://github.com/jwilder/docker-gen/archive/${VERSION}.tar.gz sources.tar.gz + +# Move the sources into the right directory +RUN tar -xzf sources.tar.gz && \ + mkdir -p /go/src/github.com/jwilder/ && \ + mv docker-gen-* /go/src/github.com/jwilder/docker-gen + +# Install the dependencies and make the docker-gen executable +WORKDIR /go/src/github.com/jwilder/docker-gen +RUN go get -v ./... && \ + CGO_ENABLED=0 GOOS=linux go build -ldflags "-X main.buildVersion=${VERSION}" ./cmd/docker-gen + FROM alpine:latest LABEL maintainer="Jason Wilder " RUN apk -U add openssl ENV VERSION 0.7.3 -ENV DOWNLOAD_URL https://github.com/jwilder/docker-gen/releases/download/$VERSION/docker-gen-alpine-linux-amd64-$VERSION.tar.gz +COPY --from=dockergen /go/src/github.com/jwilder/docker-gen/docker-gen /usr/local/bin/docker-gen ENV DOCKER_HOST unix:///tmp/docker.sock -RUN wget -qO- $DOWNLOAD_URL | tar xvz -C /usr/local/bin ENTRYPOINT ["/usr/local/bin/docker-gen"] From 5c7011b8a451857c80610930c7bcea4c1b6791b0 Mon Sep 17 00:00:00 2001 From: Tom Wiesing Date: Mon, 13 Jul 2020 12:19:04 +0200 Subject: [PATCH 2/2] Bump Dockerfile version to 0.7.4 The previous version of the Dockerfile made use of version 0.7.3. However because of changes in dependencies, this can no longer be compiled from source. To fix this regression, this commit updates the version used to 0.7.4. --- Dockerfile | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Dockerfile b/Dockerfile index 1f0d43ff..1ad26306 100644 --- a/Dockerfile +++ b/Dockerfile @@ -3,7 +3,7 @@ FROM golang:1.14-alpine as dockergen RUN apk add --no-cache git # Download the sources for the given version -ENV VERSION 0.7.3 +ENV VERSION 0.7.4 ADD https://github.com/jwilder/docker-gen/archive/${VERSION}.tar.gz sources.tar.gz # Move the sources into the right directory @@ -21,7 +21,7 @@ LABEL maintainer="Jason Wilder " RUN apk -U add openssl -ENV VERSION 0.7.3 +ENV VERSION 0.7.4 COPY --from=dockergen /go/src/github.com/jwilder/docker-gen/docker-gen /usr/local/bin/docker-gen ENV DOCKER_HOST unix:///tmp/docker.sock