feat: docker & startup
This commit is contained in:
@@ -24,8 +24,12 @@ async def shutdown(_ctx: dict[str, Any]) -> None:
|
|||||||
log.info("worker_shutdown")
|
log.info("worker_shutdown")
|
||||||
|
|
||||||
|
|
||||||
|
async def _noop(_ctx: dict[str, Any]) -> None:
|
||||||
|
pass
|
||||||
|
|
||||||
|
|
||||||
class WorkerSettings:
|
class WorkerSettings:
|
||||||
functions: ClassVar[list[Any]] = [] # populated as tasks are implemented
|
functions: ClassVar[list[Any]] = [_noop] # populated as tasks are implemented
|
||||||
on_startup = startup
|
on_startup = startup
|
||||||
on_shutdown = shutdown
|
on_shutdown = shutdown
|
||||||
max_jobs = get_settings().max_parallel_downloads
|
max_jobs = get_settings().max_parallel_downloads
|
||||||
|
|||||||
@@ -0,0 +1,34 @@
|
|||||||
|
# syntax=docker/dockerfile:1
|
||||||
|
# DEV image: source is bind-mounted by compose, uvicorn runs with --reload.
|
||||||
|
# Build context = mcma-backend/ (see docker-compose.yml).
|
||||||
|
FROM python:3.14-slim
|
||||||
|
|
||||||
|
ENV PYTHONUNBUFFERED=1 \
|
||||||
|
PYTHONDONTWRITEBYTECODE=1 \
|
||||||
|
UV_LINK_MODE=copy \
|
||||||
|
VIRTUAL_ENV=/app/.venv \
|
||||||
|
PATH="/app/.venv/bin:$PATH"
|
||||||
|
|
||||||
|
# Runtime tools: ffmpeg (transcode/HLS), fpcalc (Chromaprint fingerprinting).
|
||||||
|
RUN apt-get update \
|
||||||
|
&& apt-get install -y --no-install-recommends ffmpeg libchromaprint-tools \
|
||||||
|
&& rm -rf /var/lib/apt/lists/*
|
||||||
|
|
||||||
|
COPY --from=ghcr.io/astral-sh/uv:0.4 /uv /uvx /bin/
|
||||||
|
|
||||||
|
WORKDIR /app
|
||||||
|
|
||||||
|
# Dependency layer (incl. dev group for tooling) — cached unless lockfile changes.
|
||||||
|
COPY pyproject.toml uv.lock* ./
|
||||||
|
RUN --mount=type=cache,target=/root/.cache/uv \
|
||||||
|
uv sync --frozen --no-install-project
|
||||||
|
|
||||||
|
# Project layer. At runtime compose bind-mounts the live source over this.
|
||||||
|
COPY . .
|
||||||
|
RUN --mount=type=cache,target=/root/.cache/uv \
|
||||||
|
uv sync --frozen
|
||||||
|
|
||||||
|
EXPOSE 8000
|
||||||
|
|
||||||
|
# --reload watches /app (the bind mount) and restarts on edit.
|
||||||
|
CMD ["uvicorn", "app.main:app", "--host", "0.0.0.0", "--port", "8000", "--reload"]
|
||||||
@@ -1,5 +1,7 @@
|
|||||||
# syntax=docker/dockerfile:1
|
# syntax=docker/dockerfile:1
|
||||||
# Single image serves both `api` and `worker` (different commands in compose).
|
# PROD image: self-contained, no dev deps, no source mount.
|
||||||
|
# Single image serves both `api` and `worker` (different commands at runtime).
|
||||||
|
# Build context = mcma-backend/.
|
||||||
FROM python:3.14-slim AS base
|
FROM python:3.14-slim AS base
|
||||||
|
|
||||||
ENV PYTHONUNBUFFERED=1 \
|
ENV PYTHONUNBUFFERED=1 \
|
||||||
@@ -18,7 +20,7 @@ COPY --from=ghcr.io/astral-sh/uv:0.4 /uv /uvx /bin/
|
|||||||
|
|
||||||
WORKDIR /app
|
WORKDIR /app
|
||||||
|
|
||||||
# Dependency layer — cached unless lockfile changes.
|
# Dependency layer (prod only) — cached unless lockfile changes.
|
||||||
COPY pyproject.toml uv.lock* ./
|
COPY pyproject.toml uv.lock* ./
|
||||||
RUN --mount=type=cache,target=/root/.cache/uv \
|
RUN --mount=type=cache,target=/root/.cache/uv \
|
||||||
uv sync --frozen --no-install-project --no-dev
|
uv sync --frozen --no-install-project --no-dev
|
||||||
@@ -30,5 +32,5 @@ RUN --mount=type=cache,target=/root/.cache/uv \
|
|||||||
|
|
||||||
EXPOSE 8000
|
EXPOSE 8000
|
||||||
|
|
||||||
# Default: API server. Worker overrides command in docker-compose.
|
# Default: API server. Worker overrides command (arq ...) at runtime.
|
||||||
CMD ["uvicorn", "app.main:app", "--host", "0.0.0.0", "--port", "8000"]
|
CMD ["uvicorn", "app.main:app", "--host", "0.0.0.0", "--port", "8000"]
|
||||||
@@ -2,7 +2,6 @@
|
|||||||
name = "mcma-backend"
|
name = "mcma-backend"
|
||||||
version = "0.1.0"
|
version = "0.1.0"
|
||||||
description = "Self-hosted, offline-first music service — backend (hexagonal architecture)"
|
description = "Self-hosted, offline-first music service — backend (hexagonal architecture)"
|
||||||
readme = "README.md"
|
|
||||||
requires-python = ">=3.14"
|
requires-python = ">=3.14"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
# web
|
# web
|
||||||
|
|||||||
Reference in New Issue
Block a user