forked from mailgun/gubernator
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Dockerfile
46 lines (34 loc) · 1.3 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
# Build image
FROM --platform=$BUILDPLATFORM golang:1.20.3 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 /go/src/cmd/gubernator
RUN CGO_ENABLED=0 GOOS=${TARGETPLATFORM%/*} GOARCH=${TARGETPLATFORM#*/} go build -a -installsuffix cgo \
-ldflags "-w -s" -o /healthcheck /go/src/cmd/healthcheck
# 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 /gubernator
COPY --from=build /healthcheck /healthcheck
# Healtcheck
HEALTHCHECK --interval=3s --timeout=1s --start-period=2s --retries=2 CMD [ "/healthcheck" ]
# Run the server
ENTRYPOINT ["/gubernator"]
EXPOSE 80
EXPOSE 81
EXPOSE 7946