Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/docker-compose.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ jobs:
run: pip install -r tests/requirements.txt

- name: launch tests
run: pytest tests/*
run: pytest tests --ignore=tests/e2e

- name: Capture logs
if: always()
Expand Down
4 changes: 4 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,10 @@ data/images/
data/models/
# Written by init_script at the end of a successful run
data/.init_done
# Touched by the engine container (./data is mounted)
data/heartbeat
# Written by make e2e
e2e-artifacts/
*.pem
# Byte-compiled / optimized / DLL files
__pycache__/
Expand Down
31 changes: 28 additions & 3 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ help:
@echo " build Build local images in this repo"
@echo " build-external Build images in sibling repos"
@echo " build-all Build local and external images"
@echo " build-e2e Build only the local images the e2e needs (no notebooks)"
@echo " fetch-scenario Download scenario images (SCENARIO=smoke-then-clear)"
@echo " run-backend Start base services only"
@echo " run-camera Start only the fake cameras, to work on pyro-engine"
Expand All @@ -21,7 +22,8 @@ help:
@echo " stop Stop and remove all services and volumes"
@echo " ps Show compose status"
@echo " logs Follow logs"
@echo " test Run pytest"
@echo " test Run the unit tests"
@echo " e2e Fresh stack, then the end-to-end tests (SCENARIO=smoke-then-clear), artifacts in e2e-artifacts/"

# -------------------------------------------------------------------
# Init
Expand All @@ -40,6 +42,11 @@ build: fetch-scenario
docker build -f containers/notebooks/Dockerfile -t pyronear/notebooks:latest containers/notebooks/
docker build --build-context scenarios=data/scenarios -f containers/fake_camera/Dockerfile -t pyronear/fake-camera:latest containers/fake_camera/

# Same images as `build` minus notebooks, which the e2e does not run.
build-e2e: fetch-scenario
docker build -f containers/init_script/Dockerfile -t pyronear/pyro-api-init:latest containers/init_script/
docker build --build-context scenarios=data/scenarios -f containers/fake_camera/Dockerfile -t pyronear/fake-camera:latest containers/fake_camera/

# -------------------------------------------------------------------
# Build images from sibling repositories
# -------------------------------------------------------------------
Expand All @@ -62,11 +69,12 @@ run-backend:
# Fake camera scenarios: definitions are in data/scenarios/<name>/scenario.json,
# images come from the "scenarios" GitHub release.
SCENARIO ?= smoke-then-clear
export SCENARIO
SCENARIOS_URL = https://github.com/pyronear/pyro-envdev/releases/download/scenarios
# Downloads unless every camera of scenario.json already has frames.
fetch-scenario:
@python3 -c "import glob, json, sys; d = 'data/scenarios/$(SCENARIO)'; \
sys.exit(any(not glob.glob(f'{d}/{c}/*.jpg') for c in json.load(open(f'{d}/scenario.json'))['cameras']))" || \
sys.exit(any(not glob.glob(f'{d}/{c}/**/*.jpg', recursive=True) for c in json.load(open(f'{d}/scenario.json'))['cameras']))" || \
(curl -fsSL $(SCENARIOS_URL)/$(SCENARIO).zip -o /tmp/$(SCENARIO).zip && \
unzip -oq /tmp/$(SCENARIO).zip -x '*/scenario.json' -d data/scenarios && rm /tmp/$(SCENARIO).zip)

Expand Down Expand Up @@ -122,4 +130,21 @@ logs:
# -------------------------------------------------------------------

