-
Notifications
You must be signed in to change notification settings - Fork 20
/
Copy pathDockerfile
79 lines (57 loc) · 2.72 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
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
# For building forgerock/secret-agent:tagname
# Global build arguments
ARG GO_VERSION="1.22.2"
ARG GO_PACKAGE_SHA256="5901c52b7a78002aeff14a21f93e0f064f74ce1360fce51c6ee68cd471216a17"
ARG KUBEBUILDER_VERSION="3.1.0"
FROM openjdk:23-ea-15-jdk-slim-bullseye as tester
ARG GO_VERSION
ARG GO_PACKAGE_SHA256
ARG KUBEBUILDER_VERSION
ARG TARGETARCH
ENV CGO_ENABLED=0 GOOS=linux GOARCH=$TARGETARCH DEBIAN_FRONTEND=noninteractive
RUN apt-get update && \
apt-get install --no-install-recommends -y curl git-core make && \
apt-get clean all
RUN curl -LO https://dl.google.com/go/go${GO_VERSION}.linux-$TARGETARCH.tar.gz && \
SUM=$(sha256sum go${GO_VERSION}.linux-$TARGETARCH.tar.gz | awk '{print $1}') && \
if [ "${SUM}" != "${GO_PACKAGE_SHA256}" ]; then echo "Failed checksum"; exit 1; fi && \
tar xf go${GO_VERSION}.linux-$TARGETARCH.tar.gz && \
chown -R root:root ./go && \
mv go /usr/local && \
rm go${GO_VERSION}.linux-$TARGETARCH.tar.gz
RUN curl -L -o kubebuilder https://go.kubebuilder.io/dl/${KUBEBUILDER_VERSION}/$(go env GOOS)/$(go env GOARCH) \
&& install kubebuilder /usr/local/bin/kubebuilder \
&& /usr/local/go/bin/go install sigs.k8s.io/controller-tools/cmd/[email protected]
ENV PATH="/usr/local/go/bin:${PATH}:/root/go/bin" GOPATH="/root/go"
WORKDIR /root/go/src/github.com/ForgeRock/secret-agent
CMD ["bash"]
# Build the manager binary
FROM golang:${GO_VERSION}-alpine as builder
WORKDIR /workspace
# Copy the Go Modules manifests
COPY go.mod go.sum ./
# cache deps before building and copying source so that we don't need to re-download as much
# and so that source changes don't invalidate our downloaded layer
RUN go mod download
# Copy the go source
COPY . .
# Build with "-s -w" linker flags to omit the symbol table, debug information and the DWARF table
RUN CGO_ENABLED=0 GOOS=linux GOARCH=$TARGETARCH GO111MODULE=on go build -ldflags "-s -w" -a -o manager main.go
# 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
# WORKDIR /
# COPY --from=builder /workspace/manager .
# USER nonroot:nonroot
# ENTRYPOINT ["/manager"]
FROM openjdk:23-ea-15-jdk-slim-bullseye as release
RUN apt-get update && \
DEBIAN_FRONTEND=noninteractive apt-get install --no-install-recommends -y lsof net-tools && \
apt-get clean all
RUN addgroup --gid 11111 secret-agent && \
adduser --shell /bin/bash --home /home/secret-agent --uid 11111 --disabled-password --ingroup root --gecos secret-agent secret-agent && \
chown -R secret-agent:root /home/secret-agent
WORKDIR /opt/gen
COPY --from=builder --chown=secret-agent:root /workspace/manager /
USER 11111
CMD ["bash"]