-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathDockerfile
59 lines (43 loc) · 1.34 KB
/
Dockerfile
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
ARG GO_VERSION=latest
#
# dev image
#
FROM golang:${GO_VERSION} AS dev
# Go dependency management tool
RUN go get -u github.com/golang/dep/cmd/dep
# Golang live reload and task runner
RUN go get -u github.com/oxequa/realize
#
# builder image
#
FROM golang:${GO_VERSION} as builder
WORKDIR /go/src/project
# Copy the current code into our workdir
COPY . .
# godep - dependency manager tool,
RUN go get -u github.com/golang/dep/cmd/dep
# Create a dep project, and run `ensure`, which will pull in all
# of the dependencies within this directory.
RUN dep ensure -vendor-only
# Build the binary, with a few flags which will allow
# us to run this binary in Alpine.
RUN CGO_ENABLED=0 GOOS=linux go build -o app -a -installsuffix cgo .
#
# release image
#
FROM alpine:latest AS release
# Security related package, good to have.
RUN apk --no-cache add ca-certificates
# Same as before, create a directory for our app.
RUN mkdir /app
WORKDIR /app
# Here, instead of copying the binary from our host machine,
# we pull the binary from the container named `builder`, within
# this build context.
COPY --from=builder /go/src/project/app .
# Run the binary as per usual! This time with a binary build in a
# separate container, with all of the correct dependencies and
# run time libraries.
CMD ["./app"]
LABEL version="1.0" \
maintainer="[email protected]"