getting started with kubebuilder
This commit is contained in:
61
Dockerfile
61
Dockerfile
@ -1,35 +1,38 @@
|
||||
FROM alpine:3.20.3
|
||||
# Build the manager binary
|
||||
FROM docker.io/golang:1.23 AS builder
|
||||
ARG TARGETOS
|
||||
ARG TARGETARCH
|
||||
|
||||
WORKDIR /workspace
|
||||
# Copy the Go Modules manifests
|
||||
COPY go.mod go.mod
|
||||
COPY go.sum 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 cmd/main.go cmd/main.go
|
||||
COPY api/ api/
|
||||
COPY internal/ internal/
|
||||
|
||||
# Build
|
||||
# the GOARCH has not a default value to allow the binary be built according to the host where the command
|
||||
# was called. For example, if we call make docker-build in a local env which has the Apple Silicon M1 SO
|
||||
# the docker BUILDPLATFORM arg will be linux/arm64 when for Apple x86 it will be linux/amd64. Therefore,
|
||||
# by leaving it empty we can ensure that the container and binary shipped on it will have the same platform.
|
||||
RUN CGO_ENABLED=0 GOOS=${TARGETOS:-linux} GOARCH=${TARGETARCH} go build -a -o manager cmd/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
|
||||
|
||||
LABEL org.opencontainers.image.source=https://github.com/Lerentis/bitwarden-crd-operator
|
||||
LABEL org.opencontainers.image.description="Kubernetes Operator to create k8s secrets from bitwarden"
|
||||
LABEL org.opencontainers.image.licenses=MIT
|
||||
|
||||
ARG PYTHON_VERSION=3.12.6-r0
|
||||
ARG PIP_VERSION=24.0-r2
|
||||
ARG GCOMPAT_VERSION=1.1.0-r4
|
||||
ARG LIBCRYPTO_VERSION=3.3.2-r0
|
||||
ARG BW_VERSION=2024.7.2
|
||||
ARG NODE_VERSION=20.15.1-r0
|
||||
WORKDIR /
|
||||
COPY --from=builder /workspace/manager .
|
||||
USER 65532:65532
|
||||
|
||||
COPY requirements.txt /requirements.txt
|
||||
|
||||
RUN set -eux; \
|
||||
apk update; \
|
||||
apk del nodejs-current; \
|
||||
apk add nodejs=${NODE_VERSION} npm; \
|
||||
npm install -g @bitwarden/cli@${BW_VERSION}; \
|
||||
addgroup -S -g 1000 bw-operator; \
|
||||
adduser -S -D -u 1000 -G bw-operator bw-operator; \
|
||||
mkdir -p /home/bw-operator; \
|
||||
chown -R bw-operator /home/bw-operator; \
|
||||
apk add gcc musl-dev libstdc++ gcompat=${GCOMPAT_VERSION} python3=${PYTHON_VERSION} py3-pip=${PIP_VERSION} libcrypto3=${LIBCRYPTO_VERSION}; \
|
||||
pip install -r /requirements.txt --no-warn-script-location --break-system-packages; \
|
||||
rm /requirements.txt; \
|
||||
apk del --purge gcc musl-dev libstdc++;
|
||||
|
||||
COPY --chown=bw-operator:bw-operator src /home/bw-operator
|
||||
|
||||
USER bw-operator
|
||||
|
||||
ENTRYPOINT [ "kopf", "run", "--log-format=json", "--all-namespaces", "--liveness=http://0.0.0.0:8080/healthz" ]
|
||||
CMD [ "/home/bw-operator/bitwardenCrdOperator.py", "/home/bw-operator/kv.py", "/home/bw-operator/dockerlogin.py", "/home/bw-operator/template.py"]
|
||||
ENTRYPOINT ["/manager"]
|
||||
|
Reference in New Issue
Block a user