From 583b8251d88cd9725b00fd87ccd9246e002263da Mon Sep 17 00:00:00 2001 From: Volodymyr Zotov Date: Thu, 10 Jul 2025 16:36:40 -0500 Subject: [PATCH] Enable Docker BuildKit for chaching dependencies and faster builds After enabling it with DOCKER_BUILDKIT=1, it allows to use features like caching(--mount=type=cache) and parallel layer execution which increses speed of concurent builds which is great for local development --- Dockerfile | 4 +++- Makefile | 2 +- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/Dockerfile b/Dockerfile index 2854e52..7de8802 100644 --- a/Dockerfile +++ b/Dockerfile @@ -23,7 +23,9 @@ COPY version/ version/ # 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 CGO_ENABLED=0 \ +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 \ -ldflags "-X \"github.com/1Password/onepassword-operator/version.Version=$operator_version\"" \ diff --git a/Makefile b/Makefile index 866f7c5..2b9f5e8 100644 --- a/Makefile +++ b/Makefile @@ -132,7 +132,7 @@ run: manifests generate fmt vet ## Run a controller from your host. # More info: https://docs.docker.com/develop/develop-images/build_enhancements/ .PHONY: docker-build docker-build: test ## Build docker image with the manager. - $(CONTAINER_TOOL) build -t ${IMG} . + DOCKER_BUILDKIT=1 $(CONTAINER_TOOL) build -t ${IMG} . .PHONY: docker-push docker-push: ## Push docker image with the manager.