Skip to content

Commit c0f9a9b

Browse files
authored
Merge pull request #3 from Roalkege/feature/docker-image
Add Docker image for light-object-detect
2 parents cc816a2 + d3418e3 commit c0f9a9b

6 files changed

Lines changed: 163 additions & 0 deletions

File tree

.dockerignore

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
.git
2+
.github
3+
__pycache__
4+
*.pyc
5+
*.pyo
6+
*.pyd
7+
.Python
8+
*.egg-info
9+
.venv
10+
venv
11+
.env
12+
.pytest_cache
13+
.mypy_cache
14+
.ruff_cache
15+
.coverage
16+
dist
17+
build
18+
*.log
19+
terminals
Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
name: Build and publish Docker image
2+
3+
on:
4+
push:
5+
branches: ["main"]
6+
tags: ["v*"]
7+
workflow_dispatch: {}
8+
9+
permissions:
10+
contents: read
11+
packages: write
12+
13+
jobs:
14+
docker:
15+
runs-on: ubuntu-latest
16+
steps:
17+
- name: Checkout
18+
uses: actions/checkout@v4
19+
20+
- name: Set up Docker Buildx
21+
uses: docker/setup-buildx-action@v3
22+
23+
- name: Log in to GHCR
24+
uses: docker/login-action@v3
25+
with:
26+
registry: ghcr.io
27+
username: ${{ github.actor }}
28+
password: ${{ secrets.GITHUB_TOKEN }}
29+
30+
- name: Extract Docker metadata
31+
id: meta
32+
uses: docker/metadata-action@v5
33+
with:
34+
images: ghcr.io/${{ github.repository_owner }}/light-object-detect
35+
tags: |
36+
type=raw,value=latest,enable={{is_default_branch}}
37+
type=ref,event=branch
38+
type=ref,event=tag
39+
type=sha
40+
41+
- name: Build and push
42+
uses: docker/build-push-action@v6
43+
with:
44+
context: .
45+
push: true
46+
tags: ${{ steps.meta.outputs.tags }}
47+
labels: ${{ steps.meta.outputs.labels }}

Dockerfile

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
FROM python:3.11-slim
2+
3+
ENV PYTHONDONTWRITEBYTECODE=1 \
4+
PYTHONUNBUFFERED=1 \
5+
PIP_DISABLE_PIP_VERSION_CHECK=1 \
6+
PIP_NO_CACHE_DIR=1
7+
8+
WORKDIR /app
9+
10+
# Minimal runtime libs for opencv-python on slim images
11+
RUN apt-get update \
12+
&& apt-get install -y --no-install-recommends \
13+
libgl1 \
14+
libglib2.0-0 \
15+
&& rm -rf /var/lib/apt/lists/*
16+
17+
# Install Python deps (keeps this image self-contained for Unraid)
18+
COPY Pipfile Pipfile.lock ./
19+
RUN python -m pip install --upgrade pip \
20+
&& python -m pip install \
21+
fastapi \
22+
uvicorn \
23+
python-multipart \
24+
pydantic \
25+
pydantic-settings \
26+
pillow \
27+
exceptiongroup \
28+
numpy \
29+
tensorflow \
30+
onnxruntime==1.23.2 \
31+
opencv-python \
32+
scipy \
33+
shapely
34+
35+
COPY . .
36+
37+
EXPOSE 8000
38+
39+
# .env is optional; Unraid can mount it to /app/.env
40+
CMD ["uvicorn", "main:app", "--host", "0.0.0.0", "--port", "8000"]

README.md

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,9 +49,51 @@ A lightweight Python API for object detection with pluggable backends. This API
4949

5050
3. Access the API documentation at http://localhost:9001/docs
5151

52+
## Docker (z.B. Unraid / lightNVR)
53+
54+
### Build
55+
56+
```bash
57+
docker build -t light-object-detect:local .
58+
```
59+
60+
### Run
61+
62+
Option A: ohne `.env` (Defaults aus `config.py`):
63+
64+
```bash
65+
docker run --rm -p 8000:8000 --name light-object-detect light-object-detect:local
66+
```
67+
68+
Option B: mit `.env` (empfohlen, z.B. Backend/Model-Pfade):
69+
70+
```bash
71+
docker run --rm -p 8000:8000 --name light-object-detect \
72+
-v "$(pwd)/.env:/app/.env:ro" \
73+
light-object-detect:local
74+
```
75+
76+
PowerShell:
77+
78+
```powershell
79+
docker run --rm -p 8000:8000 --name light-object-detect `
80+
-v "${PWD}\.env:/app/.env:ro" `
81+
light-object-detect:local
82+
```
83+
84+
- **Healthcheck**: `GET /health`
85+
- **Swagger UI**: `GET /docs`
86+
87+
### lightNVR Integration
88+
89+
In lightNVR als API-URL typischerweise:
90+
91+
- `http://<docker-host>:8000/api/v1/detect`
92+
5293
## API Endpoints
5394

5495
- `GET /` - Root endpoint with API information
96+
- `GET /health` - Health check endpoint (useful for Docker/Unraid)
5597
- `GET /api/v1/backends` - List available detection backends
5698
- `POST /api/v1/detect` - Detect objects in an uploaded image
5799

docker-compose.yml

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
services:
2+
light-object-detect:
3+
build: .
4+
container_name: light-object-detect
5+
ports:
6+
- "8000:8000"
7+
# Optional: provide config via a bind-mounted .env file
8+
# volumes:
9+
# - ./docker.env:/app/.env:ro
10+
restart: unless-stopped

main.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,5 +63,10 @@ async def root():
6363
"available_backends": settings.AVAILABLE_BACKENDS,
6464
}
6565

66+
@app.get("/health")
67+
async def health():
68+
"""Health check endpoint for container orchestrators."""
69+
return {"status": "ok"}
70+
6671
if __name__ == "__main__":
6772
uvicorn.run("main:app", host="0.0.0.0", port=9001, reload=True)

0 commit comments

Comments
 (0)