-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMakefile
More file actions
156 lines (127 loc) · 5.39 KB
/
Copy pathMakefile
File metadata and controls
156 lines (127 loc) · 5.39 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
.PHONY: help install dev test lint format clean build docker-build docker-login docker-push docker-pull docker-run run check check-all commit-changes release venv postgres-up postgres-down local-up local-down
# Force use of bash shell (required for make to work properly with line continuations)
SHELL := /bin/bash
.SHELLFLAGS := -o pipefail -c
# Use venv Python if available, otherwise fall back to system python
PYTHON := $(shell [ -d venv ] && echo venv/bin/python3 || echo python3)
PIP := $(shell [ -d venv ] && echo venv/bin/pip || echo pip)
PYTEST := $(shell [ -d venv ] && echo venv/bin/pytest || echo pytest)
RUFF := $(shell [ -d venv ] && echo venv/bin/ruff || echo ruff)
BLACK := $(shell [ -d venv ] && echo venv/bin/black || echo black)
MYPY := $(shell [ -d venv ] && echo venv/bin/mypy || echo mypy)
APP_NAME := high-command-api
PORT := 5000
help:
@echo "High Command API - Helldivers 2 FastAPI Server"
@echo ""
@echo "Available targets:"
@echo " venv Create virtual environment"
@echo " install Install dependencies"
@echo " dev Install development dependencies and run with reload"
@echo " run Run the API server (requires DATABASE_URL; use postgres-up first for local)"
@echo " postgres-up Start local PostgreSQL in Docker (port 5432)"
@echo " postgres-down Stop local PostgreSQL"
@echo " local-up Start Postgres then run API (local development)"
@echo " local-down Stop Postgres"
@echo " test Run tests with coverage"
@echo " test-fast Run tests without coverage"
@echo " lint Run linters (ruff, mypy)"
@echo " format Format code with black and ruff"
@echo " clean Remove build artifacts and cache files"
@echo " docker-build Build Docker image"
@echo " docker-login Login to Harbor registry (requires HARBOR_USERNAME and HARBOR_PASSWORD)"
@echo " docker-push Build and push image to Harbor registry"
@echo " docker-pull Pull image from Harbor registry"
@echo " docker-run Run Docker container"
@echo " check Run linters and tests"
@echo " check-all Format, lint, and test (quality gate)"
@echo " commit-changes Git add, commit, and status"
@echo " release Format, lint, test, and prepare release"
@echo " help Show this help message"
venv:
python3 -m venv venv
venv/bin/pip install --upgrade pip setuptools wheel
install: venv
$(PIP) install -e .
dev: venv
$(PIP) install -e ".[dev]"
$(PYTHON) -m uvicorn src.app:app --reload --port $(PORT)
run: venv
$(PYTHON) -m uvicorn src.app:app --host 0.0.0.0 --port $(PORT)
# Local PostgreSQL for development (docker compose)
postgres-up:
docker compose up -d postgres
@echo "Waiting for Postgres to be ready..."
@until docker compose exec -T postgres pg_isready -U helldivers -d helldivers2 2>/dev/null; do sleep 1; done
@echo "Postgres is ready. Set DATABASE_URL=postgresql://helldivers:helldivers@localhost:5432/helldivers2 (see .env.example) and run: make run"
postgres-down:
docker compose stop postgres
local-up: postgres-up venv
@echo "Starting API with local Postgres..."
@DATABASE_URL=$${DATABASE_URL:-postgresql://helldivers:helldivers@localhost:5432/helldivers2} $(PYTHON) -m uvicorn src.app:app --host 0.0.0.0 --port $(PORT)
local-down: postgres-down
test:
$(PYTEST)
test-fast:
$(PYTEST) --no-cov -q
lint:
$(RUFF) check src tests
$(MYPY) src --ignore-missing-imports
format:
$(BLACK) src tests
$(RUFF) check --fix src tests
build: clean
pip install --upgrade pip build
python -m build
clean:
find . -type d -name __pycache__ -exec rm -rf {} + 2>/dev/null || true
find . -type f -name "*.pyc" -delete
find . -type d -name "*.egg-info" -exec rm -rf {} + 2>/dev/null || true
rm -rf build dist .pytest_cache .mypy_cache htmlcov .ruff_cache .coverage
HARBOR_REGISTRY := harbor.dataknife.net
HARBOR_IMAGE := $(HARBOR_REGISTRY)/library/$(APP_NAME)
IMAGE_TAG ?= latest
docker-login:
@echo "Logging into Harbor registry..."
@if [ -z "$$HARBOR_USERNAME" ] || [ -z "$$HARBOR_PASSWORD" ]; then \
echo "Error: HARBOR_USERNAME and HARBOR_PASSWORD must be set"; \
exit 1; \
fi
@echo "$$HARBOR_PASSWORD" | docker login $(HARBOR_REGISTRY) \
-u "$$HARBOR_USERNAME" \
--password-stdin
docker-build:
docker build -t $(APP_NAME):latest .
docker tag $(APP_NAME):latest $(HARBOR_IMAGE):$(IMAGE_TAG)
# Ensure we are logged into Harbor before building/tagging and pushing the image.
docker-push: docker-login docker-build
docker push $(HARBOR_IMAGE):$(IMAGE_TAG)
docker-pull:
docker pull $(HARBOR_IMAGE):$(IMAGE_TAG)
docker tag $(HARBOR_IMAGE):$(IMAGE_TAG) $(APP_NAME):latest
docker-run: docker-build
docker run -it --rm -p $(PORT):5000 $(APP_NAME):latest
check: lint test
check-all: format lint test
commit-changes:
git add .
@read -p "Enter commit message: " msg; git commit -m "$$msg" || true
git status
release: format lint test
@echo "✓ All checks passed. Ready for release."
info:
@echo "High Command API - Project Information"
@echo ""
@echo "Python Version: 3.14.0 (see .python-version)"
@echo "Framework: FastAPI 0.104.1"
@echo "Server: Uvicorn 0.24.0"
@echo "Database: SQLite3"
@echo "Scheduler: APScheduler 3.10.4"
@echo ""
@echo "Quick Start:"
@echo " make install - Install dependencies"
@echo " make dev - Run development server"
@echo " make test - Run tests"
@echo " make lint - Run linters"
@echo " make format - Format code"
@echo ""