Skip to content

Commit e7f7fd1

Browse files
committed
squash
1 parent 91641b8 commit e7f7fd1

188 files changed

Lines changed: 16421 additions & 105 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

.dockerignore

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,8 @@ vite/*
4848
secrets/*
4949
# Local testing @ildyria
5050
public/uploads-bck/*
51+
public/uploads/*
52+
*.sql
5153

5254
# Node
5355
node_modules/
@@ -56,8 +58,12 @@ npm-debug.log
5658
# Mapping for database and config used by docker compose
5759
lychee/*
5860

61+
# Python
62+
ai-vision-service/*
63+
5964
# Laravel
6065
/storage/logs/*
66+
/storage/tmp/*
6167
/storage/framework/cache/*
6268
/storage/framework/sessions/*
6369
/storage/framework/views/*

.github/dependabot.yml

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,9 +18,6 @@ updates:
1818
dependency-type: "production"
1919
development-dependencies:
2020
dependency-type: "development"
21-
ignore:
22-
- dependency-name: "typescript"
23-
versions: [ ">=6.0.0" ]
2421

2522
- package-ecosystem: composer
2623
directory: /

.github/workflows/CICD.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,11 +11,13 @@ on:
1111
- '**/*.md'
1212
- 'public/dist/*.js'
1313
- 'public/dist/**/*.js'
14+
- 'ai-vision-service/**'
1415
pull_request:
1516
paths-ignore:
1617
- '**/*.md'
1718
- 'public/dist/*.js'
1819
- 'public/dist/**/*.js'
20+
- 'ai-vision-service/**'
1921
# Allow manually triggering the workflow.
2022
workflow_dispatch:
2123

.github/workflows/dependency-review.yml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,3 +25,8 @@ jobs:
2525
uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2
2626
- name: 'Dependency Review'
2727
uses: actions/dependency-review-action@2031cfc080254a8a887f58cffee85186f0e49e48 # v4.9.0
28+
with:
29+
# No fix available yet
30+
# Note that the model is directly baked into the inage
31+
# So the risk is limited.
32+
allow-ghsas: GHSA-hqmj-h5c6-369m
Lines changed: 154 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,154 @@
1+
name: Python AI Vision Service for face recognition
2+
3+
on:
4+
push:
5+
branches:
6+
- master
7+
- assisted-vision
8+
paths:
9+
- 'ai-vision-service/face-recognition/**'
10+
pull_request:
11+
paths:
12+
- 'ai-vision-service/face-recognition/**'
13+
workflow_dispatch:
14+
15+
# Declare default permissions as read only.
16+
permissions:
17+
contents: read
18+
19+
concurrency:
20+
group: ${{ github.workflow }}-${{ github.ref }}
21+
cancel-in-progress: ${{ !contains(github.ref, 'master') && !startsWith(github.ref, 'refs/tags/') }}
22+
23+
defaults:
24+
run:
25+
working-directory: ai-vision-service/face-recognition
26+
27+
jobs:
28+
# ---------------------------------------------------------------------------
29+
# Lint – formatting and style
30+
# ---------------------------------------------------------------------------
31+
lint:
32+
name: Lint (ruff)
33+
runs-on: ubuntu-latest
34+
steps:
35+
- name: Harden Runner
36+
uses: step-security/harden-runner@fa2e9d605c4eeb9fcad4c99c224cee0c6c7f3594 # v2.16.0
37+
with:
38+
egress-policy: audit
39+
40+
- name: Checkout code
41+
uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2
42+
43+
- name: Set up uv
44+
uses: astral-sh/setup-uv@37802adc94f370d6bfd71619e3f0bf239e1f3b78 # v7.6.0
45+
with:
46+
enable-cache: true
47+
48+
- name: Install dev dependencies
49+
run: uv sync --frozen
50+
51+
- name: Check formatting
52+
run: uv run ruff format --check app/ tests/
53+
54+
- name: Lint
55+
run: uv run ruff check app/ tests/
56+
57+
# ---------------------------------------------------------------------------
58+
# Type check
59+
# ---------------------------------------------------------------------------
60+
typecheck:
61+
name: Type check (ty)
62+
runs-on: ubuntu-latest
63+
steps:
64+
- name: Harden Runner
65+
uses: step-security/harden-runner@fa2e9d605c4eeb9fcad4c99c224cee0c6c7f3594 # v2.16.0
66+
with:
67+
egress-policy: audit
68+
69+
- name: Checkout code
70+
uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2
71+
72+
- name: Set up uv
73+
uses: astral-sh/setup-uv@37802adc94f370d6bfd71619e3f0bf239e1f3b78 # v7.6.0
74+
with:
75+
enable-cache: true
76+
77+
- name: Install dev dependencies
78+
run: uv sync --frozen
79+
80+
- name: Type check
81+
run: uv run ty check app/
82+
83+
# ---------------------------------------------------------------------------
84+
# Test matrix – Python 3.13 and 3.14
85+
# ---------------------------------------------------------------------------
86+
test:
87+
name: Tests (Python ${{ matrix.python-version }})
88+
runs-on: ubuntu-latest
89+
strategy:
90+
fail-fast: false
91+
matrix:
92+
python-version:
93+
- "3.13"
94+
- "3.14"
95+
96+
steps:
97+
- name: Harden Runner
98+
uses: step-security/harden-runner@fa2e9d605c4eeb9fcad4c99c224cee0c6c7f3594 # v2.16.0
99+
with:
100+
egress-policy: audit
101+
102+
- name: Checkout code
103+
uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2
104+
105+
- name: Set up uv
106+
uses: astral-sh/setup-uv@37802adc94f370d6bfd71619e3f0bf239e1f3b78 # v7.6.0
107+
with:
108+
enable-cache: true
109+
python-version: ${{ matrix.python-version }}
110+
111+
- name: Install dev dependencies
112+
run: uv sync --frozen
113+
114+
- name: Run tests
115+
run: uv run pytest --cov=app --cov-report=xml -v
116+
117+
- name: Upload coverage
118+
if: matrix.python-version == '3.13'
119+
uses: codecov/codecov-action@671740ac38dd9b0130fbe1cec585b89eea48d3de # v5.5.2
120+
with:
121+
files: ai-vision-service/face-recognition/coverage.xml
122+
flags: ai-vision-service/face-recognition
123+
continue-on-error: true
124+
125+
# ---------------------------------------------------------------------------
126+
# Docker build verification
127+
# ---------------------------------------------------------------------------
128+
docker-build:
129+
name: Docker build
130+
runs-on: ubuntu-latest
131+
steps:
132+
- name: Harden Runner
133+
uses: step-security/harden-runner@fa2e9d605c4eeb9fcad4c99c224cee0c6c7f3594 # v2.16.0
134+
with:
135+
egress-policy: audit
136+
137+
- name: Checkout code
138+
uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2
139+
140+
- name: Set up Docker Buildx
141+
uses: docker/setup-buildx-action@4d04d5d9486b7bd6fa91e7baf45bbb4f8b9deedd #v4.0.0
142+
143+
- name: Build Docker image (no model bake in CI to save time)
144+
uses: docker/build-push-action@d08e5c354a6adb9ed34480a06d141179aa583294 # v7.0.0
145+
with:
146+
context: ai-vision-service/face-recognition
147+
push: false
148+
load: true
149+
tags: lychee-ai-vision:ci
150+
# Override the model-bake step by targeting the builder stage
151+
# to avoid downloading 300MB of model weights in CI.
152+
target: builder
153+
cache-from: type=gha
154+
cache-to: type=gha,mode=max

