# ContextFS Sync Service Dockerfile
# Builds a lightweight FastAPI service for sync operations
FROM python:3.12-slim
# Set working directory
WORKDIR /app
# Install system dependencies
RUN apt-get update && apt-get install -y --no-install-recommends \
git \
&& rm -rf /var/lib/apt/lists/*
# Copy requirements first for better caching
COPY pyproject.toml ./
# Install Python dependencies
RUN pip install --no-cache-dir \
fastapi>=0.109.0 \
uvicorn[standard]>=0.27.0 \
sqlalchemy[asyncio]>=2.0.0 \
asyncpg>=0.29.0 \
aiosqlite>=0.19.0 \
pydantic>=2.0.0 \
pydantic-settings>=2.0.0 \
pgvector>=0.2.0 \
httpx>=0.27.0 \
stripe>=8.0.0 \
cryptography>=42.0.0 \
alembic>=1.13.0 \
psycopg2-binary>=2.9.0
# Copy source code
# Note: service/migrations/ contains Alembic migrations (no separate migrations dir needed)
COPY src/contextfs /app/src/contextfs
COPY service /app/service
# Set Python path
ENV PYTHONPATH=/app/src:/app
# Default port (Railway overrides with $PORT)
ENV PORT=8766
EXPOSE 8766
# Health check uses $PORT
HEALTHCHECK --interval=30s --timeout=10s --start-period=5s --retries=3 \
CMD ["python", "-c", "import httpx; import os; httpx.get(f'http://localhost:{os.environ.get(\"PORT\", 8766)}/health').raise_for_status()"]
# Run the service - Railway provides $PORT
# Migrations run automatically in session.py create_tables()
CMD ["sh", "-c", "uvicorn service.api.main:app --host 0.0.0.0 --port ${PORT:-8766}"]