forked from kubernetes-sigs/dashboard-metrics-scraper
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Dockerfile
45 lines (33 loc) · 1.29 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
# Accept the Go version for the image to be set as a build argument.
ARG GO_VERSION=1.18
# First stage: build the executable.
FROM golang:${GO_VERSION}-stretch AS builder
# What arch is it?
ARG GOARCH=amd64
ARG GOOS=linux
# Install the Certificate-Authority certificates for the app to be able to make
# calls to HTTPS endpoints.
RUN apt-get update && \
apt-get install -y ca-certificates git gcc libc-dev libncurses5-dev sqlite3
# Set the working directory outside $GOPATH to enable the support for modules.
WORKDIR /src
# Import the code from the context.
COPY ./ ./
# Build the executable to `/app`. Mark the build as statically linked.
RUN echo "Building for $GOARCH" \
&& mkdir -p ${GOPATH}/src/github.com/kubernetes-sigs \
&& ln -sf `pwd` ${GOPATH}/src/github.com/kubernetes-sigs/dashboard-metrics-scraper \
&& GOARCH=${GOARCH} hack/build.sh
# Create a nonroot user for final image
RUN useradd -u 10001 nonroot
# Final stage: the running container.
FROM scratch AS final
# Import the compiled executable from the second stage.
COPY --from=builder /metrics-sidecar /metrics-sidecar
# Copy nonroot user
COPY --from=builder /etc/passwd /etc/passwd
# Declare the port on which the webserver will be exposed.
EXPOSE 8080
USER nonroot
# Run the compiled binary.
ENTRYPOINT ["/metrics-sidecar"]