test:
pytest -s tests/*
pytest -s tests --ignore=tests/e2e -m "not integration"

# End-to-end: fresh stack (data/ is a bind mount, so the init marker survives `down -v`),
# then the tests. Whatever fails, ps and the logs are dumped to e2e-artifacts/ and make
# exits with the failing step's code. The stack is left up for debugging, `make stop` cleans.
e2e:
$(MAKE) stop
rm -f data/.init_done
$(MAKE) init build-e2e
rm -rf e2e-artifacts && mkdir -p e2e-artifacts
@rc=0; \
docker compose --profile front --profile engine up -d --wait || rc=$$?; \
if [ $$rc -eq 0 ]; then \
uv run --python 3.12 --with-requirements tests/requirements.txt pytest tests/e2e --junitxml=e2e-artifacts/junit.xml -ra --tb=short || rc=$$?; \
fi; \
docker compose ps -a > e2e-artifacts/ps.txt 2>&1; \
docker compose --profile front --profile engine logs --no-color > e2e-artifacts/compose.log 2>&1; \
exit $$rc
11 changes: 10 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,8 @@ make run

```bash
make build
make run-all
make run
make run-engine
```

This launches everything, including the engine and the fake cameras playing the
Expand Down Expand Up @@ -88,6 +89,14 @@ docker compose logs -f engine

---

## 🧪 End-to-end tests

`make e2e SCENARIO=<name>` tears the stack down, brings up a fresh one (two fake cameras playing the scenario, the real camera API, engine, pyro-api and the frontend) and runs the pytest suite in `tests/e2e/` against it. It needs Docker and [`uv`](https://docs.astral.sh/uv/), and leaves the stack running afterwards for debugging (`make stop` cleans it).

Whatever the outcome, `e2e-artifacts/` holds `junit.xml` (which assertion failed, open it first), `compose.log` (engine, camera API and fake camera logs) and `ps.txt` (container states). A run rewrites the tracked `data/credentials.json`, since init writes the camera tokens into it: do not commit that change. Scenarios need a fresh stack, because the API groups detections of the same pose for 2 hours, which is why `make e2e` always starts from `make stop`.

---

## 🔑 Access

* **API**: [http://localhost:5050/docs](http://localhost:5050/docs)
Expand Down
7 changes: 5 additions & 2 deletions containers/fake_camera/server.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
positioned (static) moves on every Snap.

``GET /scenario`` is not part of the Reolink API: it reports the camera state
(preset, azimuth, frame, finished) so tests know where the scenario is.
(scenario, preset, azimuth, frame, finished) so tests know where the scenario is.
"""

import json
Expand Down Expand Up @@ -44,9 +44,10 @@ def reply(cmd, value=None, error=None):


class Camera:
def __init__(self, scenario_dir, name):
def __init__(self, scenario_dir, name, scenario=None):
meta = json.loads((scenario_dir / "scenario.json").read_text())
self.name = name
self.scenario = scenario # reported by /scenario
# preset id -> real-world azimuth, informational only (see /scenario)
self.azimuths = {
int(k): float(v) for k, v in meta["cameras"][name]["poses"].items()
Expand Down Expand Up @@ -77,6 +78,7 @@ def snap(self):
def status(self):
with self.lock:
return {
"scenario": self.scenario,
"camera": self.name,
"preset": self.preset,
"azimuth": self.azimuths.get(self.preset),
Expand Down Expand Up @@ -207,6 +209,7 @@ def main():
camera = Camera(
Path(os.environ.get("SCENARIOS_DIR", "/scenarios")) / scenario,
os.environ["CAMERA"],
scenario,
)
port = int(os.environ.get("PORT", "443"))
here = Path(__file__).parent
Expand Down
5 changes: 5 additions & 0 deletions data/scenarios/never-smoke/scenario.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,10 @@
"cameras": {
"croix-augas-01": {"poses": {"1": 326.5, "2": 13.2, "3": 59.8}},
"nemours-02": {"poses": {"0": 245.9, "1": 292.4, "2": 339.4, "3": 25.4}}
},
"expected": {
"alerts": 0,
"sequences": [],
"timeout_s": 600
}
}
13 changes: 13 additions & 0 deletions data/scenarios/smoke-then-clear/scenario.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,18 @@
"cameras": {
"croix-augas-01": {"poses": {"1": 326.5, "2": 13.2, "3": 59.8}},
"nemours-02": {"poses": {"0": 245.9, "1": 292.4, "2": 339.4, "3": 25.4}}
},
"expected": {
"alerts": 5,
"sequences": [
{"camera": "croix-augas-01", "preset": "1", "min_detections": 15},
{"camera": "croix-augas-01", "preset": "2", "min_detections": 15},
{"camera": "croix-augas-01", "preset": "3", "min_detections": 15},
{"camera": "nemours-02", "preset": "0", "min_detections": 15},
{"camera": "nemours-02", "preset": "1", "min_detections": 15},
{"camera": "nemours-02", "preset": "2", "min_detections": 15},
{"camera": "nemours-02", "preset": "3", "min_detections": 15}
],
"timeout_s": 2400
}
}
6 changes: 6 additions & 0 deletions docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@ services:
pyro_api:
container_name: api
image: pyronear/alert-api:latest
# No arm64 manifest on Docker Hub (Apple Silicon runs it emulated)
platform: linux/amd64
command: "sh -c 'alembic upgrade head && python app/db.py && uvicorn app.main:app --reload --host 0.0.0.0 --port 5050 --proxy-headers'"
ports:
- 5050:5050
Expand Down Expand Up @@ -164,6 +166,8 @@ services:
temporal_model_api:
container_name: temporal_model_api
image: pyronear/temporal-model-api:latest
# No arm64 manifest on Docker Hub (Apple Silicon runs it emulated)
platform: linux/amd64
profiles:
- temporal
ports:
Expand Down Expand Up @@ -213,6 +217,8 @@ services:
condition: service_healthy
frontend:
image: pyronear/pyro-platform-react:latest
# Image is amd64 only (Apple Silicon runs it emulated)
platform: linux/amd64
profiles:
- front
ports:
Expand Down
7 changes: 7 additions & 0 deletions pytest.ini
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
[pytest]
testpaths = tests
pythonpath = .
addopts = --strict-markers
markers =
e2e: needs the whole compose stack (make e2e)
integration: needs a running service such as the fake camera or the database
Empty file added tests/__init__.py
Empty file.
Empty file added tests/e2e/__init__.py
Empty file.
Loading