-
Notifications
You must be signed in to change notification settings - Fork 12
/
Copy pathDockerfile
49 lines (39 loc) · 1.58 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
FROM registry.access.redhat.com/ubi9/ubi-minimal:latest AS builder
RUN microdnf install git-core jq tar -y && microdnf clean all
# Build the manager binary
WORKDIR /workspace
# Copy the go source
COPY go.mod go.mod
COPY go.sum go.sum
# use latest Go z release
ENV GOTOOLCHAIN=auto
ENV GO_INSTALL_DIR=/golang
# Ensure correct Go version
RUN export GO_VERSION=$(grep -E "go [[:digit:]]\.[[:digit:]][[:digit:]]" go.mod | awk '{print $2}') && \
export GO_FILENAME=$(curl -sL 'https://go.dev/dl/?mode=json&include=all' | jq -r "[.[] | select(.version | startswith(\"go${GO_VERSION}\"))][0].files[] | select(.os == \"linux\" and .arch == \"amd64\") | .filename") && \
curl -sL -o go.tar.gz "https://golang.org/dl/${GO_FILENAME}" && \
mkdir -p ${GO_INSTALL_DIR} && \
tar -C ${GO_INSTALL_DIR} -xzf go.tar.gz && \
rm go.tar.gz && ln -sf ${GO_INSTALL_DIR}/go/bin/go /usr/bin/go
# Copy the go sources
COPY vendor/ vendor/
COPY cmd/main.go cmd/main.go
COPY api/ api/
COPY version/ version/
COPY internal/controller/ internal/controller/
COPY hack/ hack/
COPY .git/ .git/
RUN mkdir /licenses
COPY LICENSE /licenses
# Build
RUN --mount=type=secret,id=apikey hack/build.sh
# 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
# UBI is larger (158Mb vs. 56Mb) but approved by RH
FROM registry.access.redhat.com/ubi9/ubi-minimal:latest
WORKDIR /
COPY --from=builder /workspace/manager .
COPY --from=builder /licenses/ /licenses/
USER 65532:65532
ENTRYPOINT ["/manager"]