# ============================================================================= # FASHIONISTAR — Celery Worker Dockerfile (Northflank + Multi-Platform) # ============================================================================= # Primary Target: Northflank Free Sandbox (linux/amd64) # Also Works: Render, Railway, GCP Cloud Run Jobs, local dev # # Celery queues handled: # - default : General async tasks # - ai_tasks : AI/ML body measurement computation # - measurements : Body measurement processing # - analytics : Reporting & aggregation # - notifications : Email / SMS / Push # - webhooks : Incoming webhook processing # # Start modes (via CMD or entrypoint arg): # celery-worker → Full Celery worker (default) # celery-beat → Celery Beat scheduler only # celery-all → Worker + Beat combined (saves resources on small tiers) # ============================================================================= ARG PYTHON_VERSION=3.13-slim ARG UV_IMAGE_TAG=0.8.22 # ── Stage 1: uv binary ─────────────────────────────────────────────────────── FROM ghcr.io/astral-sh/uv:${UV_IMAGE_TAG} AS uvbin # ── Stage 2: dependency builder ────────────────────────────────────────────── FROM python:${PYTHON_VERSION} AS builder ENV PYTHONDONTWRITEBYTECODE=1 \ PYTHONUNBUFFERED=1 \ UV_COMPILE_BYTECODE=1 \ UV_LINK_MODE=copy \ UV_PROJECT_ENVIRONMENT=/opt/venv \ VIRTUAL_ENV=/opt/venv RUN apt-get update && apt-get install -y --no-install-recommends \ build-essential \ libpq-dev \ && rm -rf /var/lib/apt/lists/* COPY --from=uvbin /uv /uvx /bin/ WORKDIR /app COPY pyproject.toml uv.lock ./ RUN uv sync --frozen --no-dev --no-editable --no-install-project && \ uv pip uninstall --python /opt/venv torch torchvision mediapipe open-clip-torch sentence-transformers opencv-python-headless opencv-contrib-python nvidia-cuda-nvrtc-cu12 nvidia-cuda-runtime-cu12 nvidia-cuda-cupti-cu12 nvidia-cudnn-cu12 nvidia-cublas-cu12 nvidia-cufft-cu12 nvidia-curand-cu12 nvidia-cusolver-cu12 nvidia-cusparse-cu12 nvidia-nccl-cu12 nvidia-nvtx-cu12 nvidia-nvjitlink-cu12 triton # ── Stage 3: runtime ───────────────────────────────────────────────────────── FROM python:${PYTHON_VERSION} AS runner ENV PYTHONDONTWRITEBYTECODE=1 \ PYTHONUNBUFFERED=1 \ UV_LINK_MODE=copy \ UV_PROJECT_ENVIRONMENT=/opt/venv \ PATH="/opt/venv/bin:$PATH" \ DJANGO_SETTINGS_MODULE=backend.config.production \ WORKING_ENVIRONMENT=production \ # Celery concurrency: 4 workers per container (tune to Northflank free limits) CELERY_CONCURRENCY=4 \ # Queues this worker handles CELERY_QUEUES=default,ai_tasks,measurements,analytics,notifications,webhooks \ # Prevent worker process from accumulating memory leaks CELERY_MAX_TASKS_PER_CHILD=100 \ CELERY_LOG_LEVEL=info RUN apt-get update && apt-get install -y --no-install-recommends \ libpq5 \ postgresql-client \ curl \ && rm -rf /var/lib/apt/lists/* COPY --from=uvbin /uv /uvx /bin/ COPY --from=builder /opt/venv /opt/venv # Create non-root user (UID 1000 — matches Hugging Face + general best practice) RUN useradd --create-home --uid 1000 --shell /bin/sh appuser && \ mkdir -p /app/staticfiles /app/media /app/logs && \ chown -R appuser:appuser /app WORKDIR /app COPY --chown=appuser:appuser . . COPY --chown=appuser:appuser entrypoint.sh /entrypoint.sh RUN chmod +x /entrypoint.sh USER appuser # Celery worker has no HTTP port — only connects outbound to Redis broker # No EXPOSE needed for worker-type services (Northflank handles this correctly) ENTRYPOINT ["/entrypoint.sh"] # Default: Celery worker mode. Override with "celery-beat" for the Beat scheduler. CMD ["celery-worker"]