.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,8 @@ clover.xml
3838
.NO_AUTO_COMPOSER_MIGRATE
3939
storage/bootstrap/cache/*
4040
storage/image-jobs/*
41+
**/__pycache__/**
42+
.coverage
4143

4244
# used by Vite
4345
public/hot

Makefile

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -166,6 +166,9 @@ class-leak:
166166
docker-build:
167167
docker build -t lychee-frankenphp .
168168

169+
docker-build-legacy:
170+
docker build -t lychee-frankenphp -f Dockerfile-legacy .
171+
169172
docker-build-no-cache:
170173
docker build -t lychee-frankenphp . --no-cache
171174

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
*
2+
!.gitignore
Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
# Multi-stage build: keep the runtime image lean.
2+
3+
# ---------------------------------------------------------------------------
4+
# Stage 1 – builder: install dependencies and bake the model weights.
5+
# ---------------------------------------------------------------------------
6+
FROM python:3.13-slim@sha256:739e7213785e88c0f702dcdc12c0973afcbd606dbf021a589cab77d6b00b579d AS builder
7+
8+
# Install uv from the official image.
9+
COPY --from=ghcr.io/astral-sh/uv:latest /uv /usr/local/bin/uv
10+
11+
# Build tools required to compile insightface's Cython extension (mesh_core_cython).
12+
RUN apt-get update && apt-get install -y --no-install-recommends \
13+
g++ \
14+
libgl1 \
15+
libglib2.0-0 \
16+
&& rm -rf /var/lib/apt/lists/*
17+
18+
WORKDIR /app
19+
20+
# Install dependencies only (no source code) so layer cache is reused when
21+
# only application code changes.
22+
COPY pyproject.toml uv.lock README.md ./
23+
RUN uv sync --frozen --no-dev
24+
25+
# Bake buffalo_l model weights into the image at build time (~300 MB download).
26+
# The resulting image is ~1 GB larger but starts instantly and works in
27+
# airgapped environments. Model updates require an image rebuild.
28+
RUN uv run python -c \
29+
"from insightface.app import FaceAnalysis; \
30+
a = FaceAnalysis(name='buffalo_l', root='/root/.insightface', providers=['CPUExecutionProvider']); \
31+
a.prepare(ctx_id=-1); \
32+
print('buffalo_l model downloaded.')"
33+
34+
# ---------------------------------------------------------------------------
35+
# Stage 2 – runtime: copy only what's needed to run.
36+
# ---------------------------------------------------------------------------
37+
FROM python:3.13-slim@sha256:739e7213785e88c0f702dcdc12c0973afcbd606dbf021a589cab77d6b00b579d AS runtime
38+
39+
WORKDIR /app
40+
41+
# Copy the pre-built virtualenv and baked model weights from the builder stage.
42+
COPY --from=builder /app/.venv /app/.venv
43+
COPY --from=builder /root/.insightface /root/.insightface
44+
45+
# Copy application source.
46+
COPY app/ ./app/
47+
48+
ENV PATH="/app/.venv/bin:$PATH"
49+
50+
EXPOSE 8000
51+
52+
# Use a shell-form CMD so that the ${VISION_FACE_WORKERS:-1} variable is
53+
# expanded at container startup, not at image build time.
54+
CMD ["sh", "-c", "uvicorn app.main:app --host 0.0.0.0 --port 8000 --workers ${VISION_FACE_WORKERS:-1}"]

0 commit comments

Comments
 (0)