Skip to content

Commit

Permalink
chore(superchain): replace pyenv with pipx
Browse files Browse the repository at this point in the history
In #4201, we introduced a Python distribution built with `pyenv`
in order to safely install some Python packages globally.

However, using pyenv drives the build time of the images up from 30m to
3 hours.

This PR switches back to the distro Python and installs `pipx` to
do global installs of Python packages. `pipx` will give each tool
its own venv (similar to how `npm install -g` would work).
  • Loading branch information
rix0rrr committed Aug 10, 2023
1 parent d005937 commit 3419da7
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 36 deletions.
41 changes: 15 additions & 26 deletions superchain/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,6 @@ ENV LANG="C.UTF-8"
RUN apt-get update \
&& apt-get -y upgrade \
&& apt-get -y install --no-install-recommends \
acl \
apt-transport-https \
build-essential \
ca-certificates \
Expand All @@ -134,25 +133,15 @@ RUN apt-get update
git \
gnupg \
gzip \
libbz2-dev \
libffi-dev \
libicu-dev \
liblzma-dev \
libncursesw5-dev \
libreadline-dev \
libsqlite3-dev \
libssl-dev \
libxml2-dev \
libxmlsec1-dev \
openssh-client \
openssl \
rsync \
sudo \
tk-dev \
unzip \
xz-utils \
zip \
zlib1g-dev \
acl \
&& rm -rf /var/lib/apt/lists/*

# Install mono
Expand All @@ -174,18 +163,20 @@ RUN set -eo pipefail
&& chmod -R a+rw ${CARGO_HOME}
ENV PATH=$PATH:${CARGO_HOME}/bin

# Install Python 3
ENV PYENV_ROOT="/opt/pyenv"
RUN curl -fSsL "https://pyenv.run" | bash \
&& command -v pyenv >/dev/null || export PATH="$PYENV_ROOT/bin:$PATH" \
&& eval "$(pyenv init -)" \
&& PYTHON_CONFIGURE_OPTS='--enable-optimizations --with-lto' pyenv install 3.8 \
&& pyenv global 3.8 \
&& python3 -m pip install --no-input --upgrade pip \
&& python3 -m pip install --no-input --upgrade black setuptools twine wheel aws-sam-cli \
&& rm -rf $(pip cache dir) \
# Install Python 3 and pipx
# (Can't use 'apt-get install pipx because that's only available starting in bookworm, so we need to be nasty)
RUN apt-get update \
&& apt-get -y install python3-dev python3-pip python3-venv \
&& python3 -m pip install --break-system-packages pipx \
&& rm -rf /var/lib/apt/lists/*

# Install Python tools globally using pipx (install globally)
ENV PIPX_HOME=/opt/pipx
ENV PIPX_BIN_DIR=/usr/local/bin
RUN pipx install black \
&& pipx install twine \
&& pipx install aws-sam-cli

# Install AWS CLI v2
ENV AWS_CLI_V2_URL='https://awscli.amazonaws.com/awscli-exe-linux-x86_64.zip'
RUN curl "${AWS_CLI_V2_URL}" -o "/tmp/awscliv2.zip" \
Expand Down Expand Up @@ -410,10 +401,8 @@ ENV LANG="C.UTF-8"
\
GOROOT="/opt/golang/go" \
RUSTUP_HOME="/usr/local/rustup" \
CARGO_HOME="/usr/local/cargo" \
\
PYENV_ROOT="/opt/pyenv"
ENV PATH="${PYENV_ROOT}/shims:${PATH}:${CARGO_HOME}/bin:${GOROOT}/bin:${M2}:${PYENV_ROOT}/bin"
CARGO_HOME="/usr/local/cargo"
ENV PATH="${PATH}:${CARGO_HOME}/bin:${GOROOT}/bin:${M2}"

COPY --from=staging / /
VOLUME /var/lib/docker
Expand Down
13 changes: 3 additions & 10 deletions superchain/build-local.sh
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
#!/bin/bash
set -euo pipefail
scriptdir=$(cd $(dirname $0) && pwd)
cd $scriptdir

###
# This script can be used to build a jsii/superchain:local image from a locally
Expand All @@ -24,17 +26,8 @@ if [[ "${PLATFORM}" == "x86_64" ]]; then
PLATFORM="amd64"
fi

if command -v docker >/dev/null; then
DOCKER=docker
elif command -v finch >/dev/null; then
DOCKER=finch
else
echo "Could not find 'docker' or 'finch' in PATH, aborting..."
exit 1
fi

# Now on to building the image
${DOCKER} build \
${DOCKER:-docker} build \
--target superchain \
--build-arg BUILDPLATFORM=linux/${PLATFORM} \
--build-arg TARGETPLATFORM=linux/${PLATFORM} \
Expand Down

0 comments on commit 3419da7

Please sign in to comment.