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
This commit is contained in:
Volodymyr Zotov
2025-07-10 16:36:40 -05:00
parent 285066139f
commit 583b8251d8
2 changed files with 4 additions and 2 deletions

View File

@@ -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\"" \

View File

@@ -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.