Skip to content

Commit

Permalink
Fix local build, only use cache-from if index.json exists
Browse files Browse the repository at this point in the history
  • Loading branch information
KevinMind committed Mar 21, 2024
1 parent 4e184fc commit 0d4392d
Showing 1 changed file with 15 additions and 10 deletions.
25 changes: 15 additions & 10 deletions Makefile-os
Original file line number Diff line number Diff line change
Expand Up @@ -51,18 +51,23 @@ create_docker_builder: ## Create a custom builder for buildkit to efficiently bu
--name $(DOCKER_BUILDER) \
--driver=docker-container

DOCKER_BUILD_ARGS := -t $(DOCKER_TAG) \
--load \
--platform $(DOCKER_PLATFORM) \
--progress=$(DOCKER_PROGRESS) \
--builder=$(DOCKER_BUILDER) \
--label git.commit=$(DOCKER_COMMIT) \
--cache-to=type=local,dest=$(DOCKER_CACHE_DIR)-new \

DOCKER_CACHE_INDEX = $(wildcard $(DOCKER_CACHE_DIR)/index.json)

ifneq ($(DOCKER_CACHE_INDEX),)
DOCKER_BUILD_ARGS += --cache-from=type=local,src=$(DOCKER_CACHE_DIR),mode=max
endif

.PHONY: build_docker_image
build_docker_image: create_docker_builder ## Build the docker image
DOCKER_BUILDKIT=1 docker buildx build \
-t $(DOCKER_TAG) \
--load \
--platform $(DOCKER_PLATFORM) \
--progress=$(DOCKER_PROGRESS) \
--cache-to=type=local,dest=$(DOCKER_CACHE_DIR)-new \
--cache-from=type=local,src=$(DOCKER_CACHE_DIR),mode=max \
--builder=$(DOCKER_BUILDER) \
--label git.commit=$(DOCKER_COMMIT) \
.
DOCKER_BUILDKIT=1 docker buildx build $(DOCKER_BUILD_ARGS) .
rm -rf $(DOCKER_CACHE_DIR)
mv $(DOCKER_CACHE_DIR)-new $(DOCKER_CACHE_DIR)

Expand Down

0 comments on commit 0d4392d

Please sign in to comment.