From 27898589131a7d0d5220facc3b4aa70b9c82bd72 Mon Sep 17 00:00:00 2001 From: Tiger Kaovilai Date: Thu, 14 Nov 2024 13:35:14 -0500 Subject: [PATCH] break up velero-builder stage to allow more concurrent layer builds. Signed-off-by: Tiger Kaovilai --- Dockerfile | 24 +++++++++++++++--------- 1 file changed, 15 insertions(+), 9 deletions(-) diff --git a/Dockerfile b/Dockerfile index b493c6662d..7a041e8349 100644 --- a/Dockerfile +++ b/Dockerfile @@ -13,7 +13,7 @@ # limitations under the License. # Velero binary build section -FROM --platform=$BUILDPLATFORM golang:1.22-bookworm AS velero-builder +FROM --platform=$BUILDPLATFORM golang:1.22-bookworm AS velero-builder-base ARG GOPROXY ARG BIN @@ -41,13 +41,15 @@ RUN go mod download COPY . /go/src/github.com/vmware-tanzu/velero -RUN mkdir -p /output/usr/bin && \ - export GOARM=$( echo "${GOARM}" | cut -c2-) && \ - go build -o /output/${BIN} \ - -ldflags "${LDFLAGS}" ${PKG}/cmd/${BIN} && \ - go build -o /output/velero-helper \ - -ldflags "${LDFLAGS}" ${PKG}/cmd/velero-helper && \ - go clean -modcache -cache +RUN mkdir -p /output/usr/bin + +FROM velero-builder-base AS velero-builder-helper +RUN GOARM=$( echo "${GOARM}" | cut -c2-) go build -o /output/velero-helper \ +-ldflags "${LDFLAGS}" ${PKG}/cmd/velero-helper + +FROM velero-builder-base AS velero-builder +RUN GOARM=$( echo "${GOARM}" | cut -c2-) go build -o /output/${BIN} \ + -ldflags "${LDFLAGS}" ${PKG}/cmd/${BIN} # Restic binary build section FROM --platform=$BUILDPLATFORM golang:1.22-bookworm AS restic-builder @@ -66,6 +68,9 @@ ENV CGO_ENABLED=0 \ GOARCH=${TARGETARCH} \ GOARM=${TARGETVARIANT} +# /output dir needed by last stage to copy even when BIN is not velero +RUN mkdir -p /output/usr/bin + # cache go mod download before applying patches RUN --mount=type=cache,target=/go/pkg/mod if [ "${BIN}" = "velero" ]; then \ mkdir -p /build/restic && \ @@ -79,7 +84,6 @@ COPY hack/fix_restic_cve.txt /go/src/github.com/vmware-tanzu/velero/hack/ # cache go mod download after applying patches RUN --mount=type=cache,target=/go/pkg/mod if [ "${BIN}" = "velero" ]; then \ - mkdir -p /output/usr/bin && \ cd /build/restic && \ git apply /go/src/github.com/vmware-tanzu/velero/hack/fix_restic_cve.txt && \ go mod download; \ @@ -99,6 +103,8 @@ LABEL maintainer="Xun Jiang " COPY --from=velero-builder /output / +COPY --from=velero-builder-helper /output / + COPY --from=restic-builder /output / USER cnb:cnb