File size: 4,123 Bytes
27c799c | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 | # =============================================================================
# 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"]
|