File size: 1,190 Bytes
42adb22
3f85952
42adb22
3f85952
 
 
 
 
 
 
 
 
 
 
 
42adb22
 
3f85952
42adb22
 
3f85952
 
 
 
 
42adb22
3f85952
42adb22
3f85952
 
 
 
 
 
 
42adb22
 
3f85952
42adb22
3f85952
42adb22
 
3f85952
 
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
FROM python:3.11-slim AS builder

RUN apt-get update && apt-get install -y --no-install-recommends \
    gcc libpq-dev curl && rm -rf /var/lib/apt/lists/*

# Install uv
RUN curl -LsSf https://astral.sh/uv/install.sh | sh
ENV PATH="/root/.local/bin:$PATH"

WORKDIR /app
COPY pyproject.toml .
COPY production/ ./production/

# Sync dependencies with uv
RUN uv sync --frozen

FROM python:3.11-slim AS production

RUN apt-get update && apt-get install -y --no-install-recommends \
    libpq5 curl && rm -rf /var/lib/apt/lists/*

# Install uv in production too
RUN curl -LsSf https://astral.sh/uv/install.sh | sh
ENV PATH="/root/.local/bin:$PATH"

RUN useradd --create-home --shell /bin/bash appuser

WORKDIR /app
COPY --from=builder /app/.venv /app/.venv
COPY --chown=appuser:appuser production/ ./production/
COPY --chown=appuser:appuser pyproject.toml .

ENV PATH="/app/.venv/bin:$PATH"
ENV PYTHONPATH="/app"

RUN chown -R appuser:appuser /app
USER appuser

EXPOSE 8000

HEALTHCHECK --interval=30s --timeout=10s --start-period=40s --retries=3 \
    CMD curl -f http://localhost:8000/health || exit 1

CMD ["uvicorn", "production.production_server:app", "--host", "0.0.0.0", "--port", "8000"]