1- FROM python:3.10
1+ FROM python:3.11-slim
22
33ENV PYTHONUNBUFFERED=1
44
55WORKDIR /app/
66
7- # Install uv
8- # Ref: https://docs.astral.sh/uv/guides/integration/docker/#installing-uv
9- COPY --from=ghcr.io/astral-sh/uv:0.5.11 /uv /uvx /bin/
7+ # Install system dependencies
8+ RUN apt-get update && apt-get install -y \
9+ gcc \
10+ && rm -rf /var/lib/apt/lists/*
1011
11- # Place executables in the environment at the front of the path
12- # Ref: https://docs.astral.sh/uv/guides/integration/docker/#using-the-environment
13- ENV PATH= "/app/.venv/bin:$PATH"
12+ # Install Python dependencies
13+ COPY requirements.txt .
14+ RUN pip install --no-cache-dir -r requirements.txt
1415
15- # Compile bytecode
16- # Ref: https://docs.astral.sh/uv/guides/integration/docker/#compiling-bytecode
17- ENV UV_COMPILE_BYTECODE=1
16+ # Copy application code
17+ COPY ./scripts /app/scripts
18+ COPY ./alembic.ini /app/
19+ COPY ./app /app/app
1820
19- # uv Cache
20- # Ref: https://docs.astral.sh/uv/guides/integration/docker/#caching
21- ENV UV_LINK_MODE=copy
21+ # Create a non-root user
22+ RUN useradd -m -u 1000 appuser && \
23+ chown -R appuser:appuser /app
2224
23- # Install dependencies
24- # Ref: https://docs.astral.sh/uv/guides/integration/docker/#intermediate-layers
25- RUN --mount=type=cache,target=/root/.cache/uv \
26- --mount=type=bind,source=uv.lock,target=uv.lock \
27- --mount=type=bind,source=pyproject.toml,target=pyproject.toml \
28- uv sync --frozen --no-install-project
25+ # Switch to non-root user
26+ USER appuser
2927
28+ # Set environment variables
3029ENV PYTHONPATH=/app
30+ ENV ENVIRONMENT=production
3131
32- COPY ./scripts /app/scripts
33-
34- COPY ./pyproject.toml ./uv.lock ./alembic.ini /app/
35-
36- COPY ./app /app/app
37-
38- # Sync the project
39- # Ref: https://docs.astral.sh/uv/guides/integration/docker/#intermediate-layers
40- RUN --mount=type=cache,target=/root/.cache/uv \
41- uv sync
32+ # Expose port
33+ EXPOSE 8000
4234
43- CMD ["fastapi" , "run" , "--workers" , "4" , "app/main.py" ]
35+ # Start the application
36+ CMD ["python3.11" , "-m" , "uvicorn" , "app.main:app" , "--host" , "0.0.0.0" , "--port" , "8000" , "--log-level" , "debug" ]
0 commit comments