Skip to content

Commit 37de427

Browse files
authored
Merge pull request #346 from buchdag/fix-dockerfile
Have the Dockerfile build from the actual surrounding sources rather than downloading a hardcoded version
2 parents e877b8f + aa1675f commit 37de427

File tree

1 file changed

+17
-18
lines changed

1 file changed

+17
-18
lines changed

Dockerfile

Lines changed: 17 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,28 +1,27 @@
11
# Build docker-gen from scratch
2-
FROM golang:1.14-alpine as dockergen
3-
RUN apk add --no-cache git
2+
FROM golang:1.16-alpine as go-builder
43

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

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
6+
WORKDIR /build
137

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

18-
FROM alpine:latest
19-
LABEL maintainer="Jason Wilder <[email protected]>"
12+
# Build the docker-gen executable
13+
RUN CGO_ENABLED=0 go build -ldflags "-X main.buildVersion=${VERSION}" -o docker-gen ./cmd/docker-gen
14+
15+
FROM alpine:3.13
2016

21-
RUN apk -U add openssl
17+
LABEL maintainer="Jason Wilder <[email protected]>"
2218

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

21+
# Install packages required by the image
22+
RUN apk add --no-cache --virtual .bin-deps openssl
23+
24+
# Install docker-gen from build stage
25+
COPY --from=go-builder /build/docker-gen /usr/local/bin/docker-gen
2726

28-
ENTRYPOINT ["/usr/local/bin/docker-gen"]
27+
ENTRYPOINT ["/usr/local/bin/docker-gen"]

0 commit comments

Comments
 (0)