-
Notifications
You must be signed in to change notification settings - Fork 0
/
Dockerfile
49 lines (35 loc) · 1.23 KB
/
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
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
# Stage 1: Builder - install dependencies using Poetry
FROM python:3.11-slim AS builder
# --- Install Poetry ---
ARG POETRY_VERSION=1.8
ENV POETRY_HOME=/opt/poetry
ENV POETRY_NO_INTERACTION=1
ENV POETRY_VIRTUALENVS_IN_PROJECT=1
ENV POETRY_VIRTUALENVS_CREATE=1
ENV PYTHONDONTWRITEBYTECODE=1
ENV PYTHONUNBUFFERED=1
# Poetry cache for dependencies
ENV POETRY_CACHE_DIR=/opt/.cache
# Install Poetry
RUN pip install "poetry==${POETRY_VERSION}"
WORKDIR /app
# --- Install dependencies ---
# Copy only the dependency definitions
COPY pyproject.toml poetry.lock ./
# Install dependencies in a virtual environment
RUN poetry install --no-root && rm -rf $POETRY_CACHE_DIR
# Stage 2: Runtime - copy the app and virtual environment from the builder
FROM python:3.11-slim AS runtime
# Set up the virtual environment path
ENV VIRTUAL_ENV=/app/.venv
ENV PATH="/app/.venv/bin:$PATH"
# Copy the virtual environment from the builder stage
COPY --from=builder /app/.venv /app/.venv
# Copy the FastAPI app code
COPY ./data_security_service /app/data_security_service
# Set working directory
WORKDIR /app/data_security_service
# Expose the port for the FastAPI app
EXPOSE 8001
# Start FastAPI server
CMD ["uvicorn", "main:app", "--host", "0.0.0.0", "--port", "8001"]