2019-10-04 19:49:31 +02:00
|
|
|
# Use the offical Golang image to create a build artifact.
|
|
|
|
# This is based on Debian and sets the GOPATH to /go.
|
|
|
|
# https://hub.docker.com/_/golang
|
|
|
|
FROM golang:1.13 as builder
|
|
|
|
|
|
|
|
# Create and change to the app directory.
|
|
|
|
WORKDIR /app
|
|
|
|
|
2019-10-25 22:37:40 +02:00
|
|
|
RUN go get -u github.com/golang/dep/cmd/dep
|
|
|
|
|
2019-10-04 19:49:31 +02:00
|
|
|
# Retrieve application dependencies.
|
|
|
|
# This allows the container build to reuse cached dependencies.
|
|
|
|
COPY go.* ./
|
|
|
|
RUN go mod download
|
|
|
|
|
|
|
|
# Copy local code to the container image.
|
|
|
|
COPY . ./
|
|
|
|
|
2019-10-25 22:37:40 +02:00
|
|
|
#Ensure dependencies with dep
|
|
|
|
RUN dep ensure
|
|
|
|
|
2019-10-04 19:49:31 +02:00
|
|
|
# Build the binary.
|
2019-10-04 20:04:48 +02:00
|
|
|
RUN CGO_ENABLED=0 GOOS=linux go build -v -o server
|
2019-10-04 19:49:31 +02:00
|
|
|
|
|
|
|
# Use the official Alpine image for a lean production container.
|
|
|
|
# https://hub.docker.com/_/alpine
|
|
|
|
# https://docs.docker.com/develop/develop-images/multistage-build/#use-multi-stage-builds
|
|
|
|
FROM alpine:3
|
|
|
|
RUN apk add --no-cache ca-certificates
|
|
|
|
|
|
|
|
# Copy the binary to the production image from the builder stage.
|
|
|
|
COPY --from=builder /app/server /server
|
|
|
|
|
|
|
|
# Run the web service on container startup.
|
|
|
|
CMD ["/server"]
|