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:70031844b8c225351d0bb63e2c383f80db85d92ba894e3da7e13bcf80efa9a37 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:6cd937e9155bdfd805d1b94e037f9d6a899603306030936a3b11680af0c2ed58
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