Skip to content
This repository was archived by the owner on Nov 5, 2019. It is now read-only.

Commit 81623fa

Browse files
authored
Merge pull request #22 from ibnesayeed/master
Reworked Dockerfile for flexibility
2 parents 72775c0 + 072f879 commit 81623fa

File tree

1 file changed

+36
-14
lines changed

1 file changed

+36
-14
lines changed

Dockerfile

Lines changed: 36 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,39 @@
1-
FROM golang:latest
2-
# Expose default port
3-
EXPOSE 3000
1+
ARG GOLANG_TAG=latest
2+
ARG ALPINE_TAG=latest
3+
4+
# Build stage with all the development dependencies
5+
FROM golang:${GOLANG_TAG} AS dev
6+
7+
# Setup gin for dev monitoring
8+
RUN go-wrapper download github.com/codegangsta/gin
9+
RUN go-wrapper install github.com/codegangsta/gin
10+
11+
# Copy the local package files into the image's workspace.
12+
COPY . /go/src/github.com/datatogether/coverage
13+
WORKDIR /go/src/github.com/datatogether/coverage
14+
15+
# Run tests
16+
RUN go test
417

5-
# gin is for dev monitoring
6-
# RUN go-wrapper download github.com/codegangsta/gin
7-
# RUN go-wrapper install github.com/codegangsta/gin
18+
# Build the static api binary
19+
RUN CGO_ENABLED=0 GOOS=linux go install -a -installsuffix cgo
20+
21+
# Let gin watch and build by default in development environment
22+
CMD ["gin", "-i"]
23+
24+
# Start over from an Alpine Linux image as a base
25+
# to create a minumal production image
26+
FROM alpine:${ALPINE_TAG}
27+
LABEL repo="https://github.com/datatogether/coverage"
28+
29+
# Add certificates for TLS requests
30+
RUN apk --no-cache add ca-certificates
31+
32+
# Expose default port
33+
EXPOSE 8080
834

9-
# Copy the local package files to the container’s workspace.
10-
ADD . /go/src/github.com/datatogether/coverage
11-
# WORKDIR /go/src/github.com/datatogether/coverage
12-
# CMD ["gin", "-i"]
35+
# Copy the binary from the dev stage into a location that is in PATH
36+
COPY --from=dev /go/bin/coverage /usr/local/bin/
1337

14-
# Install api binary globally within container
15-
RUN go install github.com/datatogether/coverage
16-
# Set binary as entrypoint
17-
ENTRYPOINT /go/bin/coverage
38+
# Set binary as the default command
39+
CMD ["coverage"]

0 commit comments

Comments
 (0)