From a21d436fb24e467d4e78fa89809623facbebf094 Mon Sep 17 00:00:00 2001 From: Olaoluwa Osuntokun Date: Tue, 2 Dec 2025 19:09:23 -0800 Subject: [PATCH] make: use Docker named volumes for ~21x faster local linting MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit This commit optimizes Docker cache mounting for the linter with a CI-aware strategy: **Local development (macOS/Windows)**: Uses Docker named volumes which keep data inside Docker's native Linux filesystem, avoiding the slow host-syncing overhead of bind mounts. This yields ~21x faster linting on warm cache. **CI (GitHub Actions)**: Uses bind mounts to host paths (`~/.cache/go-build`, `~/go/pkg/mod`) that GitHub Actions already caches via the setup-go action. This ensures CI benefits from cached dependencies across runs. The Makefile detects CI mode via the `CI` environment variable that GitHub Actions sets automatically. Local benchmark results: - Cold run (empty cache): ~2m 28s - Warm run (cached): ~11s (~21x faster) Key improvements in warm runs: - Go packages loading: 1m 58s → 5.6s - Linters execution: 20.5s → 2.7s - Total execution: 2m 20s → 8.6s --- Makefile | 30 ++++++++++++++++++++++++++---- 1 file changed, 26 insertions(+), 4 deletions(-) diff --git a/Makefile b/Makefile index f12cdb379fc..c78e6e9fdf4 100644 --- a/Makefile +++ b/Makefile @@ -68,12 +68,28 @@ ifneq ($(workers),) LINT_WORKERS = --concurrency=$(workers) endif +# Docker cache mounting strategy: +# - CI (GitHub Actions): Use bind mounts to host paths that GA caches persist. +# - Local: Use Docker named volumes (much faster on macOS/Windows due to +# avoiding slow host-syncing overhead). +# Paths inside container must match GOCACHE/GOMODCACHE in tools/Dockerfile. +ifdef CI +# CI mode: bind mount to host paths that GitHub Actions caches. DOCKER_TOOLS = docker run \ --rm \ - -v $(shell bash -c "$(GOCC) env GOCACHE || (mkdir -p /tmp/go-cache; echo /tmp/go-cache)"):/tmp/build/.cache \ - -v $(shell bash -c "$(GOCC) env GOMODCACHE || (mkdir -p /tmp/go-modcache; echo /tmp/go-modcache)"):/tmp/build/.modcache \ - -v $(shell bash -c "mkdir -p /tmp/go-lint-cache; echo /tmp/go-lint-cache"):/root/.cache/golangci-lint \ + -v $${HOME}/.cache/go-build:/tmp/build/.cache \ + -v $${HOME}/go/pkg/mod:/tmp/build/.modcache \ + -v $${HOME}/.cache/golangci-lint:/root/.cache/golangci-lint \ -v $$(pwd):/build lnd-tools +else +# Local mode: Docker named volumes for fast macOS/Windows performance. +DOCKER_TOOLS = docker run \ + --rm \ + -v lnd-go-build-cache:/tmp/build/.cache \ + -v lnd-go-mod-cache:/tmp/build/.modcache \ + -v lnd-go-lint-cache:/root/.cache/golangci-lint \ + -v $$(pwd):/build lnd-tools +endif GREEN := "\\033[0;32m" NC := "\\033[0m" @@ -472,6 +488,11 @@ clean-mobile: $(RM) -r mobile/build $(RM) mobile/*_generated.go +#? clean-docker-volumes: Remove Docker cache volumes used for local development +clean-docker-volumes: + @$(call print, "Removing Docker cache volumes.") + docker volume rm lnd-go-build-cache lnd-go-mod-cache lnd-go-lint-cache 2>/dev/null || true + .PHONY: all \ btcd \ default \ @@ -500,4 +521,5 @@ clean-mobile: ios \ android \ mobile \ - clean + clean \ + clean-docker-volumes