Skip to content

Commit 31a333c

Browse files
authored
refactor: simplify Makefile (#35)
1 parent 6222268 commit 31a333c

1 file changed

Lines changed: 28 additions & 49 deletions

File tree

Makefile

Lines changed: 28 additions & 49 deletions
Original file line numberDiff line numberDiff line change
@@ -3,91 +3,70 @@
33
COMPOSE ?= docker compose
44
FRONTEND_DIR := frontend
55
PYTHON ?= python3
6+
FRONTEND_IMAGE_LOCAL := local/global-tsunami-risk-map-frontend:latest
7+
FRONTEND_IMAGE_REMOTE := ghcr.io/yejiyang/global-tsunami-risk-map-frontend:latest
68

7-
.PHONY: help docker-build docker-up docker-down docker-logs docker-clean docker-rebuild-frontend docker-up-frontend docker-up-backend docker-rebuild-backend frontend-build frontend-serve docker-build-frontend docker-run-local docker-run
9+
.PHONY: help docker-build docker-up docker-down docker-logs docker-clean \
10+
docker-up-% docker-rebuild-% frontend-build frontend-serve \
11+
docker-build-frontend docker-run-local docker-run
812

913
.DEFAULT_GOAL := help
1014

11-
help:
12-
@echo "Geospatial Dataset Publishing Project"
13-
@echo ""
14-
@echo "Docker Commands:"
15-
@echo " docker-build - Build all Docker images"
16-
@echo " docker-up - Start all Docker containers"
17-
@echo " docker-down - Stop all Docker containers"
18-
@echo " docker-logs - View Docker container logs"
19-
@echo " docker-clean - Remove Docker containers, images, and volumes"
20-
@echo " docker-rebuild-backend - Rebuild backend container (no cache)"
21-
@echo " docker-rebuild-frontend - Rebuild frontend container (no cache)"
22-
@echo " docker-up-frontend - Start only the frontend container"
23-
@echo " docker-up-backend - Start only the backend container"
24-
@echo " docker-build-frontend - Build local frontend Docker image"
25-
@echo " docker-run-local - Run with locally built frontend image"
26-
@echo " docker-run - Run with remote frontend image from GitHub"
27-
@echo ""
28-
@echo "Frontend Commands:"
29-
@echo " frontend-build - Build frontend assets"
30-
@echo " frontend-serve - Build and serve frontend locally"
15+
help: ## Show this help
16+
@grep -E '^[-a-zA-Z0-9_%]+:.*?## .*$$' $(MAKEFILE_LIST) | sort | \
17+
awk 'BEGIN {FS = ":.*?## "}; {printf "\033[36m%-25s\033[0m %s\n", $$1, $$2}'
3118

3219

3320
# Docker commands
34-
docker-build:
21+
docker-build: ## Build all Docker images
3522
@echo "Building Docker images..."
3623
$(COMPOSE) build
3724

38-
docker-up:
25+
docker-up: ## Start all Docker containers
3926
@echo "Starting Docker containers..."
4027
$(COMPOSE) up -d
4128

42-
docker-down:
29+
docker-down: ## Stop all Docker containers
4330
@echo "Stopping Docker containers..."
4431
$(COMPOSE) down
4532

46-
docker-logs:
33+
docker-logs: ## View Docker container logs
4734
@echo "Viewing Docker logs..."
4835
$(COMPOSE) logs -f
4936

50-
docker-clean:
37+
docker-clean: ## Remove Docker containers, images, and volumes
5138
@echo "Cleaning Docker resources..."
5239
$(COMPOSE) down --rmi all --volumes --remove-orphans
5340

54-
docker-rebuild-frontend:
55-
@echo "Rebuilding frontend Docker container..."
56-
$(COMPOSE) build --no-cache frontend
41+
# Service-specific commands
42+
docker-rebuild-%: ## Rebuild a specific service without cache
43+
@echo "Rebuilding $* Docker container (no cache)..."
44+
$(COMPOSE) build --no-cache $*
5745

58-
docker-up-frontend:
59-
@echo "Starting frontend Docker container..."
60-
$(COMPOSE) up -d frontend
61-
62-
docker-up-backend:
63-
@echo "Starting backend Docker container..."
64-
$(COMPOSE) up -d backend
65-
66-
# Docker backend-specific commands
67-
docker-rebuild-backend:
68-
@echo "Rebuilding backend Docker container (no cache)..."
69-
$(COMPOSE) build --no-cache backend
46+
docker-up-%: ## Start a specific service
47+
@echo "Starting $* Docker container..."
48+
$(COMPOSE) up -d $*
7049

7150
# Build and run with local or remote frontend image
72-
docker-build-frontend:
51+
docker-build-frontend: ## Build local frontend Docker image
7352
@echo "Building local frontend Docker image..."
74-
docker build -t local/global-tsunami-risk-map-frontend:latest ./$(FRONTEND_DIR)
53+
docker build -t $(FRONTEND_IMAGE_LOCAL) ./$(FRONTEND_DIR)
7554

76-
docker-run-local: docker-build-frontend
55+
docker-run-local: docker-build-frontend ## Run with locally built frontend image
7756
@echo "Running with local frontend image..."
78-
USE_LOCAL_BUILD=local/global-tsunami-risk-map-frontend $(COMPOSE) up -d
57+
USE_LOCAL_BUILD=$(FRONTEND_IMAGE_LOCAL) $(COMPOSE) up -d
7958

80-
docker-run:
59+
docker-run: ## Run with remote frontend image from GitHub
8160
@echo "Running with remote frontend image from GitHub..."
8261
@echo "Pulling latest frontend image..."
83-
docker pull ghcr.io/yejiyang/global-tsunami-risk-map-frontend:latest
62+
docker pull $(FRONTEND_IMAGE_REMOTE)
8463
$(COMPOSE) up -d
8564

8665
# Frontend development helpers
87-
frontend-build:
66+
frontend-build: ## Build frontend assets
8867
@echo "Building frontend..."
8968
cd $(FRONTEND_DIR) && npm run build
9069

91-
frontend-serve:
70+
frontend-serve: ## Build and serve frontend locally
9271
@echo "Serving frontend locally on http://localhost:8080"
9372
cd $(FRONTEND_DIR)/src && $(PYTHON) -m http.server 8080

0 commit comments

Comments
 (0)