street-lingo/backend/Dockerfile

45 lines
1.0 KiB
Docker

FROM python:3.11-slim
# Set environment variables
ENV PYTHONUNBUFFERED=1 \
PYTHONDONTWRITEBYTECODE=1 \
PIP_NO_CACHE_DIR=1 \
PIP_DISABLE_PIP_VERSION_CHECK=1
# Set work directory
WORKDIR /app
# Install system dependencies
RUN apt-get update && apt-get install -y \
gcc \
g++ \
&& rm -rf /var/lib/apt/lists/*
# Install UV for faster Python package management
RUN pip install uv
# Create non-root user early
RUN useradd --create-home --shell /bin/bash app && \
chown -R app:app /app
# Switch to app user
USER app
# Copy pyproject.toml and uv.lock
COPY --chown=app:app pyproject.toml uv.lock ./
# Install Python dependencies as app user
RUN uv sync --frozen --no-dev
# Copy application code
COPY --chown=app:app . .
# Expose port
EXPOSE 8000
# Health check
HEALTHCHECK --interval=30s --timeout=30s --start-period=5s --retries=3 \
CMD curl -f http://localhost:8000/api/health || exit 1
# Run the application
CMD ["uv", "run", "python", "-m", "uvicorn", "main:app", "--host", "0.0.0.0", "--port", "8000"]