44# * instance plugin
55# Both components are built before going into a distroless container
66
7+ # Build the manager binary
8+ FROM --platform=$BUILDPLATFORM golang:1.23.1 AS gobuilder
9+ ARG TARGETOS
10+ ARG TARGETARCH
11+
12+ WORKDIR /workspace
13+ # Copy the Go Modules manifests
14+ COPY ../go.mod go.mod
15+ COPY ../go.sum go.sum
16+ # cache deps before building and copying source so that we don't need to re-download as much
17+ # and so that source changes don't invalidate our downloaded layer
18+ RUN go mod download
19+
20+ # Copy the go source
21+ COPY ../cmd/manager/main.go cmd/manager/main.go
22+ COPY ../api/ api/
23+ COPY ../internal/ internal/
24+
25+ # Build
26+ # the GOARCH has not a default value to allow the binary be built according to the host where the command
27+ # was called. For example, if we call make docker-build in a local env which has the Apple Silicon M1 SO
28+ # the docker BUILDPLATFORM arg will be linux/arm64 when for Apple x86 it will be linux/amd64. Therefore,
29+ # by leaving it empty we can ensure that the container and binary shipped on it will have the same platform.
30+ RUN --mount=type=cache,target=/go/pkg/mod --mount=type=cache,target=/root/.cache/go-build \
31+ CGO_ENABLED=0 GOOS=${TARGETOS:-linux} GOARCH=${TARGETARCH} go build -a -o manager cmd/manager/main.go
32+
733# Build barman-cloud
834# pip will build everything inside /usr/ since this is the case
935# we should build and then copy every file into a destination that will
@@ -19,17 +45,6 @@ RUN mkdir /new-usr/ && \
1945 cp -r --parents /usr/local/lib/ /usr/lib/*-linux-gnu/ /usr/local/bin/ \
2046 /new-usr/
2147
22- # Build instance
23- # This step builds a simple instance app that will manage and handle
24- # the barman-cloud commands inside the sidecar
25- FROM --platform=$BUILDPLATFORM golang:1.23.1 AS gobuilder
26- ENV CGO_ENABLED=0
27- COPY .. /src
28- ARG TARGETOS
29- ARG TARGETARCH
30- RUN --mount=type=cache,target=/go/pkg/mod --mount=type=cache,target=/root/.cache/go-build \
31- GOOS=$TARGETOS GOARCH=$TARGETARCH go build -C /src -o /build/instance /src/cmd/instance/main.go
32-
3348# Joint process
3449# Now we put everything that was build from the origin into our
3550# distroless container
@@ -49,6 +64,6 @@ LABEL summary="$SUMMARY" \
4964 release="1"
5065
5166COPY --from=pythonbuilder /new-usr/* /usr/
52- COPY --from=gobuilder /build/instance /usr/local/bin/instance
67+ COPY --from=gobuilder /workspace/manager /manager
5368USER 26:26
54- ENTRYPOINT ["/usr/local/bin/instance "]
69+ ENTRYPOINT ["/manager "]
0 commit comments