Skip to content

Commit

Permalink
Merge pull request #346 from buchdag/fix-dockerfile
Browse files Browse the repository at this point in the history
Have the Dockerfile build from the actual surrounding sources rather than downloading a hardcoded version
  • Loading branch information
jwilder authored Apr 10, 2021
2 parents e877b8f + aa1675f commit 37de427
Showing 1 changed file with 17 additions and 18 deletions.
35 changes: 17 additions & 18 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,28 +1,27 @@
# Build docker-gen from scratch
FROM golang:1.14-alpine as dockergen
RUN apk add --no-cache git
FROM golang:1.16-alpine as go-builder

# Download the sources for the given version
ENV VERSION 0.7.5
ADD https://github.com/jwilder/docker-gen/archive/${VERSION}.tar.gz sources.tar.gz
ARG VERSION=master

# 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
WORKDIR /build

# Install the dependencies and make the docker-gen executable
WORKDIR /go/src/github.com/jwilder/docker-gen
RUN CGO_ENABLED=0 go build -ldflags "-X main.buildVersion=${VERSION}" ./cmd/docker-gen
# Install the dependencies
COPY . .
RUN go mod download -json

FROM alpine:latest
LABEL maintainer="Jason Wilder <mail@jasonwilder.com>"
# Build the docker-gen executable
RUN CGO_ENABLED=0 go build -ldflags "-X main.buildVersion=${VERSION}" -o docker-gen ./cmd/docker-gen

FROM alpine:3.13

RUN apk -U add openssl
LABEL maintainer="Jason Wilder <mail@jasonwilder.com>"

ENV VERSION 0.7.5
COPY --from=dockergen /go/src/github.com/jwilder/docker-gen/docker-gen /usr/local/bin/docker-gen
ENV DOCKER_HOST unix:///tmp/docker.sock

# Install packages required by the image
RUN apk add --no-cache --virtual .bin-deps openssl

# Install docker-gen from build stage
COPY --from=go-builder /build/docker-gen /usr/local/bin/docker-gen

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

0 comments on commit 37de427

Please sign in to comment.