forked from Lead-Studios/veritix-python
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathDockerfile
More file actions
42 lines (31 loc) · 1.4 KB
/
Dockerfile
File metadata and controls
42 lines (31 loc) · 1.4 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
# Dockerfile
# Stage 1: Build Stage
# Use a slim, official Python image for efficiency
FROM python:3.11-slim AS builder
# Set the working directory inside the container
WORKDIR /app
# Prevent Python from writing .pyc files and buffering stdout/stderr
ENV PYTHONDONTWRITEBYTECODE=1
ENV PYTHONUNBUFFERED=1
# Copy only the requirements file first to take advantage of Docker layer caching
COPY requirements.txt .
# Install dependencies with increased timeout and retry
RUN pip install --no-cache-dir --timeout=300 --retries=3 --trusted-host pypi.org --trusted-host pypi.python.org --trusted-host files.pythonhosted.org -r requirements.txt
# Stage 2: Production Stage (using the same slim image)
FROM python:3.11-slim
# Set the working directory
WORKDIR /app
# Copy installed packages from the builder stage
COPY --from=builder /usr/local/lib/python3.11/site-packages /usr/local/lib/python3.11/site-packages
# Copy the application source code (src/ and tests/)
# This copies everything from the host's current directory into /app inside the container
COPY src /app/src
COPY tests /app/tests
COPY requirements.txt /app/
COPY run.py /app/
# Port the application listens on
EXPOSE 8000
# Command to run the application using Uvicorn
# The command format is: uvicorn [module:app_object] --host [ip] --port [port]
# We use the standard uvicorn worker configuration
CMD ["uvicorn", "src.main:app", "--host", "0.0.0.0", "--port", "8000"]