From 4bd0f2ab632d96e8bcfee2c1ed68bb8d06ee29b4 Mon Sep 17 00:00:00 2001 From: Marco Nenciarini Date: Mon, 28 Oct 2024 09:12:47 +0100 Subject: [PATCH] fix: rebase changes Signed-off-by: Marco Nenciarini --- containers/Dockerfile.plugin | 4 +-- containers/Dockerfile.sidecar | 41 +++++++++++++++++++--------- internal/cnpgi/operator/lifecycle.go | 4 +-- 3 files changed, 32 insertions(+), 17 deletions(-) diff --git a/containers/Dockerfile.plugin b/containers/Dockerfile.plugin index ced9b1b..de932ab 100644 --- a/containers/Dockerfile.plugin +++ b/containers/Dockerfile.plugin @@ -1,5 +1,5 @@ # Build the manager binary -FROM golang:1.23 AS builder +FROM --platform=$BUILDPLATFORM golang:1.23.1 AS gobuilder ARG TARGETOS ARG TARGETARCH @@ -42,7 +42,7 @@ LABEL summary="$SUMMARY" \ release="1" WORKDIR / -COPY --from=builder /workspace/manager . +COPY --from=gobuilder /workspace/manager . USER 65532:65532 ENTRYPOINT ["/manager"] \ No newline at end of file diff --git a/containers/Dockerfile.sidecar b/containers/Dockerfile.sidecar index 6093f94..f369344 100644 --- a/containers/Dockerfile.sidecar +++ b/containers/Dockerfile.sidecar @@ -4,6 +4,32 @@ # * instance plugin # Both components are built before going into a distroless container +# Build the manager binary +FROM --platform=$BUILDPLATFORM golang:1.23.1 AS gobuilder +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/manager/main.go cmd/manager/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 --mount=type=cache,target=/go/pkg/mod --mount=type=cache,target=/root/.cache/go-build \ + CGO_ENABLED=0 GOOS=${TARGETOS:-linux} GOARCH=${TARGETARCH} go build -a -o manager cmd/manager/main.go + # Build barman-cloud # pip will build everything inside /usr/ since this is the case # we should build and then copy every file into a destination that will @@ -19,17 +45,6 @@ RUN mkdir /new-usr/ && \ cp -r --parents /usr/local/lib/ /usr/lib/*-linux-gnu/ /usr/local/bin/ \ /new-usr/ -# Build instance -# This step builds a simple instance app that will manage and handle -# the barman-cloud commands inside the sidecar -FROM --platform=$BUILDPLATFORM golang:1.23.1 AS gobuilder -ENV CGO_ENABLED=0 -COPY .. /src -ARG TARGETOS -ARG TARGETARCH -RUN --mount=type=cache,target=/go/pkg/mod --mount=type=cache,target=/root/.cache/go-build \ - GOOS=$TARGETOS GOARCH=$TARGETARCH go build -C /src -o /build/instance /src/cmd/instance/main.go - # Joint process # Now we put everything that was build from the origin into our # distroless container @@ -49,6 +64,6 @@ LABEL summary="$SUMMARY" \ release="1" COPY --from=pythonbuilder /new-usr/* /usr/ -COPY --from=gobuilder /build/instance /usr/local/bin/instance +COPY --from=gobuilder /workspace/manager /manager USER 26:26 -ENTRYPOINT ["/usr/local/bin/instance"] +ENTRYPOINT ["/manager"] diff --git a/internal/cnpgi/operator/lifecycle.go b/internal/cnpgi/operator/lifecycle.go index 34ca43f..3406df6 100644 --- a/internal/cnpgi/operator/lifecycle.go +++ b/internal/cnpgi/operator/lifecycle.go @@ -231,8 +231,8 @@ func reconcilePodSpec( sidecarConfig.Name = "plugin-barman-cloud" sidecarConfig.Image = viper.GetString("sidecar-image") sidecarConfig.ImagePullPolicy = cluster.Spec.ImagePullPolicy - sidecarConfig.Command= []string{ - "/usr/local/bin/instance", + sidecarConfig.Command = []string{ + "/manager", } // merge the main container envs if they aren't already set