Skip to content

Commit 16dbe96

Browse files
committed
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/
1 parent 4edc190 commit 16dbe96

File tree

1 file changed

+19
-2
lines changed

1 file changed

+19
-2
lines changed

Dockerfile

Lines changed: 19 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,29 @@
1+
# Build docker-gen from scratch
2+
FROM golang:1.14-alpine as dockergen
3+
RUN apk add --no-cache git
4+
5+
# Download the sources for the given version
6+
ENV VERSION 0.7.3
7+
ADD https://github.com/jwilder/docker-gen/archive/${VERSION}.tar.gz sources.tar.gz
8+
9+
# Move the sources into the right directory
10+
RUN tar -xzf sources.tar.gz && \
11+
mkdir -p /go/src/github.com/jwilder/ && \
12+
mv docker-gen-* /go/src/github.com/jwilder/docker-gen
13+
14+
# Install the dependencies and make the docker-gen executable
15+
WORKDIR /go/src/github.com/jwilder/docker-gen
16+
RUN go get -v ./... && \
17+
CGO_ENABLED=0 GOOS=linux go build -ldflags "-X main.buildVersion=${VERSION}" ./cmd/docker-gen
18+
119
FROM alpine:latest
220
LABEL maintainer="Jason Wilder <[email protected]>"
321

422
RUN apk -U add openssl
523

624
ENV VERSION 0.7.3
7-
ENV DOWNLOAD_URL https://github.com/jwilder/docker-gen/releases/download/$VERSION/docker-gen-alpine-linux-amd64-$VERSION.tar.gz
25+
COPY --from=dockergen /go/src/github.com/jwilder/docker-gen/docker-gen /usr/local/bin/docker-gen
826
ENV DOCKER_HOST unix:///tmp/docker.sock
927

10-
RUN wget -qO- $DOWNLOAD_URL | tar xvz -C /usr/local/bin
1128

1229
ENTRYPOINT ["/usr/local/bin/docker-gen"]

0 commit comments

Comments
 (0)