Skip to content
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit 505e645

Browse files
committedJul 26, 2023
mostly remove graalpy from the final image to reduce size
1 parent b1853f3 commit 505e645

File tree

3 files changed

+38
-42
lines changed

3 files changed

+38
-42
lines changed
 

‎docker/build_scripts/finalize.sh

+7
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,13 @@ for PREFIX in $(find /opt/_internal/ -mindepth 1 -maxdepth 1 \( -name 'cpython*'
3232
ln -s ${PREFIX}/bin/python /usr/local/bin/pypy${PY_VER}
3333
elif [[ "${PREFIX}" == *"/graalpy"* ]]; then
3434
ln -s ${PREFIX}/bin/python /usr/local/bin/graalpy${PY_VER}
35+
# we remove most of graalpy itself, but symlink the install script to
36+
# get the same version (same sha) back in the same place
37+
ln -s ${PREFIX}/install-graalpy.sh /usr/local/bin/install-graalpy${PY_VER}
38+
rm -rf ${PREFIX}/lib/graalpy*
39+
rm -rf ${PREFIX}/lib/sulong*
40+
rm -rf ${PREFIX}/lib/llvm*
41+
rm -rf ${PREFIX}/lib/*.so
3542
else
3643
ln -s ${PREFIX}/bin/python /usr/local/bin/python${PY_VER}
3744
fi

‎docker/build_scripts/install-graalpy.sh

+27-42
Original file line numberDiff line numberDiff line change
@@ -14,53 +14,38 @@ if [ "${BASE_POLICY}" == "musllinux" ]; then
1414
exit 0
1515
fi
1616

17-
PYTHON_VERSION=$1
18-
VERSION_PREFIX=$2
19-
GRAALPY_VERSION=$3
20-
ARCHIVE_PREFIX=$4
21-
GRAALPY_DOWNLOAD_URL=https://github.com/oracle/graalpython/releases/download/${VERSION_PREFIX}-${GRAALPY_VERSION}/
22-
# graal-23.0.0/graalpython-23.0.0-linux-amd64.tar.gz
23-
24-
25-
function get_shortdir {
26-
local exe=$1
27-
$exe -c 'import sys; print(sys.implementation.cache_tag)'
28-
}
29-
30-
31-
mkdir -p /tmp
32-
cd /tmp
33-
3417
case ${AUDITWHEEL_ARCH} in
3518
x86_64) GRAALPY_ARCH=amd64;;
3619
aarch64) GRAALPY_ARCH=aarch64;;
37-
*) echo "No PyPy for ${AUDITWHEEL_ARCH}"; exit 0;;
20+
*) echo "No GraalPy for ${AUDITWHEEL_ARCH}"; exit 0;;
3821
esac
3922

40-
EXPAND_NAME=graalpy-${GRAALPY_VERSION}-linux-${GRAALPY_ARCH}
41-
TMPDIR=/tmp/${EXPAND_NAME}
23+
PYTHON_VERSION=$1
24+
VERSION_PREFIX=$2
25+
GRAALPY_VERSION=$3
26+
ARCHIVE_PREFIX=$4
27+
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
28+
TMPDIR=/tmp/
4229
TARBALL=graalpython-${GRAALPY_VERSION}-linux-${GRAALPY_ARCH}.tar.gz
43-
PREFIX="/opt/_internal"
30+
TARBALL_SHA=`grep " ${TARBALL}\$" ${MY_DIR}/graalpy.sha256`
31+
PREFIX="/opt/_internal/graalpy-${GRAALPY_VERSION}"
4432

33+
# create a download script that will download and extract graalpy. we leave
34+
# this script in the image to avoid the large distribution to use up space in
35+
# the default image.
4536
mkdir -p ${PREFIX}
46-
47-
fetch_source ${TARBALL} ${GRAALPY_DOWNLOAD_URL}
48-
49-
# We only want to check the current tarball sha256sum
50-
grep " ${TARBALL}\$" ${MY_DIR}/graalpy.sha256 > ${TARBALL}.sha256
51-
# then check sha256 sum
52-
sha256sum -c ${TARBALL}.sha256
53-
54-
tar -xf ${TARBALL}
55-
56-
# rename the directory to something shorter like graalpy230-310
57-
PREFIX=${PREFIX}/$(get_shortdir ${TMPDIR}/bin/graalpy)
58-
mv ${TMPDIR} ${PREFIX}
59-
60-
# add a generic "python" symlink
61-
if [ ! -f "${PREFIX}/bin/python" ]; then
62-
ln -s graalpy ${PREFIX}/bin/python
63-
fi
64-
65-
# We do not need precompiled .pyc and .pyo files.
66-
clean_pyc ${PREFIX}
37+
cat <<EOF> ${PREFIX}/install-graalpy.sh
38+
#!/bin/bash
39+
set -exuo pipefail
40+
mkdir -p ${PREFIX}
41+
mkdir -p ${TMPDIR}
42+
curl -fsSL -o "${TMPDIR}/${TARBALL}" "${GRAALPY_DOWNLOAD_URL}/${TARBALL}"
43+
cd ${TMPDIR}
44+
echo "${TARBALL_SHA}" | sha256sum -c
45+
tar -xf "${TMPDIR}/${TARBALL}" --overwrite --strip-components=1 -C "${PREFIX}"
46+
rm -f "${TMPDIR}/${TARBALL}"
47+
EOF
48+
49+
# call the download script right now.
50+
chmod +x ${PREFIX}/install-graalpy.sh
51+
${PREFIX}/install-graalpy.sh

‎tests/run_tests.sh

+4
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,10 @@ else
1717
exit 1
1818
fi
1919

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

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

0 commit comments

Comments
 (0)
Please sign in to comment.