Skip to content

Commit

Permalink
break up velero-builder stage to allow more concurrent layer builds.
Browse files Browse the repository at this point in the history
Signed-off-by: Tiger Kaovilai <[email protected]>
  • Loading branch information
kaovilai committed Nov 15, 2024
1 parent c9938f9 commit 2789858
Showing 1 changed file with 15 additions and 9 deletions.
24 changes: 15 additions & 9 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand All @@ -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 && \
Expand All @@ -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; \
Expand All @@ -99,6 +103,8 @@ LABEL maintainer="Xun Jiang <[email protected]>"

COPY --from=velero-builder /output /

COPY --from=velero-builder-helper /output /

COPY --from=restic-builder /output /

USER cnb:cnb
Expand Down

0 comments on commit 2789858

Please sign in to comment.