|
1 | | -FROM python:3.7-alpine AS base |
| 1 | +FROM python:3.12-slim AS base |
2 | 2 |
|
3 | 3 | FROM base AS builder |
4 | 4 |
|
5 | | -ENV PIP_DISABLE_PIP_VERSION_CHECK=on |
6 | | -ENV PYTHONUNBUFFERED=1 |
| 5 | +ENV PIP_DISABLE_PIP_VERSION_CHECK=on \ |
| 6 | + PYTHONUNBUFFERED=1 \ |
| 7 | + POETRY_NO_INTERACTION=1 \ |
| 8 | + POETRY_VIRTUALENVS_IN_PROJECT=true \ |
| 9 | + POETRY_VIRTUALENVS_CREATE=true \ |
| 10 | + POETRY_CACHE_DIR=/tmp/poetry_cache |
7 | 11 |
|
8 | | -RUN apk update |
9 | | -RUN apk upgrade |
10 | | -RUN apk add --no-cache build-base musl-dev python3-dev libffi-dev openssl-dev |
| 12 | +# Install build dependencies |
| 13 | +RUN apt-get update && apt-get install -y --no-install-recommends \ |
| 14 | + build-essential \ |
| 15 | + && rm -rf /var/lib/apt/lists/* |
11 | 16 |
|
12 | | -RUN python -m venv /opt/venv |
13 | | -# Make sure we use the virtualenv: |
14 | | -ENV PATH="/opt/venv/bin:$PATH" |
| 17 | +WORKDIR /app |
15 | 18 |
|
16 | | -COPY poetry.lock pyproject.toml ./ |
| 19 | +# Install poetry |
| 20 | +RUN pip install --no-cache-dir poetry |
17 | 21 |
|
18 | | -RUN pip install poetry |
19 | | -RUN poetry config virtualenvs.create false |
20 | | -RUN poetry install --only=main --compile --no-interaction --no-cache |
| 22 | +# Copy dependency files |
| 23 | +COPY pyproject.toml poetry.lock README.md ./ |
| 24 | +COPY pybot ./pybot |
21 | 25 |
|
22 | | -# The `built-image` stage is the base for all remaining images |
23 | | -# Pulls all of the built dependencies from the builder stage |
24 | | -FROM base AS built-image |
25 | | -ENV PIP_DISABLE_PIP_VERSION_CHECK=on |
26 | | -ENV PYTHONUNBUFFERED=1 |
| 26 | +# Install dependencies into .venv in project |
| 27 | +RUN poetry install --only=main --no-interaction --no-cache && \ |
| 28 | + rm -rf $POETRY_CACHE_DIR |
27 | 29 |
|
28 | | -RUN apk update |
29 | | -RUN apk upgrade |
30 | | -RUN rm -rf /var/cache/apk/* |
| 30 | +# Production image |
| 31 | +FROM base AS prod |
31 | 32 |
|
32 | | -# copy installed deps from builder image |
33 | | -COPY --from=builder /opt/venv /opt/venv |
| 33 | +ENV PIP_DISABLE_PIP_VERSION_CHECK=on \ |
| 34 | + PYTHONUNBUFFERED=1 \ |
| 35 | + PATH="/app/.venv/bin:$PATH" |
34 | 36 |
|
35 | | -# Make sure we use the virtualenv |
36 | | -ENV PATH="/opt/venv/bin:$PATH" |
| 37 | +WORKDIR /app |
37 | 38 |
|
38 | | -# The `app` stage is used as the base for images that don't |
39 | | -# need the development dependencies |
40 | | -FROM built-image AS app |
| 39 | +# Copy application and virtual environment from builder |
| 40 | +COPY --from=builder /app ./ |
41 | 41 |
|
42 | | -COPY . /src |
43 | | -WORKDIR /src |
44 | | - |
45 | | -# The `prod` stage creates an image that will run the application using a |
46 | | -# production webserver and the `environments/production.py` configuration |
47 | | -FROM app AS prod |
48 | | -ENTRYPOINT ["python3", "-m", "pybot"] |
| 42 | +CMD ["python", "-m", "pybot"] |
0 commit comments