-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathDockerfile.prod
44 lines (33 loc) · 1.21 KB
/
Dockerfile.prod
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
FROM python:3.9.19-alpine3.19 AS builder
LABEL maintainer="[email protected]"
# Set working directory
WORKDIR /app
# Set only build-relevant environment variables
ENV PIP_NO_CACHE_DIR=1 \
POETRY_VERSION=1.8.3 \
POETRY_HOME="/opt/poetry" \
POETRY_VIRTUALENVS_IN_PROJECT=false \
POETRY_NO_INTERACTION=1
# Install system dependencies and Poetry in a single layer
RUN apk add --no-cache gcc musl-dev libffi-dev \
&& pip install "poetry==$POETRY_VERSION"
# Copy only dependency files
COPY pyproject.toml poetry.lock ./
# Install dependencies directly to system Python and cleanup in the same layer
RUN poetry config virtualenvs.create false \
&& poetry install --no-root --only main \
&& rm -rf /root/.cache/pip/* \
&& rm -rf /root/.cache/poetry/* \
&& rm -rf /var/cache/apk/*
# Production image
FROM python:3.9.19-alpine3.19
# Set working directory and runtime environment variables
WORKDIR /app
RUN addgroup -S appgroup && adduser -S appuser -G appgroup
USER appuser
ENV PYTHONUNBUFFERED=1 \
PYTHONDONTWRITEBYTECODE=1 \
PYTHONPATH=/app
# Copy application code and dependencies
COPY ./ ./
COPY --from=builder /usr/local/lib/python3.9/site-packages/ /usr/local/lib/python3.9/site-packages/