22FROM python:3.12-slim
33
44# Set environment variables for Python and prevent the creation of .pyc files
5- ENV PYTHONDONTWRITEBYTECODE=1
6- ENV PYTHONUNBUFFERED=1
5+ ARG BUILD_ENVIRONMENT
6+
7+ ENV BUILD_ENVIRONMENT=${BUILD_ENVIRONMENT} \
8+ PYTHONDONTWRITEBYTECODE=1 \
9+ PYTHONFAULTHANDLER=1 \
10+ PYTHONUNBUFFERED=1 \
11+ PYTHONHASHSEED=random \
12+ PIP_NO_CACHE_DIR=off \
13+ PIP_DISABLE_PIP_VERSION_CHECK=on \
14+ PIP_DEFAULT_TIMEOUT=100 \
15+ # Poetry's configuration:
16+ POETRY_NO_INTERACTION=1 \
17+ POETRY_VIRTUALENVS_CREATE=false \
18+ POETRY_CACHE_DIR='/var/cache/pypoetry' \
19+ POETRY_HOME='/usr/local' \
20+ POETRY_VERSION=1.8.3
721
822# Install OS dependencies required for building some Python packages
923RUN apt-get update && apt-get install -y --no-install-recommends \
@@ -12,7 +26,7 @@ RUN apt-get update && apt-get install -y --no-install-recommends \
1226 && rm -rf /var/lib/apt/lists/*
1327
1428# Install Poetry
15- RUN pip install --upgrade pip && pip install poetry
29+ RUN pip install --upgrade pip && curl -sSL https://install.python- poetry.org | python3 -
1630
1731# Set working directory
1832WORKDIR /app
@@ -21,8 +35,7 @@ WORKDIR /app
2135COPY pyproject.toml poetry.lock* /app/
2236
2337# Configure Poetry to not create a virtual environment and install dependencies
24- RUN poetry config virtualenvs.create false && \
25- poetry install --no-interaction --no-ansi --no-dev
38+ RUN poetry install $(test "$BUILD_ENVIRONMENT" == production && echo "--only=main" )
2639
2740# Copy the rest of the project
2841COPY . /app
0 commit comments