-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathDockerfile
45 lines (32 loc) · 1.08 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
# Dynamic Builds
ARG BUILDER_IMAGE=golang:1.19-buster
ARG FINAL_IMAGE=debian:buster-slim
# Build stage
FROM ${BUILDER_IMAGE} AS builder
# Build Args
ARG GIT_REVISION=""
# Ensure ca-certificates are up to date on the image
RUN update-ca-certificates
# Use modules for dependencies
WORKDIR $GOPATH/src/github.com/bbengfort/raft
COPY go.mod .
COPY go.sum .
ENV CGO_ENABLED=0
ENV GO111MODULE=on
RUN go mod download
RUN go mod verify
# Copy package
COPY . .
# Build binary
RUN go build -v -o /go/bin/raft -ldflags="-X 'github.com/bbengfort/raft.GitVersion=${GIT_REVISION}'" ./cmd/raft
# Final Stage
FROM ${FINAL_IMAGE} AS final
LABEL maintainer="Benjamin Bengfort <benjamin@bengfort.com>"
LABEL description="An implementation of the Raft consensus algorithm"
# Ensure ca-certificates are up to date
RUN set -x && apt-get update && \
DEBIAN_FRONTEND=noninteractive apt-get install -y ca-certificates && \
rm -rf /var/lib/apt/lists/*
# Copy the binary to the production image from the builder stage
COPY --from=builder /go/bin/raft /usr/local/bin/raft
CMD [ "/usr/local/bin/raft", "serve" ]