-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMakefile
More file actions
120 lines (100 loc) · 3.81 KB
/
Makefile
File metadata and controls
120 lines (100 loc) · 3.81 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
SHELL := /bin/bash
.SHELLFLAGS := -eu -o pipefail -c
.PHONY: help up down docker-build docker-push run db test coverage typecheck lint check db-migrate db-migration publish ui-% fake-camera
help:
@echo "Targets:"
@echo ""
@echo " Docker:"
@echo " make up Start HomeSec + Postgres"
@echo " make down Stop all services"
@echo " make docker-build Build Docker image"
@echo " make docker-push Push to DockerHub"
@echo ""
@echo " Local dev:"
@echo " make run Run HomeSec locally (requires Postgres)"
@echo " make db Start just Postgres"
@echo " make test Run tests with coverage"
@echo " make coverage Run tests and generate HTML coverage report"
@echo " make typecheck Run mypy"
@echo " make lint Run ruff linter"
@echo " make check Run lint + typecheck + test + ui-check"
@echo " make fake-camera Start a mock ONVIF + RTSP camera (requires ffmpeg, mediamtx)"
@echo ""
@echo " Database:"
@echo " make db-migrate Run migrations"
@echo " make db-migration m=\"description\" Generate new migration"
@echo ""
@echo " Release:"
@echo " make publish Build and upload to PyPI"
@echo ""
@echo " UI proxy:"
@echo " make ui-<target> Run make target in ui/ (example: make ui-api-generate)"
# Config
HOMESEC_CONFIG ?= config/config.yaml
HOMESEC_LOG_LEVEL ?= INFO
DOCKER_IMAGE ?= homesec
DOCKER_TAG ?= latest
DOCKERHUB_USER ?= $(shell echo $${DOCKERHUB_USER:-})
# Docker
up:
docker compose up -d --build
down:
docker compose down
docker-build:
docker build -t $(DOCKER_IMAGE):$(DOCKER_TAG) .
docker-push: docker-build
@if [ -z "$(DOCKERHUB_USER)" ]; then \
echo "Error: DOCKERHUB_USER not set. Run: export DOCKERHUB_USER=yourusername"; \
exit 1; \
fi
docker tag $(DOCKER_IMAGE):$(DOCKER_TAG) $(DOCKERHUB_USER)/$(DOCKER_IMAGE):$(DOCKER_TAG)
docker tag $(DOCKER_IMAGE):$(DOCKER_TAG) $(DOCKERHUB_USER)/$(DOCKER_IMAGE):latest
docker push $(DOCKERHUB_USER)/$(DOCKER_IMAGE):$(DOCKER_TAG)
docker push $(DOCKERHUB_USER)/$(DOCKER_IMAGE):latest
# Local dev
run:
@echo "Running database migrations..."
@uv run alembic -c alembic.ini upgrade head
uv run python -m homesec.cli run --config $(HOMESEC_CONFIG) --log_level $(HOMESEC_LOG_LEVEL)
db:
docker compose up -d postgres
test:
uv run pytest tests/homesec/ -v --cov=homesec --cov-report=term-missing
coverage:
uv run pytest tests/homesec/ -v --cov=homesec --cov-report=html --cov-report=xml
@echo "Coverage report: htmlcov/index.html"
typecheck:
uv run mypy --package homesec --strict
lint:
uv run ruff check src tests
uv run ruff format --check src tests
lint-fix:
uv run ruff check --fix src tests
uv run ruff format src tests
check: lint typecheck test ui-check
fake-camera:
@echo "Starting mock ONVIF server on port 8000..."
@python3 dev/fake-camera/mock_onvif.py &
@echo "Starting RTSP server on port 8099..."
@./mediamtx dev/fake-camera/mediamtx.yml &
@sleep 2
@echo "Streaming media/sample.mp4 to rtsp://localhost:8099/live..."
@ffmpeg -re -stream_loop -1 -i media/sample.mp4 -c copy -f rtsp rtsp://admin:admin123@localhost:8099/live
# Database
db-migrate:
uv run --with alembic --with sqlalchemy --with asyncpg --with python-dotenv alembic -c alembic.ini upgrade head
db-migration:
@if [ -z "$(m)" ]; then \
echo "Error: message required. Run: make db-migration m=\"your description\""; \
exit 1; \
fi
uv run --with alembic --with sqlalchemy --with asyncpg --with python-dotenv alembic -c alembic.ini revision --autogenerate -m "$(m)"
# Release
publish: check
rm -rf dist build
uv run --with build python -m build
uv run --with twine python -m twine check dist/*
uv run --with twine python -m twine upload dist/*
# Proxy any ui-* target to the UI Makefile (e.g., ui-api-generate -> make -C ui api-generate).
ui-%:
@$(MAKE) -C ui $*