forked from mailgun/gubernator
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Dockerfile-cli
35 lines (26 loc) · 1009 Bytes
/
Dockerfile-cli
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
# Build image
FROM --platform=$BUILDPLATFORM golang:1.17 as build
ARG BUILDPLATFORM
ARG TARGETPLATFORM
# https://github.com/docker/buildx/issues/510#issuecomment-768432329
ENV BUILDPLATFORM=${BUILDPLATFORM:-linux/amd64}
ENV TARGETPLATFORM=${TARGETPLATFORM:-linux/amd64}
WORKDIR /go/src
# This should create cached layer of our dependencies for subsequent builds to use
COPY go.mod /go/src
COPY go.sum /go/src
RUN go mod download
# Copy the local package files to the container
ADD . /go/src
ARG VERSION
# Build the server inside the container
RUN CGO_ENABLED=0 GOOS=${TARGETPLATFORM%/*} GOARCH=${TARGETPLATFORM#*/} go build -a -installsuffix cgo \
-ldflags "-w -s -X main.Version=$VERSION" -o /gubernator-cli /go/src/cmd/gubernator-cli/main.go
# Create our deploy image
FROM scratch
# Certs for ssl
COPY --from=build /etc/ssl/certs/ca-certificates.crt /etc/ssl/certs/
# Copy our static executable.
COPY --from=build /gubernator-cli /gubernator-cli
# Run the server
ENTRYPOINT ["/gubernator-cli"]