-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathMakefile
More file actions
197 lines (170 loc) · 6.19 KB
/
Makefile
File metadata and controls
197 lines (170 loc) · 6.19 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
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
.PHONY: up down clean-volumes help test setup clean-env lint
# Default target
.DEFAULT_GOAL := help
# =============================================================================
# Configuration Variables
# =============================================================================
# Configuration file path (can be overridden: make up config=config/custom.yaml)
config ?= ./config/default.yaml
# Build flag - set to 'true' to rebuild images without cache
# Usage: make up build=true
build ?= false
# Virtual environment detection
VENV := .venv
PYTHON := $(VENV)/bin/python
PYTEST := $(VENV)/bin/pytest
UV := $(shell command -v uv 2> /dev/null)
# =============================================================================
# Core Commands
# =============================================================================
## up: Start OpenDT services (use build=true to rebuild images)
up: clean-volumes
@echo ""
@echo "Starting OpenDT..."
@echo "Config: $(config)"
@echo ""
@if [ ! -f "$(config)" ]; then \
echo "Error: Config file not found: $(config)"; \
exit 1; \
fi
@$(PYTHON) scripts/opendt_cli.py init --config $(config)
@RUN_ID=$$(cat .run_id) && \
if [ ! -f "data/$$RUN_ID/.env" ]; then \
echo "Error: data/$$RUN_ID/.env not found after initialization"; \
exit 1; \
fi && \
set -a && . ./data/$$RUN_ID/.env && set +a && \
if [ "$(build)" = "true" ]; then \
echo "Rebuilding Docker images..."; \
docker compose $$PROFILE_FLAG build --no-cache; \
fi && \
echo "Starting containers..." && \
docker compose $$PROFILE_FLAG up -d
@echo ""
@echo "Services started:"
@echo " Dashboard http://localhost:3000"
@echo " API http://localhost:3001"
@echo ""
@echo "View logs with: make logs-<service>"
@echo ""
## down: Stop all containers
down:
@echo ""
@echo "Stopping OpenDT services..."
@RUN_ID=$$(cat .run_id 2>/dev/null || true); \
if [ -n "$$RUN_ID" ] && [ -f "data/$$RUN_ID/.env" ]; then \
set -a && . ./data/$$RUN_ID/.env && set +a && docker compose $$PROFILE_FLAG down; \
else \
docker compose down; \
fi
@echo "Done."
@echo ""
## clean-volumes: Stop containers and delete all persistent volumes
clean-volumes:
@RUN_ID=$$(cat .run_id 2>/dev/null || true); \
if [ -n "$$RUN_ID" ] && [ -f "data/$$RUN_ID/.env" ]; then \
set -a && . ./data/$$RUN_ID/.env && set +a && docker compose $$PROFILE_FLAG down -v 2>/dev/null || true; \
else \
docker compose down -v 2>/dev/null || true; \
fi
@docker volume rm opendt-kafka-data 2>/dev/null || true
@docker volume rm opendt-grafana-storage 2>/dev/null || true
# =============================================================================
# Development Commands
# =============================================================================
## setup: Create virtual environment and install dependencies
setup:
@echo ""
@echo "Setting up development environment..."
@if [ -z "$(UV)" ]; then \
echo "Error: uv not found. Install with: curl -LsSf https://astral.sh/uv/install.sh | sh"; \
exit 1; \
fi
@echo "Creating virtual environment..."
@uv venv
@echo "Installing dependencies..."
@uv pip install -e libs/common
@uv pip install -e "libs/common[test]"
@uv pip install -e ".[dev]"
@echo ""
@echo "Done. Activate with: source .venv/bin/activate"
@echo ""
## test: Run tests
test:
@echo ""
@echo "Running tests..."
@if [ ! -d "$(VENV)" ]; then \
echo "Virtual environment not found. Running setup..."; \
$(MAKE) setup; \
fi
@if [ ! -f "$(PYTEST)" ]; then \
echo "pytest not found. Running setup..."; \
$(MAKE) setup; \
fi
@$(PYTEST) libs/common/tests/ -v --tb=short
@echo ""
@echo "All tests passed."
@echo ""
# Lint fix flag - set to 'true' to auto-fix issues
# Usage: make lint fix=true
fix ?= false
## lint: Run Ruff linter (use fix=true to auto-fix)
lint:
@echo ""
@echo "Running Ruff linter..."
@if [ "$(fix)" = "true" ]; then \
uv run ruff check . --fix; \
uv run ruff format .; \
else \
uv run ruff check .; \
fi
@echo ""
## clean-env: Remove virtual environment
clean-env:
@echo ""
@echo "Removing virtual environment..."
@rm -rf $(VENV)
@rm -rf .uv
@echo "Done."
@echo ""
# =============================================================================
# Logging Commands
# =============================================================================
## logs-api: Tail logs for api service
logs-api:
@RUN_ID=$$(cat .run_id) && set -a && . ./data/$$RUN_ID/.env && set +a && docker compose logs -f api
## logs-dc-mock: Tail logs for dc-mock service
logs-dc-mock:
@RUN_ID=$$(cat .run_id) && set -a && . ./data/$$RUN_ID/.env && set +a && docker compose logs -f dc-mock
## logs-simulator: Tail logs for simulator service
logs-simulator:
@RUN_ID=$$(cat .run_id) && set -a && . ./data/$$RUN_ID/.env && set +a && docker compose logs -f simulator
## logs-calibrator: Tail logs for calibrator service
logs-calibrator:
@RUN_ID=$$(cat .run_id) && set -a && . ./data/$$RUN_ID/.env && set +a && docker compose --profile calibration logs -f calibrator
# =============================================================================
# Shell Commands
# =============================================================================
## shell-api: Open a shell in the api container
shell-api:
@RUN_ID=$$(cat .run_id) && set -a && . ./data/$$RUN_ID/.env && set +a && docker compose exec api /bin/bash
## shell-dc-mock: Open a shell in the dc-mock container
shell-dc-mock:
@RUN_ID=$$(cat .run_id) && set -a && . ./data/$$RUN_ID/.env && set +a && docker compose exec dc-mock /bin/bash
## shell-simulator: Open a shell in the simulator container
shell-simulator:
@RUN_ID=$$(cat .run_id) && set -a && . ./data/$$RUN_ID/.env && set +a && docker compose exec simulator /bin/bash
## shell-calibrator: Open a shell in the calibrator container
shell-calibrator:
@RUN_ID=$$(cat .run_id) && set -a && . ./data/$$RUN_ID/.env && set +a && docker compose --profile calibration exec calibrator /bin/bash
# =============================================================================
# Help
# =============================================================================
## help: Show available commands
help:
@echo ""
@echo "OpenDT Commands"
@echo "==============="
@echo ""
@sed -n 's/^##//p' ${MAKEFILE_LIST} | column -t -s ':' | sed -e 's/^/ /'
@echo ""