47 lines
1.1 KiB
Docker
47 lines
1.1 KiB
Docker
# Use Python 3.13 slim image
|
|
FROM python:3.13-slim
|
|
|
|
# Set working directory
|
|
WORKDIR /app
|
|
|
|
# Install system dependencies and build tools
|
|
RUN apt-get update && apt-get install -y \
|
|
curl \
|
|
gcc \
|
|
g++ \
|
|
build-essential \
|
|
python3-dev \
|
|
&& rm -rf /var/lib/apt/lists/*
|
|
|
|
# Install Hatch
|
|
RUN pip install --no-cache-dir hatch
|
|
|
|
# Copy project files
|
|
COPY pyproject.toml ./
|
|
COPY LICENSE ./
|
|
COPY README.md ./
|
|
COPY src/ ./src/
|
|
COPY templates/ ./templates/
|
|
|
|
# Install project and dependencies using Hatch
|
|
RUN hatch build -t wheel && \
|
|
pip install --no-cache-dir dist/*.whl && \
|
|
rm -rf dist/ build/
|
|
|
|
# Create non-root user for security
|
|
RUN useradd --create-home --shell /bin/bash app \
|
|
&& chown -R app:app /app
|
|
USER app
|
|
|
|
# Set environment variable to indicate container environment
|
|
ENV DOCKER_CONTAINER=1
|
|
|
|
# Expose port
|
|
EXPOSE 8000
|
|
|
|
# Health check
|
|
HEALTHCHECK --interval=30s --timeout=10s --start-period=5s --retries=3 \
|
|
CMD curl -f http://localhost:8000/ || exit 1
|
|
|
|
# Run the application
|
|
CMD ["uvicorn", "random_access.main:app", "--host", "0.0.0.0", "--port", "8000"]
|