-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMakefile
More file actions
124 lines (102 loc) · 4.84 KB
/
Makefile
File metadata and controls
124 lines (102 loc) · 4.84 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
# Makefile for Geospatial Dataset Publishing project
COMPOSE ?= docker compose
PROJECT_NAME := geospatial-dataset-publishing
FRONTEND_DIR := frontend
PYTHON ?= python3
# ----- Container images -----
FRONTEND_IMAGE_LOCAL := local/global-tsunami-risk-map-frontend:latest
FRONTEND_IMAGE_REMOTE := ghcr.io/yejiyang/global-tsunami-risk-map-frontend:latest
BACKEND_IMAGE_LOCAL := geopython-api:latest
BACKEND_IMAGE_REMOTE := ghcr.io/yejiyang/pygeoapi-w-global-tsunami-data:latest
# Utility containers for data processing (avoid local installs)
GDAL_IMAGE := osgeo/gdal:alpine-small-latest
TIPPE_IMAGE := emotionalcities/tippecanoe
# Other flags
LOCAL ?= false # Set to 'true' to build and run with the local frontend image
NOCACHE ?= false # Set to 'true' to force rebuild without cache
# Paths
DATA_DIR := $(CURDIR)/data
.PHONY: help docker-build docker-down docker-logs docker-clean \
docker-up-% docker-rebuild-% frontend-build frontend-serve \
docker-build-frontend docker-run-local docker-run \
hazard-fgb hazard-tiles
.DEFAULT_GOAL := help
help: ## Show this help
@grep -E '^[-a-zA-Z0-9_%]+:.*?## .*$$' $(MAKEFILE_LIST) | sort | \
awk 'BEGIN {FS = ":.*?## "}; {printf "\033[36m%-25s\033[0m %s\n", $$1, $$2}'
# Docker commands
docker-build: ## Build all Docker images
@echo "Building Docker images..."
$(COMPOSE) --project-name $(PROJECT_NAME) build
docker-down: ## Stop all Docker containers
@echo "Stopping Docker containers..."
@if [ "$(LOCAL)" = "true" ]; then \
$(COMPOSE) --project-name $(PROJECT_NAME) --profile local down; \
else \
$(COMPOSE) --project-name $(PROJECT_NAME) down; \
fi
docker-logs: ## View Docker container logs
@echo "Viewing Docker logs..."
$(COMPOSE) --project-name $(PROJECT_NAME) logs -f
docker-clean: ## Remove Docker containers, images, and volumes
@echo "Cleaning Docker resources..."
$(COMPOSE) --project-name $(PROJECT_NAME) down --rmi all --volumes --remove-orphans
# Service-specific commands
docker-rebuild-%: ## Rebuild a specific service without cache
@echo "Rebuilding $* Docker container (no cache)..."
$(COMPOSE) --project-name $(PROJECT_NAME) build --no-cache $*
docker-up-%: ## Start a specific service
@echo "Starting $* Docker container..."
$(COMPOSE) --project-name $(PROJECT_NAME) up -d $*
# Build and run with local or remote frontend image
docker-build-frontend: ## Build local frontend Docker image (use NOCACHE=true to force rebuild)
@echo "Building local frontend Docker image..."
@if [ "$(NOCACHE)" = "true" ]; then \
echo "Building WITHOUT cache..."; \
docker build --no-cache -t $(FRONTEND_IMAGE_LOCAL) ./$(FRONTEND_DIR); \
else \
docker build -t $(FRONTEND_IMAGE_LOCAL) ./$(FRONTEND_DIR); \
fi
# Unified run target (use LOCAL=true to prefer the locally-built frontend image)
docker-run: ## Run the stack (use LOCAL=true for local frontend build, NOCACHE=true to force rebuild)
@if [ "$(LOCAL)" = "true" ]; then \
echo "Building and running with local images..."; \
$(MAKE) docker-build-frontend; \
$(COMPOSE) --project-name $(PROJECT_NAME) --profile local up -d backend-local frontend-local; \
else \
echo "Running with remote images from GitHub..."; \
echo "Pulling latest frontend image..."; \
docker pull $(FRONTEND_IMAGE_REMOTE); \
echo "Pulling latest backend image..."; \
docker pull $(BACKEND_IMAGE_REMOTE); \
$(COMPOSE) --project-name $(PROJECT_NAME) up -d backend frontend; \
fi
# Backwards-compatibility alias
docker-run-local: ## Alias for 'LOCAL=true make docker-run'
@$(MAKE) LOCAL=true docker-run
# Frontend development helpers
frontend-build: ## Build frontend assets
@echo "Building frontend..."
cd $(FRONTEND_DIR) && npm run build
frontend-serve: ## Build and serve frontend locally
@echo "Serving frontend locally on http://localhost:8080"
cd $(FRONTEND_DIR)/src && $(PYTHON) -m http.server 8080
# -----------------------------------------------------------------------------
# Data processing helpers (Hazard dataset)
# -----------------------------------------------------------------------------
# Convert GeoJSON → FlatGeobuf using GDAL inside a lightweight container
hazard-fgb: ## Generate FlatGeobuf for Global Hazard Points via Docker
@echo "[hazard-fgb] Converting GeoJSON to FlatGeobuf (containerised GDAL)…"
docker run --rm -v $(DATA_DIR):/data $(GDAL_IMAGE) \
ogr2ogr -f FlatGeobuf /data/hazard/global-hazard-points.fgb \
/data/hazard/global-hazard-points.geojson -nln GlobalHazardPoints
# Create vector tiles (MVT) with tippecanoe inside a container
hazard-tiles: ## Generate vector tiles for Global Hazard Points via Docker
@echo "[hazard-tiles] Building vector tiles with tippecanoe (containerised)…"
docker run --rm -v $(DATA_DIR):/data $(TIPPE_IMAGE) \
tippecanoe -r1 -pk -pf \
--output-to-directory=/data/tiles/global-hazard/ \
--force --maximum-zoom=15 \
--extend-zooms-if-still-dropping \
--no-tile-compression \
/data/hazard/global-hazard-points.geojson