Adding Dockerfile to create the image. 22/12122/2
authornaman.gupta <naman.gupta@samsung.com>
Mon, 27 Nov 2023 04:53:16 +0000 (10:23 +0530)
committerThoralf Czichy <thoralf.czichy@nokia.com>
Thu, 7 Dec 2023 09:17:57 +0000 (09:17 +0000)
Adding Dockerfile to create the image.

Change-Id: Ia26092f778e8adc24544181e171d684c377483ba
Signed-off-by: naman.gupta <naman.gupta@samsung.com>
depRicKubernetesOperator/Dockerfile

index e69de29..e0309e2 100644 (file)
@@ -0,0 +1,33 @@
+# Build the manager binary\r
+FROM golang:1.20 as builder\r
+ARG TARGETOS\r
+ARG TARGETARCH\r
+\r
+WORKDIR /workspace\r
+# Copy the Go Modules manifests\r
+COPY go.mod go.mod\r
+COPY go.sum go.sum\r
+# cache deps before building and copying source so that we don't need to re-download as much\r
+# and so that source changes don't invalidate our downloaded layer\r
+RUN go mod download\r
+\r
+# Copy the go source\r
+COPY cmd/main.go cmd/main.go\r
+COPY api/ api/\r
+COPY internal/controller/ internal/controller/\r
+\r
+# Build\r
+# the GOARCH has not a default value to allow the binary be built according to the host where the command\r
+# was called. For example, if we call make docker-build in a local env which has the Apple Silicon M1 SO\r
+# the docker BUILDPLATFORM arg will be linux/arm64 when for Apple x86 it will be linux/amd64. Therefore,\r
+# by leaving it empty we can ensure that the container and binary shipped on it will have the same platform.\r
+RUN CGO_ENABLED=0 GOOS=${TARGETOS:-linux} GOARCH=${TARGETARCH} go build -a -o manager cmd/main.go\r
+\r
+# Use distroless as minimal base image to package the manager binary\r
+# Refer to https://github.com/GoogleContainerTools/distroless for more details\r
+FROM gcr.io/distroless/static:nonroot\r
+WORKDIR /\r
+COPY --from=builder /workspace/manager .\r
+USER 65532:65532\r
+\r
+ENTRYPOINT ["/manager"]\r