Skip to content

Commit

Permalink
mostly remove graalpy from the final image to reduce size
Browse files Browse the repository at this point in the history
  • Loading branch information
timfel committed Jul 26, 2023
1 parent b1853f3 commit 505e645
Show file tree
Hide file tree
Showing 3 changed files with 38 additions and 42 deletions.
7 changes: 7 additions & 0 deletions docker/build_scripts/finalize.sh
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,13 @@ for PREFIX in $(find /opt/_internal/ -mindepth 1 -maxdepth 1 \( -name 'cpython*'
ln -s ${PREFIX}/bin/python /usr/local/bin/pypy${PY_VER}
elif [[ "${PREFIX}" == *"/graalpy"* ]]; then
ln -s ${PREFIX}/bin/python /usr/local/bin/graalpy${PY_VER}
# we remove most of graalpy itself, but symlink the install script to
# get the same version (same sha) back in the same place
ln -s ${PREFIX}/install-graalpy.sh /usr/local/bin/install-graalpy${PY_VER}
rm -rf ${PREFIX}/lib/graalpy*
rm -rf ${PREFIX}/lib/sulong*
rm -rf ${PREFIX}/lib/llvm*
rm -rf ${PREFIX}/lib/*.so
else
ln -s ${PREFIX}/bin/python /usr/local/bin/python${PY_VER}
fi
Expand Down
69 changes: 27 additions & 42 deletions docker/build_scripts/install-graalpy.sh
Original file line number Diff line number Diff line change
Expand Up @@ -14,53 +14,38 @@ if [ "${BASE_POLICY}" == "musllinux" ]; then
exit 0
fi

PYTHON_VERSION=$1
VERSION_PREFIX=$2
GRAALPY_VERSION=$3
ARCHIVE_PREFIX=$4
GRAALPY_DOWNLOAD_URL=https://github.com/oracle/graalpython/releases/download/${VERSION_PREFIX}-${GRAALPY_VERSION}/
# graal-23.0.0/graalpython-23.0.0-linux-amd64.tar.gz


function get_shortdir {
local exe=$1
$exe -c 'import sys; print(sys.implementation.cache_tag)'
}


mkdir -p /tmp
cd /tmp

case ${AUDITWHEEL_ARCH} in
x86_64) GRAALPY_ARCH=amd64;;
aarch64) GRAALPY_ARCH=aarch64;;
*) echo "No PyPy for ${AUDITWHEEL_ARCH}"; exit 0;;
*) echo "No GraalPy for ${AUDITWHEEL_ARCH}"; exit 0;;
esac

EXPAND_NAME=graalpy-${GRAALPY_VERSION}-linux-${GRAALPY_ARCH}
TMPDIR=/tmp/${EXPAND_NAME}
PYTHON_VERSION=$1
VERSION_PREFIX=$2
GRAALPY_VERSION=$3
ARCHIVE_PREFIX=$4
GRAALPY_DOWNLOAD_URL=https://github.com/oracle/graalpython/releases/download/${VERSION_PREFIX}-${GRAALPY_VERSION}/ # e.g. graal-23.0.0/graalpython-23.0.0-linux-amd64.tar.gz
TMPDIR=/tmp/
TARBALL=graalpython-${GRAALPY_VERSION}-linux-${GRAALPY_ARCH}.tar.gz
PREFIX="/opt/_internal"
TARBALL_SHA=`grep " ${TARBALL}\$" ${MY_DIR}/graalpy.sha256`
PREFIX="/opt/_internal/graalpy-${GRAALPY_VERSION}"

# create a download script that will download and extract graalpy. we leave
# this script in the image to avoid the large distribution to use up space in
# the default image.
mkdir -p ${PREFIX}

fetch_source ${TARBALL} ${GRAALPY_DOWNLOAD_URL}

# We only want to check the current tarball sha256sum
grep " ${TARBALL}\$" ${MY_DIR}/graalpy.sha256 > ${TARBALL}.sha256
# then check sha256 sum
sha256sum -c ${TARBALL}.sha256

tar -xf ${TARBALL}

# rename the directory to something shorter like graalpy230-310
PREFIX=${PREFIX}/$(get_shortdir ${TMPDIR}/bin/graalpy)
mv ${TMPDIR} ${PREFIX}

# add a generic "python" symlink
if [ ! -f "${PREFIX}/bin/python" ]; then
ln -s graalpy ${PREFIX}/bin/python
fi

# We do not need precompiled .pyc and .pyo files.
clean_pyc ${PREFIX}
cat <<EOF> ${PREFIX}/install-graalpy.sh
#!/bin/bash
set -exuo pipefail
mkdir -p ${PREFIX}
mkdir -p ${TMPDIR}
curl -fsSL -o "${TMPDIR}/${TARBALL}" "${GRAALPY_DOWNLOAD_URL}/${TARBALL}"
cd ${TMPDIR}
echo "${TARBALL_SHA}" | sha256sum -c
tar -xf "${TMPDIR}/${TARBALL}" --overwrite --strip-components=1 -C "${PREFIX}"
rm -f "${TMPDIR}/${TARBALL}"
EOF
# call the download script right now.
chmod +x ${PREFIX}/install-graalpy.sh
${PREFIX}/install-graalpy.sh
4 changes: 4 additions & 0 deletions tests/run_tests.sh
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,10 @@ else
exit 1
fi

# make sure all graalpy versions are available for testing
for INSTALLER in $(find /opt/_internal/ -mindepth 2 -maxdepth 2 \( -name 'install-graalpy.sh' \)); do
$INSTALLER
done

for PYTHON in /opt/python/*/bin/python; do
# Smoke test to make sure that our Pythons work, and do indeed detect as
Expand Down

0 comments on commit 505e645

Please sign in to comment.