|
1 |
| -# Use the official Python image as base |
2 |
| -FROM python:3-slim-bullseye as python-base |
| 1 | +FROM python:3-slim-bullseye AS python-base |
3 | 2 |
|
4 |
| -# Set environment variables |
5 | 3 | ENV PYTHONUNBUFFERED=1 \
|
6 |
| - PYTHONDONTWRITEBYTECODE=1 \ |
7 |
| - PIP_NO_CACHE_DIR=off \ |
8 |
| - PIP_DISABLE_PIP_VERSION_CHECK=on \ |
9 |
| - PIP_DEFAULT_TIMEOUT=100 \ |
10 |
| - POETRY_HOME="/opt/poetry" \ |
11 |
| - POETRY_VIRTUALENVS_IN_PROJECT=true \ |
12 |
| - POETRY_NO_INTERACTION=1 \ |
13 |
| - PYSETUP_PATH="/opt/pysetup" \ |
14 |
| - VENV_PATH="/opt/pysetup/.venv" |
15 |
| - |
16 |
| -ENV PATH="$POETRY_HOME/bin:$VENV_PATH/bin:$PATH" |
17 |
| - |
18 |
| -FROM python-base as builder-base |
19 |
| - |
20 |
| -# Install system dependencies |
21 |
| -RUN apt-get update && apt-get install -y --no-install-recommends curl build-essential && \ |
| 4 | + PYTHONDONTWRITEBYTECODE=1 \ |
| 5 | + PIP_NO_CACHE_DIR=on \ |
| 6 | + PIP_DISABLE_PIP_VERSION_CHECK=on \ |
| 7 | + PIP_DEFAULT_TIMEOUT=100 \ |
| 8 | + POETRY_HOME="/opt/poetry" \ |
| 9 | + POETRY_VIRTUALENVS_IN_PROJECT=true \ |
| 10 | + POETRY_NO_INTERACTION=1 \ |
| 11 | + PATH="/opt/poetry/bin:$PATH" |
| 12 | + |
| 13 | +FROM python-base AS builder-base |
| 14 | + |
| 15 | +RUN apt-get update && \ |
| 16 | + apt-get install --no-install-recommends -y \ |
| 17 | + curl \ |
| 18 | + build-essential && \ |
22 | 19 | apt-get clean && \
|
23 | 20 | rm -rf /var/lib/apt/lists/*
|
24 | 21 |
|
25 |
| -# Install poetry |
26 |
| -RUN curl -sSL https://install.python-poetry.org | python3 - |
| 22 | +RUN --mount=type=cache,target=/root/.cache \ |
| 23 | + curl -sSL https://install.python-poetry.org | python3 - |
27 | 24 |
|
28 |
| -# Set the working directory in the container |
29 |
| -WORKDIR $PYSETUP_PATH |
| 25 | +WORKDIR /opt/pysetup |
| 26 | +COPY poetry.lock pyproject.toml ./ |
30 | 27 |
|
31 |
| -# Copy the poetry files |
32 |
| -COPY ./poetry.lock ./pyproject.toml ./ |
| 28 | +RUN --mount=type=cache,target=/root/.cache \ |
| 29 | + poetry install --no-root --without=dev |
33 | 30 |
|
34 |
| -# Install project dependencies |
35 |
| -RUN poetry install --no-root --no-dev |
| 31 | +COPY ./src /opt/pysetup/src |
36 | 32 |
|
37 |
| -FROM python-base as runtime |
38 |
| - |
39 |
| -# Copy the source code into the container |
40 |
| -COPY --from=builder-base $VENV_PATH $VENV_PATH |
41 |
| -COPY src/ /app |
| 33 | +FROM python-base AS runtime |
| 34 | +COPY --from=builder-base /opt/pysetup /opt/pysetup |
| 35 | +COPY ./src /app |
42 | 36 | WORKDIR /app
|
43 |
| - |
44 |
| -# Run the bot |
45 | 37 | CMD ["python", "-u", "main.py"]
|
0 commit comments