generated from kyegomez/Python-Package-Template
-
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathDockerfile
31 lines (24 loc) · 903 Bytes
/
Dockerfile
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
# Use the official Python 3.12 image
FROM python:3.12-slim AS base
# Set environment variables
ENV PYTHONDONTWRITEBYTECODE=1
ENV PYTHONUNBUFFERED=1
# Set the working directory
WORKDIR /app
# Install system dependencies for faster builds
FROM base AS builder
RUN apt-get update && apt-get install -y --no-install-recommends \
gcc \
libpq-dev \
&& apt-get clean \
&& rm -rf /var/lib/apt/lists/*
# Copy only requirements first for better caching
COPY requirements.txt .
# Install Python dependencies with increased timeout and retry
RUN pip install --upgrade pip && \
pip install --default-timeout=600 --retries=10 -r requirements.txt --index-url=https://pypi.org/simple
# Copy the application code
FROM base
COPY --from=builder /app /app
# Command to run the application with dynamic worker count
CMD ["sh", "-c", "uvicorn api:app --host 0.0.0.0 --port 8000 --workers $(nproc)"]