forked from kubernetes-sigs/dashboard-metrics-scraper
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathDockerfile
51 lines (38 loc) · 1.6 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
47
48
49
50
51
# Accept the Go version for the image to be set as a build argument.
# Default to Go 1.11
ARG GO_VERSION=1.11
# First stage: build the executable.
FROM golang:${GO_VERSION}-alpine 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 apk add --no-cache ca-certificates git gcc libc-dev
# Set the environment variables for the go command:
# * GOFLAGS=-mod=vendor to force `go build` to look into the `/vendor` folder.
ENV GOFLAGS=-mod=vendor
# 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} go build \
-installsuffix 'static' \
-ldflags '-extldflags "-static"' \
-o /metrics-sidecar github.com/kubernetes-sigs/dashboard-metrics-scraper
# Final stage: the running container.
FROM scratch AS final
# Import the Certificate-Authority certificates for enabling HTTPS.
COPY --from=builder /etc/ssl/certs/ca-certificates.crt /etc/ssl/certs/
# Import the compiled executable from the second stage.
COPY --from=builder /metrics-sidecar /metrics-sidecar
# We need a tmp folder too
COPY --from=builder /tmp /tmp
# Declare the port on which the webserver will be exposed.
EXPOSE 8080
# Run the compiled binary.
ENTRYPOINT ["/metrics-sidecar"]