-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathDockerfile.prod
More file actions
59 lines (41 loc) · 1.54 KB
/
Dockerfile.prod
File metadata and controls
59 lines (41 loc) · 1.54 KB
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
46
47
48
49
50
51
52
53
54
55
56
57
58
59
# syntax=docker/dockerfile:1.4
FROM python:3.13-slim AS builder
# Install system dependencies for build
RUN apt-get update && \
apt-get install -y --no-install-recommends \
build-essential curl && \
rm -rf /var/lib/apt/lists/*
# Set environment variables
ENV POETRY_VERSION=2.1.4 \
POETRY_VIRTUALENVS_CREATE=false \
PYTHONUNBUFFERED=1
# Install Poetry
RUN curl -sSL https://install.python-poetry.org | python3 - --version $POETRY_VERSION
WORKDIR /app
# ---- Builder stage ----
# Copy only dependency files first for better cache
COPY poetry.lock pyproject.toml ./
# Install dependencies (no dev, no venv, install to /opt/venv for later copy)
RUN poetry config virtualenvs.create false && \
pip install --upgrade pip && \
poetry install --no-interaction --no-ansi --no-root --only=main
# ---- Runtime stage ----
FROM python:3.13-slim AS runtime
# Create a non-root user
RUN useradd -m eudai
WORKDIR /app
# Copy virtualenv site-packages from builder stage
COPY --from=builder /usr/local/lib/python3.13/site-packages /usr/local/lib/python3.13/site-packages
COPY --from=builder /usr/local/bin /usr/local/bin
# Copy application code
COPY --chown=eudai:eudai . .
# Expose port (adjust as needed)
EXPOSE 8000
# Set other environment variables if needed
ENV POETRY_NO_INTERACTION=1
# Drop root privileges
USER eudai
# Healthcheck (optional)
HEALTHCHECK --interval=30s --timeout=5s --start-period=20s CMD curl --fail htt://localhost:8000/health || exit 1
# Start the application
CMD ["poetry", "main:app", "--host", "0.0.0.0", "--port", "8000"]