feat: add :cpu tag for amd64 CPU-only image
Introduces a VARIANT=gpu|cpu build arg to the Dockerfile. The cpu variant uses ubuntu:22.04 (no CUDA base), installs torch+cpu and onnxruntime (no GPU deps) via a separate pyproject-cpu.toml / uv-cpu.lock, and is published as :cpu (dev-cpu on the dev branch) via a new build-cpu CI job. Saves ~2 GB over the default GPU image. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
@@ -126,3 +126,58 @@ jobs:
|
||||
- name: Inspect image
|
||||
run: |
|
||||
docker buildx imagetools inspect ${{ steps.tags.outputs.tags }}
|
||||
|
||||
build-cpu:
|
||||
name: Build CPU-only (amd64)
|
||||
runs-on: ubuntu-latest
|
||||
permissions:
|
||||
contents: read
|
||||
packages: write
|
||||
|
||||
steps:
|
||||
- name: Free up disk space
|
||||
run: |
|
||||
sudo rm -rf /usr/share/dotnet
|
||||
sudo rm -rf /opt/ghc
|
||||
sudo rm -rf "/usr/local/share/boost"
|
||||
sudo rm -rf "$AGENT_TOOLSDIRECTORY"
|
||||
echo "Disk space freed."
|
||||
|
||||
- name: Checkout repository
|
||||
uses: actions/checkout@v6
|
||||
|
||||
- name: Set up Docker Buildx
|
||||
uses: docker/setup-buildx-action@v4
|
||||
|
||||
- name: Log in to GHCR
|
||||
uses: docker/login-action@v4
|
||||
with:
|
||||
registry: ${{ env.REGISTRY }}
|
||||
username: ${{ github.actor }}
|
||||
password: ${{ secrets.GITHUB_TOKEN }}
|
||||
|
||||
- name: Determine CPU image tag
|
||||
id: cpu-tag
|
||||
run: |
|
||||
if [ "${{ github.ref_name }}" = "dev" ]; then
|
||||
echo "tag=${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}:dev-cpu" >> "$GITHUB_OUTPUT"
|
||||
else
|
||||
echo "tag=${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}:cpu" >> "$GITHUB_OUTPUT"
|
||||
fi
|
||||
|
||||
- name: Build and push CPU image
|
||||
uses: docker/build-push-action@v6
|
||||
with:
|
||||
context: .
|
||||
file: ./Dockerfile
|
||||
platforms: linux/amd64
|
||||
build-args: VARIANT=cpu
|
||||
cache-from: type=gha,scope=linux/amd64-cpu
|
||||
cache-to: type=gha,mode=max,scope=linux/amd64-cpu
|
||||
github-token: ${{ secrets.GITHUB_TOKEN }}
|
||||
push: true
|
||||
tags: ${{ steps.cpu-tag.outputs.tag }}
|
||||
|
||||
- name: Inspect CPU image
|
||||
run: |
|
||||
docker buildx imagetools inspect ${{ steps.cpu-tag.outputs.tag }}
|
||||
|
||||
+28
-16
@@ -1,20 +1,25 @@
|
||||
# ── Platform-conditional base ─────────────────────────────────────────────
|
||||
# amd64: NVIDIA CUDA 13.3 (GPU acceleration when available, CPU fallback)
|
||||
# arm64: Ubuntu 24.04 (CPU-only; no CUDA on ARM)
|
||||
# ── Base images ───────────────────────────────────────────────────────────────
|
||||
# amd64 + gpu: NVIDIA CUDA 13.3 + cuDNN (GPU acceleration when available)
|
||||
# amd64 + cpu: Ubuntu 22.04 (CPU-only, ~2 GB smaller image)
|
||||
# arm64: Ubuntu 24.04 (CPU-only; no CUDA wheels on ARM)
|
||||
|
||||
FROM --platform=$BUILDPLATFORM nvidia/cuda:13.3.0-cudnn-runtime-ubuntu22.04 AS base-amd64
|
||||
FROM ubuntu:24.04 AS base-arm64
|
||||
ARG VARIANT=gpu
|
||||
|
||||
# ── Build stage ───────────────────────────────────────────────────────────
|
||||
FROM --platform=$BUILDPLATFORM nvidia/cuda:13.3.0-cudnn-runtime-ubuntu22.04 AS base-amd64-gpu
|
||||
FROM ubuntu:22.04 AS base-amd64-cpu
|
||||
FROM ubuntu:24.04 AS base-arm64-gpu
|
||||
FROM ubuntu:24.04 AS base-arm64-cpu
|
||||
|
||||
# ── Build stage ───────────────────────────────────────────────────────────────
|
||||
ARG TARGETARCH
|
||||
|
||||
FROM base-${TARGETARCH} AS build
|
||||
FROM base-${TARGETARCH}-${VARIANT} AS build
|
||||
|
||||
ARG VARIANT=gpu
|
||||
ENV DEBIAN_FRONTEND=noninteractive
|
||||
|
||||
# Both bases (Ubuntu 22.04 CUDA / Ubuntu 24.04) need Python 3.13 from the
|
||||
# deadsnakes PPA. GNUPGHOME is isolated to a tmpdir so gpg never tries to
|
||||
# contact an agent socket, which fails silently under QEMU.
|
||||
# Both Ubuntu 22.04 and 24.04 get Python 3.13 from the deadsnakes PPA.
|
||||
# GNUPGHOME is isolated so gpg never contacts an agent socket under QEMU.
|
||||
RUN apt-get update && apt-get install -y --no-install-recommends \
|
||||
ca-certificates curl gnupg software-properties-common \
|
||||
&& GNUPGHOME=$(mktemp -d) add-apt-repository ppa:deadsnakes/ppa -y \
|
||||
@@ -30,20 +35,26 @@ RUN curl -LsSf https://astral.sh/uv/install.sh | sh \
|
||||
|
||||
WORKDIR /app
|
||||
|
||||
COPY pyproject.toml uv.lock ./
|
||||
RUN uv sync --frozen --no-dev \
|
||||
# For cpu variant, swap in the CPU-only pyproject and lockfile before syncing.
|
||||
COPY pyproject.toml uv.lock pyproject-cpu.toml uv-cpu.lock ./
|
||||
RUN if [ "$VARIANT" = "cpu" ]; then \
|
||||
cp pyproject-cpu.toml pyproject.toml && \
|
||||
cp uv-cpu.lock uv.lock; \
|
||||
fi && \
|
||||
uv sync --frozen --no-dev \
|
||||
&& uv cache clean
|
||||
|
||||
COPY winnow/ winnow/
|
||||
COPY entrypoint.sh scheduler.py ./
|
||||
RUN chmod +x /app/entrypoint.sh
|
||||
|
||||
# ── Runtime stage ─────────────────────────────────────────────────────────
|
||||
# ── Runtime stage ─────────────────────────────────────────────────────────────
|
||||
# Starts fresh from the base image — excludes build tools (g++,
|
||||
# python3.13-dev, gnupg, software-properties-common) not needed at runtime.
|
||||
|
||||
FROM base-${TARGETARCH} AS runtime
|
||||
FROM base-${TARGETARCH}-${VARIANT} AS runtime
|
||||
|
||||
ARG VARIANT=gpu
|
||||
ENV DEBIAN_FRONTEND=noninteractive
|
||||
|
||||
RUN apt-get update && apt-get install -y --no-install-recommends \
|
||||
@@ -61,8 +72,9 @@ RUN apt-get update && apt-get install -y --no-install-recommends \
|
||||
COPY --from=build /app /app
|
||||
COPY --from=build /usr/local/bin/uv /usr/local/bin/uv
|
||||
|
||||
# Expose CUDA/cuDNN libraries from pip packages so onnxruntime-gpu
|
||||
# can find libcublasLt.so.12 and libcudnn.so.9 at runtime (amd64 only)
|
||||
# Expose CUDA/cuDNN libraries from pip packages so onnxruntime-gpu can find
|
||||
# libcublasLt.so.12 and libcudnn.so.9 at runtime (amd64-gpu only).
|
||||
# On cpu builds these paths don't exist; non-existent entries are ignored.
|
||||
ENV LD_LIBRARY_PATH="/app/.venv/lib/python3.13/site-packages/nvidia/cudnn/lib:/app/.venv/lib/python3.13/site-packages/nvidia/cuda_runtime/lib:${LD_LIBRARY_PATH}"
|
||||
|
||||
RUN groupadd -g 568 apps && useradd -u 568 -g apps -m -s /bin/bash appuser \
|
||||
|
||||
@@ -111,12 +111,19 @@ If the embedding model is unavailable, the tool falls back to **time spread**: e
|
||||
|
||||
## Running in Docker
|
||||
|
||||
### Image Tags
|
||||
|
||||
| Tag | Arch | GPU | Notes |
|
||||
| :-- | :-- | :-- | :-- |
|
||||
| `:latest` | amd64 + arm64 | CUDA 13.3 (amd64) | Requires NVIDIA Container Toolkit on amd64 |
|
||||
| `:cpu` | amd64 | None | ~2 GB smaller; use if you have no NVIDIA GPU |
|
||||
|
||||
### Quick Start
|
||||
|
||||
```yaml
|
||||
services:
|
||||
winnow:
|
||||
image: ghcr.io/sudolulo/winnow:latest
|
||||
image: ghcr.io/sudolulo/winnow:latest # or :cpu for CPU-only amd64
|
||||
environment:
|
||||
- IMMICH_URL=http://192.168.1.10:2283
|
||||
- API_KEY=your-immich-api-key
|
||||
@@ -136,6 +143,8 @@ services:
|
||||
capabilities: [gpu]
|
||||
```
|
||||
|
||||
> **CPU users (`:cpu` tag):** remove the `deploy.resources` block — no NVIDIA runtime needed.
|
||||
|
||||
See [compose.yml](compose.yml) for the full annotated example.
|
||||
|
||||
### Scheduling Behaviour
|
||||
|
||||
@@ -0,0 +1,93 @@
|
||||
[project]
|
||||
name = "winnow"
|
||||
version = "0.2.9"
|
||||
description = "Immich to Frigate training sets"
|
||||
license = "AGPL-3.0-or-later"
|
||||
requires-python = ">=3.13"
|
||||
authors = [{ name = "Holden Salomon", email = "holden@arch.fyi" }]
|
||||
keywords = ["immich", "frigate", "face-recognition", "training-data", "arcface", "insightface"]
|
||||
classifiers = [
|
||||
"Development Status :: 3 - Alpha",
|
||||
"Intended Audience :: Developers",
|
||||
"License :: OSI Approved :: GNU Affero General Public License v3 or later (AGPLv3+)",
|
||||
"Programming Language :: Python :: 3.13",
|
||||
"Topic :: Scientific/Engineering :: Image Recognition",
|
||||
]
|
||||
dependencies = [
|
||||
"croniter>=5.0.2",
|
||||
"insightface>=0.7.3",
|
||||
"numpy>=2.2.6",
|
||||
"onnxruntime>=1.23.2",
|
||||
"opencv-python-headless>=4.12.0.88",
|
||||
"pillow>=12.1.0",
|
||||
"python-dotenv>=1.2.1",
|
||||
"requests>=2.32.5",
|
||||
"rich>=14.2.0",
|
||||
"torch>=2.12.0",
|
||||
"torchvision>=0.27.0",
|
||||
"transformers>=4.57.6",
|
||||
"ultralytics>=8.4.66",
|
||||
]
|
||||
|
||||
[project.scripts]
|
||||
winnow = "winnow.cli:main"
|
||||
|
||||
[project.urls]
|
||||
Repository = "https://github.com/sudolulo/winnow"
|
||||
|
||||
[tool.uv]
|
||||
required-environments = [
|
||||
"sys_platform == 'linux' and platform_machine == 'x86_64'",
|
||||
]
|
||||
|
||||
[tool.uv.sources]
|
||||
torch = [
|
||||
{ index = "pytorch-cpu", marker = "sys_platform == 'linux' and platform_machine == 'x86_64'" },
|
||||
]
|
||||
torchvision = [
|
||||
{ index = "pytorch-cpu", marker = "sys_platform == 'linux' and platform_machine == 'x86_64'" },
|
||||
]
|
||||
|
||||
[[tool.uv.index]]
|
||||
name = "pytorch-cpu"
|
||||
url = "https://download.pytorch.org/whl/cpu"
|
||||
explicit = true
|
||||
|
||||
[dependency-groups]
|
||||
dev = [
|
||||
"pytest>=8.0",
|
||||
"ruff>=0.15.17",
|
||||
]
|
||||
|
||||
[tool.hatch.build.targets.wheel]
|
||||
packages = ["winnow"]
|
||||
|
||||
[tool.ruff]
|
||||
line-length = 120
|
||||
target-version = "py313"
|
||||
|
||||
[tool.ruff.lint]
|
||||
select = ["E", "F", "I"]
|
||||
|
||||
[tool.deptry]
|
||||
pep621_dev_dependency_groups = ["dev"]
|
||||
|
||||
[tool.deptry.package_module_name_map]
|
||||
pillow = "PIL"
|
||||
opencv-python-headless = "cv2"
|
||||
python-dotenv = "dotenv"
|
||||
insightface = "insightface"
|
||||
numpy = "numpy"
|
||||
onnxruntime = "onnxruntime"
|
||||
requests = "requests"
|
||||
rich = "rich"
|
||||
torch = "torch"
|
||||
transformers = "transformers"
|
||||
ultralytics = "ultralytics"
|
||||
|
||||
[tool.pytest.ini_options]
|
||||
testpaths = ["tests"]
|
||||
|
||||
[build-system]
|
||||
requires = ["hatchling"]
|
||||
build-backend = "hatchling.build"
|
||||
+1884
File diff suppressed because it is too large
Load Diff
Reference in New Issue
Block a user