Skip to content

Commit

Permalink
Merge pull request dependabot#6466 from dependabot/pavera/python-mult…
Browse files Browse the repository at this point in the history
…istage

Build python in parallel with multistage
  • Loading branch information
pavera authored Jan 19, 2023
2 parents 2b57484 + 3f4995e commit bd376f0
Show file tree
Hide file tree
Showing 2 changed files with 113 additions and 22 deletions.
114 changes: 92 additions & 22 deletions Dockerfile.python
Original file line number Diff line number Diff line change
@@ -1,4 +1,15 @@
FROM ghcr.io/dependabot/dependabot-updater-core
ARG PY_3_11=3.11.1
ARG PY_3_10=3.10.9
ARG PY_3_9=3.9.16
ARG PY_3_8=3.8.16
ARG PY_3_7=3.7.16

FROM ghcr.io/dependabot/dependabot-updater-core as python-core
ARG PY_3_11
ARG PY_3_10
ARG PY_3_9
ARG PY_3_8
ARG PY_3_7
USER root

RUN apt-get update \
Expand Down Expand Up @@ -36,34 +47,93 @@ RUN apt-get update \
libgeos-dev \
python3-enchant

### PYTHON
COPY --chown=dependabot:dependabot python/helpers /opt/python/helpers
# Install Python with pyenv.
USER root
ENV PYENV_ROOT=/usr/local/.pyenv \
PATH="/usr/local/.pyenv/bin:$PATH"
RUN mkdir -p "$PYENV_ROOT" && chown dependabot:dependabot "$PYENV_ROOT"
USER dependabot
ENV DEPENDABOT_NATIVE_HELPERS_PATH="/opt"
RUN git -c advice.detachedHead=false clone https://github.com/pyenv/pyenv.git --branch v2.3.9 --single-branch --depth=1 /usr/local/.pyenv \
# This is the version of CPython that gets installed
&& pyenv install 3.11.1 \
&& pyenv global 3.11.1 \
&& pyenv install 3.10.9 \
&& pyenv install 3.9.16 \
&& pyenv install 3.8.16 \
&& pyenv install 3.7.16 \
&& rm -Rf /tmp/python-build* \
&& bash /opt/python/helpers/build \
RUN git -c advice.detachedHead=false clone https://github.com/pyenv/pyenv.git --branch v2.3.9 --single-branch --depth=1 /usr/local/.pyenv

FROM python-core as python-3.10
RUN pyenv install $PY_3_10 \
&& bash /opt/python/helpers/build_for_version $PY_3_10 \
&& cd /usr/local/.pyenv \
&& tar czf 3.10.tar.gz versions/$PY_3_10

FROM python-core as python-3.9
RUN pyenv install $PY_3_9 \
&& bash /opt/python/helpers/build_for_version $PY_3_9 \
&& cd /usr/local/.pyenv \
&& tar czf 3.9.tar.gz versions/$PY_3_9

FROM python-core as python-3.8
RUN pyenv install $PY_3_8 \
&& bash /opt/python/helpers/build_for_version $PY_3_8 \
&& cd /usr/local/.pyenv \
&& tar czf 3.8.tar.gz versions/$PY_3_8

FROM python-core as python-3.7
RUN pyenv install $PY_3_7 \
&& bash /opt/python/helpers/build_for_version $PY_3_7 \
&& cd /usr/local/.pyenv \
&& tar czf 3.10.tar.gz versions/3.10.9 \
&& tar czf 3.9.tar.gz versions/3.9.16 \
&& tar czf 3.8.tar.gz versions/3.8.16 \
&& tar czf 3.7.tar.gz versions/3.7.16 \
&& rm -Rf versions/3.10.9 \
&& rm -Rf versions/3.9.16 \
&& rm -Rf versions/3.8.16 \
&& rm -Rf versions/3.7.16
&& tar czf 3.7.tar.gz versions/$PY_3_7


FROM ghcr.io/dependabot/dependabot-updater-core
ARG PY_3_11
USER root
RUN apt-get update \
&& apt-get upgrade -y \
&& apt-get install -y --no-install-recommends \
dirmngr \
gnupg2 \
zlib1g-dev \
liblzma-dev \
libgdbm-dev \
bison \
tzdata \
zip \
unzip \
openssh-client \
software-properties-common \
curl \
build-essential \
make \
libpq-dev \
libssl-dev \
libbz2-dev \
libffi-dev \
libreadline-dev \
libsqlite3-dev \
libcurl4-openssl-dev \
llvm \
libncurses5-dev \
libncursesw5-dev \
libmysqlclient-dev \
xz-utils \
tk-dev \
libxml2-dev \
libxmlsec1-dev \
libgeos-dev \
python3-enchant

### PYTHON
COPY --chown=dependabot:dependabot python/helpers /opt/python/helpers
USER root
ENV PYENV_ROOT=/usr/local/.pyenv \
PATH="/usr/local/.pyenv/bin:$PATH"
RUN mkdir -p "$PYENV_ROOT" && chown dependabot:dependabot "$PYENV_ROOT"
USER dependabot
COPY --chown=dependabot:dependabot python /home/dependabot/python
ENV DEPENDABOT_NATIVE_HELPERS_PATH="/opt"
RUN git -c advice.detachedHead=false clone https://github.com/pyenv/pyenv.git --branch v2.3.9 --single-branch --depth=1 /usr/local/.pyenv
RUN pyenv install $PY_3_11 \
&& pyenv global $PY_3_11 \
&& bash /opt/python/helpers/build_for_version $PY_3_11

COPY --from=python-3.10 /usr/local/.pyenv/3.10.tar.gz /usr/local/.pyenv/3.10.tar.gz
COPY --from=python-3.9 /usr/local/.pyenv/3.9.tar.gz /usr/local/.pyenv/3.9.tar.gz
COPY --from=python-3.8 /usr/local/.pyenv/3.8.tar.gz /usr/local/.pyenv/3.8.tar.gz
COPY --from=python-3.7 /usr/local/.pyenv/3.7.tar.gz /usr/local/.pyenv/3.7.tar.gz
COPY --chown=dependabot:dependabot python /home/dependabot/python
21 changes: 21 additions & 0 deletions python/helpers/build_for_version
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
#!/bin/bash

set -e

if [ -z "$DEPENDABOT_NATIVE_HELPERS_PATH" ]; then
echo "Unable to build, DEPENDABOT_NATIVE_HELPERS_PATH is not set"
exit 1
fi

install_dir="$DEPENDABOT_NATIVE_HELPERS_PATH/python"
mkdir -p "$install_dir"

helpers_dir="$(dirname "${BASH_SOURCE[0]}")"
cp -r \
"$helpers_dir/lib" \
"$helpers_dir/run.py" \
"$helpers_dir/requirements.txt" \
"$install_dir"

cd "$install_dir"
PYENV_VERSION=$1 pyenv exec pip --disable-pip-version-check install --use-pep517 -r "requirements.txt"

0 comments on commit bd376f0

Please sign in to comment.