-
Notifications
You must be signed in to change notification settings - Fork 28
/
Dockerfile
40 lines (28 loc) · 979 Bytes
/
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
# Start from golang base image
FROM golang:alpine as builder
# Enable go modules
ENV GO111MODULE=on
# Install git. (alpine image does not have git in it)
RUN apk update && apk add --no-cache git
# Set current working directory
WORKDIR /app
# Note here: To avoid downloading dependencies every time we
# build image. Here, we are caching all the dependencies by
# first copying go.mod and go.sum files and downloading them,
# to be used every time we build the image if the dependencies
# are not changed.
# Copy go mod and sum files
COPY go.mod ./
COPY go.sum ./
# Download all dependencies.
RUN go mod download
# Now, copy the source code
COPY . .
# Note here: CGO_ENABLED is disabled for cross system compilation
# It is also a common best practise.
# Build the application.
RUN CGO_ENABLED=0 go build -o ./bin/metrics-server ./cmd/main.go
# Start a new stage from scratch
FROM scratch
COPY --from=builder /app/bin/metrics-server /
ENTRYPOINT [ "/metrics-server" ]