Skip to content

Commit f3b38f4

Browse files
committed
fix(makefile): add volume management commands for Docker setup
- Introduced `ensure-volumes` target to create necessary bind-mount directories before starting services. - Added `clean-volumes` target to remove created volume directories during cleanup. - Updated `start`, `setup-cluster`, and `setup-cluster2` targets to ensure volumes are created as needed. - Refactored cleanup process to use the new `clean-volumes` target for better organization.
1 parent 1ee610f commit f3b38f4

1 file changed

Lines changed: 24 additions & 2 deletions

File tree

Makefile

Lines changed: 24 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,11 @@ COMPOSE_FILE := docker/docker-compose.yaml
44
COMPOSE_TEST_FILE := docker/docker-compose.test.yaml
55
COMPOSE_CLUSTER2_FILE := docker/docker-compose.cluster2.yaml
66

7-
.PHONY: start stop restart build logs status test api-test portal-test setup-cluster setup-cluster2 clean help lint api-lint portal-lint
7+
VOLUME_DIRS := docker/volumes docker/volumes/postgres docker/volumes/postgres-test docker/volumes/kubeconfig docker/volumes/kubeconfig2 docker/volumes/token
8+
HOST_UID := $(shell id -u)
9+
HOST_GID := $(shell id -g)
10+
11+
.PHONY: start stop restart build logs status test api-test portal-test setup-cluster setup-cluster2 clean help lint api-lint portal-lint ensure-volumes clean-volumes
812

913
help:
1014
@echo "Tron Development Commands:"
@@ -24,7 +28,23 @@ help:
2428
@echo " make api-lint - Run API linter (format then ruff check)"
2529
@echo " make portal-lint - Run Portal linter (eslint + tsc --noEmit)"
2630

31+
# Create bind-mount dirs as the current user before Docker does (as root).
32+
ensure-volumes:
33+
@echo "🧹 Ensuring volumes are created..."
34+
@mkdir -p $(VOLUME_DIRS)
35+
@echo "✅ Volumes created!"
36+
37+
clean-volumes:
38+
@echo "🧹 Cleaning up volumes..."
39+
@if [ -d docker/volumes ]; then \
40+
docker run --rm -v "$(CURDIR)/docker/volumes:/volumes" alpine \
41+
chown -R $(HOST_UID):$(HOST_GID) /volumes; \
42+
fi
43+
@rm -rf $(VOLUME_DIRS)
44+
@echo "✅ Volumes cleaned!"
45+
2746
start:
47+
@make ensure-volumes
2848
@echo "🚀 Starting Tron development environment..."
2949
@$(DOCKER_COMPOSE) -f $(COMPOSE_FILE) up -d
3050
@echo ""
@@ -53,7 +73,7 @@ clean:
5373
@$(DOCKER_COMPOSE) -f $(COMPOSE_FILE) down -v --remove-orphans
5474
@$(DOCKER_COMPOSE) -f $(COMPOSE_TEST_FILE) down -v --remove-orphans 2>/dev/null || true
5575
@$(DOCKER_COMPOSE) -f $(COMPOSE_CLUSTER2_FILE) down -v --remove-orphans 2>/dev/null || true
56-
@rm -rf docker/volumes/postgres docker/volumes/postgres-test docker/volumes/kubeconfig docker/volumes/kubeconfig2 docker/volumes/token
76+
@make clean-volumes
5777
@echo "✅ Cleaned!"
5878

5979
build:
@@ -68,10 +88,12 @@ status:
6888
@$(DOCKER_COMPOSE) -f $(COMPOSE_FILE) ps
6989

7090
setup-cluster:
91+
@make ensure-volumes
7192
@echo "🔧 Setting up local k3s cluster..."
7293
@cd docker && ./scripts/setup-k3s-cluster.sh 2>/dev/null || ../scripts/setup-k3s-cluster.sh
7394

7495
setup-cluster2:
96+
@make ensure-volumes
7597
@echo "🔧 Setting up k3s cluster2..."
7698
@$(DOCKER_COMPOSE) -f $(COMPOSE_CLUSTER2_FILE) up -d
7799
@sleep 5

0 commit comments

Comments
 (0)