forked from mattkelly/cerebral
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Dockerfile
42 lines (32 loc) · 1.24 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
FROM golang:1.12.9-alpine3.10 as builder
# Add build tools
RUN apk update && \
apk add --no-cache git gcc musl-dev curl
RUN curl -fsSL -o /usr/local/bin/dep https://github.com/golang/dep/releases/download/v0.5.0/dep-linux-amd64 && \
chmod +x /usr/local/bin/dep
ENV SRC_DIR=/go/src/github.com/containership/cerebral/
WORKDIR /app
# Install deps before adding rest of source so we can cache the resulting vendor dir
COPY Gopkg.toml Gopkg.lock $SRC_DIR
RUN cd $SRC_DIR && \
dep ensure -vendor-only
# Add the source code
COPY . $SRC_DIR
# Build it:
ARG GIT_DESCRIBE
ARG GIT_COMMIT
RUN cd $SRC_DIR && \
CGO_ENABLED=0 GOOS=linux GOARCH=amd64 \
go build -ldflags \
"-X github.com/containership/cerebral/pkg/buildinfo.gitDescribe=${GIT_DESCRIBE} \
-X github.com/containership/cerebral/pkg/buildinfo.gitCommit=${GIT_COMMIT} \
-X github.com/containership/cerebral/pkg/buildinfo.unixTime=`date '+%s'` \
-w" \
-a -tags netgo \
-o cerebral cmd/cerebral/cerebral.go && \
cp cerebral /app/
# Create Docker image of just the binary
FROM scratch as runner
COPY --from=builder /etc/ssl/certs/ca-certificates.crt /etc/ssl/certs/ca-certificates.crt
COPY --from=builder /app/cerebral .
CMD ["./cerebral"]