1+ # TODO: Find out whether it possible to use "faster" base Python image
12FROM python:3.9.2-slim-buster as python-base
23
34LABEL maintainer="Igor Davydenko <iam@igordavydenko.com>"
45LABEL description="Add poetry, pre-commit, and other dev-tools to official Python slim Docker image."
56
6- # poetry envirnment
7- ENV POETRY_HOME="/opt/poetry"
8- ENV POETRY_NO_INTERACTION=1
7+ # Ensure to use latest system versions
8+ RUN apt update -qq && apt upgrade -y && apt autoremove -y
99
10- # versions
11- ENV POETRY_VERSION=1.1.4
12- ENV PIP_VERSION 20.3.3
13- ENV PRE_COMMIT_VERSION 2.9.3
14- ENV TOX_VERSION 3.20.1
15- ENV VIRTUALENV_VERSION 20.2.2
10+ # Global poetry setup
11+ ENV POETRY_HOME "/opt/poetry"
12+ ENV POETRY_NO_INTERACTION "1"
13+ ENV PATH "${POETRY_HOME}/bin:${PATH}"
1614
17- # additonal applications to install
15+ # Install poetry at one stage
16+ FROM python-base as poetry-base
17+
18+ ENV POETRY_VERSION "1.1.4"
19+ RUN apt install -y build-essential curl
20+ RUN curl -sSL https://raw.githubusercontent.com/sdispater/poetry/master/get-poetry.py | python
21+ RUN poetry --version
22+
23+ # Install dev tools at another stage
24+ FROM python-base as development-base
25+
26+ # Additonal applications to install
1827ENV ADDITIONAL_APPS \
1928 curl \
29+ g++ \
30+ gcc \
2031 gettext \
2132 git \
2233 locales \
@@ -25,31 +36,26 @@ ENV ADDITIONAL_APPS \
2536 nano \
2637 openssh-client \
2738 rsync
39+ RUN apt install -y ${ADDITIONAL_APPS} && apt autoremove -y
40+
41+ # To check latest versions,
42+ #
43+ # ```bash
44+ # pip-latest-release pip pre-commit tox virtualenv
45+ # ```
46+ ENV PIP_VERSION "21.0.1"
47+ ENV PRE_COMMIT_VERSION "2.10.1"
48+ ENV TOX_VERSION "3.22.0"
49+ ENV VIRTUALENV_VERSION "20.4.2"
2850
29- # prepend poetry
30- ENV PATH="$POETRY_HOME/bin:$PATH"
31-
32- RUN apt update -qq \
33- && apt upgrade -y \
34- && apt autoremove -y
35-
36- FROM python-base as poetry-builder-base
37- RUN apt install -y \
38- curl \
39- build-essential
40- RUN curl -sSL https://raw.githubusercontent.com/sdispater/poetry/master/get-poetry.py | python
41- RUN poetry --version
42-
43-
44- FROM python-base as development-base
45- RUN apt install -y $ADDITIONAL_APPS && apt autoremove -y
4651RUN pip install \
47- pip==$PIP_VERSION \
48- pre-commit==$PRE_COMMIT_VERSION \
49- tox==$TOX_VERSION \
50- virtualenv==$VIRTUALENV_VERSION
52+ pip==${ PIP_VERSION} \
53+ pre-commit==${ PRE_COMMIT_VERSION} \
54+ tox==${ TOX_VERSION} \
55+ virtualenv==${ VIRTUALENV_VERSION}
5156
52- COPY --from=poetry-builder-base $POETRY_HOME $POETRY_HOME
57+ # Copy poetry from previous stage
58+ COPY --from=poetry-base ${POETRY_HOME} ${POETRY_HOME}
5359
5460WORKDIR /app
5561CMD ["python3" ]
0 commit comments