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