From 67bd15c1b586f35b42ba19f08c928ba654af3045 Mon Sep 17 00:00:00 2001 From: Pavlo Shchelokovskyy Date: Mon, 3 Oct 2016 20:24:36 +0300 Subject: [PATCH] [tinyipa] allow skipping python compileall Somtimes it is useful to have tinyipa image with normal Python experience (access to source code for debugging, Python interpreter). This patch allows to skip compiling all Python to *.pyo and removing all *.py[c] files by setting export PYOPTIMIZE_TINYIPA=false in the shell before running the build scripts. Change-Id: I570d5a30af0f6a0c9de533e61d03ad5c198c2864 Closes-Bug: #1629953 --- imagebuild/tinyipa/README.rst | 17 +++++++++++++++++ imagebuild/tinyipa/finalise-tinyipa.sh | 17 +++++++++++------ 2 files changed, 28 insertions(+), 6 deletions(-) diff --git a/imagebuild/tinyipa/README.rst b/imagebuild/tinyipa/README.rst index aa2165213..c8476bddf 100644 --- a/imagebuild/tinyipa/README.rst +++ b/imagebuild/tinyipa/README.rst @@ -72,12 +72,29 @@ or:: Advanced options ---------------- +(De)Optimizing the image +~~~~~~~~~~~~~~~~~~~~~~~~ + If you want the build script to preinstall everything into the ramdisk, instead of loading some things at runtime (this results in a slightly bigger ramdisk), before running make or build-tinyipa.sh run:: export BUILD_AND_INSTALL_TINYIPA=true +By default, building TinyIPA will compile most of the Python code to +optimized ``*.pyo`` files, completely remove most of ``*.py`` and ``*.pyc`` +files, and run ironic-python-agent with ``PYTHONOPTIMIZE=1`` +to save space on the ramdisk. +If instead you want a normal Python experience inside the image, +for example for debugging/hacking on IPA in a running ramdisk, +before running make or build-tinyipa.sh run:: + + export PYOPTIMIZE_TINYIPA=false + + +Enabling SSH access to the ramdisk +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + If you want to enable SSH access to the image, set ``ENABLE_SSH`` variable in your shell before building the tinyipa:: diff --git a/imagebuild/tinyipa/finalise-tinyipa.sh b/imagebuild/tinyipa/finalise-tinyipa.sh index 023130be3..891590cf3 100755 --- a/imagebuild/tinyipa/finalise-tinyipa.sh +++ b/imagebuild/tinyipa/finalise-tinyipa.sh @@ -8,6 +8,7 @@ BUILD_AND_INSTALL_TINYIPA=${BUILD_AND_INSTALL_TINYIPA:-true} TINYCORE_MIRROR_URL=${TINYCORE_MIRROR_URL:-"http://repo.tinycorelinux.net/"} ENABLE_SSH=${ENABLE_SSH:-false} SSH_PUBLIC_KEY=${SSH_PUBLIC_KEY:-} +PYOPTIMIZE_TINYIPA=${PYOPTIMIZE_TINYIPA:-true} TC=1001 STAFF=50 @@ -147,12 +148,16 @@ sudo cp "$WORKDIR/build_files/bootlocal.sh" "$FINALDIR/opt/." sudo sed -i '/# Main/a NOZSWAP=1' "$FINALDIR/etc/init.d/tc-config" # sudo cp $WORKDIR/build_files/tc-config $FINALDIR/etc/init.d/tc-config -# Precompile all python -set +e -$CHROOT_CMD /bin/bash -c "python -OO -m compileall /usr/local/lib/python2.7" -set -e -find $FINALDIR/usr/local/lib/python2.7 -name "*.py" -not -path "*ironic_python_agent/api/config.py" | sudo xargs rm -find $FINALDIR/usr/local/lib/python2.7 -name "*.pyc" | sudo xargs rm +if $PYOPTIMIZE_TINYIPA; then + # Precompile all python + set +e + $CHROOT_CMD /bin/bash -c "python -OO -m compileall /usr/local/lib/python2.7" + set -e + find $FINALDIR/usr/local/lib/python2.7 -name "*.py" -not -path "*ironic_python_agent/api/config.py" | sudo xargs rm + find $FINALDIR/usr/local/lib/python2.7 -name "*.pyc" | sudo xargs rm +else + sudo sed -i "s/PYTHONOPTIMIZE=1/PYTHONOPTIMIZE=0/" "$FINALDIR/opt/bootlocal.sh" +fi # Delete unnecessary Babel .dat files find $FINALDIR -path "*babel/locale-data/*.dat" -not -path "*en_US*" | sudo xargs rm