-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathDockerfile.api
More file actions
47 lines (34 loc) · 1.19 KB
/
Dockerfile.api
File metadata and controls
47 lines (34 loc) · 1.19 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
# ---- Builder Stage ----
FROM python:3.11-slim AS builder
WORKDIR /app
# Install build-time system dependencies
RUN apt-get update && apt-get install -y --no-install-recommends build-essential
# Create a virtual environment
ENV VIRTUAL_ENV=/app/venv
RUN python3 -m venv $VIRTUAL_ENV
ENV PATH="$VIRTUAL_ENV/bin:$PATH"
# Copy and install dependencies into the virtual environment
COPY requirements-api.txt .
RUN pip install --no-cache-dir -r requirements-api.txt
# ---- Final Stage ----
FROM python:3.11-slim AS final
WORKDIR /app
# Set environment variables
ENV PYTHONDONTWRITEBYTECODE=1 \
PYTHONUNBUFFERED=1 \
PATH="/app/venv/bin:$PATH"
# Copy the virtual environment from the builder stage
COPY --from=builder /app/venv /app/venv
# Copy project files
COPY api/ /app/api/
COPY src/ /app/src/
COPY sdk/ /app/sdk/
COPY pyproject.toml /app/
COPY docker/scripts/healthcheck.py /app/docker/scripts/
# Expose port
EXPOSE 8000
# Health check
HEALTHCHECK --interval=30s --timeout=30s --start-period=5s --retries=3 \
CMD python /app/docker/scripts/healthcheck.py http://localhost:8000/api/health || exit 1
# Command to run the API
CMD ["uvicorn", "api.main:app", "--host", "0.0.0.0", "--port", "8000"]