From 614eafbf1b805edbccbde7857fb77ecc5887d656 Mon Sep 17 00:00:00 2001 From: Souyama Date: Fri, 29 Dec 2023 15:57:51 +0530 Subject: [PATCH] Improve docker image build time through caches (#5316) * Improve build time with build caches Signed-off-by: Souyama * Add to Changelog Signed-off-by: Souyama --------- Signed-off-by: Souyama --- CHANGELOG.md | 1 + Dockerfile | 6 +++++- Dockerfile.adapter | 6 +++++- Dockerfile.webhooks | 6 +++++- 4 files changed, 16 insertions(+), 3 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 9930992301d..96a21d0590a 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -111,6 +111,7 @@ New deprecation(s): - **General**: Fix CVE-2023-45142 in Opentelemetry ([#5089](https://github.com/kedacore/keda/issues/5089)) - **General**: Fix logger in Opentelemetry collector ([#5094](https://github.com/kedacore/keda/issues/5094)) - **General**: Fix lost commit from the newly created utility function ([#5037](https://github.com/kedacore/keda/issues/5037)) +- **General**: Improve docker image build time through caches ([#5316](https://github.com/kedacore/keda/issues/5316)) - **General**: Reduce amount of gauge creations for OpenTelemetry metrics ([#5101](https://github.com/kedacore/keda/issues/5101)) - **General**: Removed not required RBAC permissions ([#5261](https://github.com/kedacore/keda/issues/5261)) - **General**: Support profiling for KEDA components ([#4789](https://github.com/kedacore/keda/issues/4789)) diff --git a/Dockerfile b/Dockerfile index 11c8e58f912..d1cdf69f522 100644 --- a/Dockerfile +++ b/Dockerfile @@ -24,7 +24,11 @@ COPY go.sum go.sum # https://www.docker.com/blog/faster-multi-platform-builds-dockerfile-cross-compilation-guide/ ARG TARGETOS ARG TARGETARCH -RUN VERSION=${BUILD_VERSION} GIT_COMMIT=${GIT_COMMIT} GIT_VERSION=${GIT_VERSION} TARGET_OS=$TARGETOS ARCH=$TARGETARCH make manager +ARG GOCACHE=/root/.cache/go-build +RUN go env -w GOCACHE=${GOCACHE} +RUN --mount=type=cache,target=${GOCACHE} \ + VERSION=${BUILD_VERSION} GIT_COMMIT=${GIT_COMMIT} GIT_VERSION=${GIT_VERSION} TARGET_OS=$TARGETOS ARCH=$TARGETARCH \ + make manager # Use distroless as minimal base image to package the manager binary # Refer to https://github.com/GoogleContainerTools/distroless for more details diff --git a/Dockerfile.adapter b/Dockerfile.adapter index 10ebae4f18e..05fe3c6de3e 100644 --- a/Dockerfile.adapter +++ b/Dockerfile.adapter @@ -24,7 +24,11 @@ COPY go.sum go.sum # https://www.docker.com/blog/faster-multi-platform-builds-dockerfile-cross-compilation-guide/ ARG TARGETOS ARG TARGETARCH -RUN VERSION=${BUILD_VERSION} GIT_COMMIT=${GIT_COMMIT} GIT_VERSION=${GIT_VERSION} TARGET_OS=$TARGETOS ARCH=$TARGETARCH make adapter +ARG GOCACHE=/root/.cache/go-build +RUN go env -w GOCACHE=${GOCACHE} +RUN --mount=type=cache,target=${GOCACHE} \ + VERSION=${BUILD_VERSION} GIT_COMMIT=${GIT_COMMIT} GIT_VERSION=${GIT_VERSION} TARGET_OS=$TARGETOS ARCH=$TARGETARCH \ + make adapter # Use distroless as minimal base image to package the manager binary # Refer to https://github.com/GoogleContainerTools/distroless for more details diff --git a/Dockerfile.webhooks b/Dockerfile.webhooks index b9115c81b48..a982075b033 100644 --- a/Dockerfile.webhooks +++ b/Dockerfile.webhooks @@ -24,7 +24,11 @@ COPY go.sum go.sum # https://www.docker.com/blog/faster-multi-platform-builds-dockerfile-cross-compilation-guide/ ARG TARGETOS ARG TARGETARCH -RUN VERSION=${BUILD_VERSION} GIT_COMMIT=${GIT_COMMIT} GIT_VERSION=${GIT_VERSION} TARGET_OS=$TARGETOS ARCH=$TARGETARCH make webhooks +ARG GOCACHE=/root/.cache/go-build +RUN go env -w GOCACHE=${GOCACHE} +RUN --mount=type=cache,target=${GOCACHE} \ + VERSION=${BUILD_VERSION} GIT_COMMIT=${GIT_COMMIT} GIT_VERSION=${GIT_VERSION} TARGET_OS=$TARGETOS ARCH=$TARGETARCH \ + make webhooks # Use distroless as minimal base image to package the manager binary # Refer to https://github.com/GoogleContainerTools/distroless for more details