Skip to content

Commit a21d436

Browse files
committed
make: use Docker named volumes for ~21x faster local linting
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
1 parent cb3991e commit a21d436

File tree

1 file changed

+26
-4
lines changed

1 file changed

+26
-4
lines changed

Makefile

Lines changed: 26 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -68,12 +68,28 @@ ifneq ($(workers),)
6868
LINT_WORKERS = --concurrency=$(workers)
6969
endif
7070

71+
# Docker cache mounting strategy:
72+
# - CI (GitHub Actions): Use bind mounts to host paths that GA caches persist.
73+
# - Local: Use Docker named volumes (much faster on macOS/Windows due to
74+
# avoiding slow host-syncing overhead).
75+
# Paths inside container must match GOCACHE/GOMODCACHE in tools/Dockerfile.
76+
ifdef CI
77+
# CI mode: bind mount to host paths that GitHub Actions caches.
7178
DOCKER_TOOLS = docker run \
7279
--rm \
73-
-v $(shell bash -c "$(GOCC) env GOCACHE || (mkdir -p /tmp/go-cache; echo /tmp/go-cache)"):/tmp/build/.cache \
74-
-v $(shell bash -c "$(GOCC) env GOMODCACHE || (mkdir -p /tmp/go-modcache; echo /tmp/go-modcache)"):/tmp/build/.modcache \
75-
-v $(shell bash -c "mkdir -p /tmp/go-lint-cache; echo /tmp/go-lint-cache"):/root/.cache/golangci-lint \
80+
-v $${HOME}/.cache/go-build:/tmp/build/.cache \
81+
-v $${HOME}/go/pkg/mod:/tmp/build/.modcache \
82+
-v $${HOME}/.cache/golangci-lint:/root/.cache/golangci-lint \
7683
-v $$(pwd):/build lnd-tools
84+
else
85+
# Local mode: Docker named volumes for fast macOS/Windows performance.
86+
DOCKER_TOOLS = docker run \
87+
--rm \
88+
-v lnd-go-build-cache:/tmp/build/.cache \
89+
-v lnd-go-mod-cache:/tmp/build/.modcache \
90+
-v lnd-go-lint-cache:/root/.cache/golangci-lint \
91+
-v $$(pwd):/build lnd-tools
92+
endif
7793

7894
GREEN := "\\033[0;32m"
7995
NC := "\\033[0m"
@@ -472,6 +488,11 @@ clean-mobile:
472488
$(RM) -r mobile/build
473489
$(RM) mobile/*_generated.go
474490

491+
#? clean-docker-volumes: Remove Docker cache volumes used for local development
492+
clean-docker-volumes:
493+
@$(call print, "Removing Docker cache volumes.")
494+
docker volume rm lnd-go-build-cache lnd-go-mod-cache lnd-go-lint-cache 2>/dev/null || true
495+
475496
.PHONY: all \
476497
btcd \
477498
default \
@@ -500,4 +521,5 @@ clean-mobile:
500521
ios \
501522
android \
502523
mobile \
503-
clean
524+
clean \
525+
clean-docker-volumes

0 commit comments

Comments
 (0)