forked from DandyDeveloper/dnsmadeeasy-webhook
-
Notifications
You must be signed in to change notification settings - Fork 4
/
Dockerfile
43 lines (33 loc) · 1.23 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
FROM golang:1.23@sha256:73f06be4578c9987ce560087e2e2ea6485fb605e3910542cadd8fa09fc5f3e31 AS build
WORKDIR /workspace
ENV GO111MODULE=on
ENV TEST_ASSET_PATH /_out/kubebuilder/bin
RUN apt update -qq && apt install -qq -y git bash curl g++
# Fetch binary early because to allow more caching
COPY scripts scripts
COPY testdata testdata
RUN ./scripts/fetch-test-binaries.sh
COPY src src
# Build
RUN cd src; go mod download
RUN cd src; CGO_ENABLED=0 go build -o webhook -ldflags '-w -extldflags "-static"' .
#Test
ARG TEST_ZONE_NAME
RUN \
if [ -n "$TEST_ZONE_NAME" ]; then \
cd src; \
CCGO_ENABLED=0 \
TEST_ASSET_ETCD=${TEST_ASSET_PATH}/etcd \
TEST_ASSET_KUBE_APISERVER=${TEST_ASSET_PATH}/kube-apiserver \
TEST_ZONE_NAME="$TEST_ZONE_NAME" \
go test -v .; \
fi
# Use distroless as minimal base image to package the manager binary
# Refer to https://github.com/GoogleContainerTools/distroless for more details
FROM gcr.io/distroless/static:nonroot@sha256:d71f4b239be2d412017b798a0a401c44c3049a3ca454838473a4c32ed076bfea
WORKDIR /
COPY --from=build /workspace/src/webhook /app/webhook
USER nonroot:nonroot
ENTRYPOINT ["/app/webhook"]
ARG IMAGE_SOURCE
LABEL org.opencontainers.image.source $IMAGE_SOURCE