Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add clean_docker command and fix local build_docker_image when run with empty cache #22050

Merged
merged 2 commits into from
Mar 22, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 22 additions & 10 deletions Makefile-os
Original file line number Diff line number Diff line change
Expand Up @@ -51,21 +51,33 @@ 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)

.PHONY: clean_docker
clean_docker: ## Clean up docker containers, images, caches, volumes and local cache directories. Use with caution. To restart the app run make initialize_docker after this commandUse with caution.
docker compose down --rmi all --volumes
docker rmi $(DOCKER_TAG) || true
rm -rf $(DOCKER_CACHE_DIR)
rm -rf ./deps/**

.PHONY: initialize_docker
initialize_docker: create_env_file
# Run a fresh container from the base image to install deps. Since /deps is
Expand Down
Loading