From d3b4b10d4ab16aa12b3b809d464266ff89e72ab7 Mon Sep 17 00:00:00 2001 From: jiangjianfeng Date: Fri, 17 Sep 2021 14:53:55 +0800 Subject: [PATCH] Modify python-glibc demo with copy_bom --- .../python_glibc/install_python_with_conda.sh | 2 +- demos/python/python_glibc/python-glibc.yaml | 25 +++++++++++++++++++ .../python_glibc/run_python_on_occlum.sh | 25 +++++++------------ 3 files changed, 35 insertions(+), 17 deletions(-) create mode 100644 demos/python/python_glibc/python-glibc.yaml diff --git a/demos/python/python_glibc/install_python_with_conda.sh b/demos/python/python_glibc/install_python_with_conda.sh index fb19e1a0..9a5e8c75 100755 --- a/demos/python/python_glibc/install_python_with_conda.sh +++ b/demos/python/python_glibc/install_python_with_conda.sh @@ -8,5 +8,5 @@ script_dir="$( cd "$( dirname "${BASH_SOURCE[0]}" )" >/dev/null 2>&1 && pwd )" # 2. Install python and dependencies to specified position [ -d Miniconda3-latest-Linux-x86_64.sh ] || wget https://repo.anaconda.com/miniconda/Miniconda3-latest-Linux-x86_64.sh [ -d miniconda ] || bash ./Miniconda3-latest-Linux-x86_64.sh -b -p $script_dir/miniconda -$script_dir/miniconda/bin/conda create --prefix $script_dir/occlum_instance/image/opt/python-occlum -y python=3.7 numpy=1.18.1 pandas=0.24.2 scipy=1.3.1 Cython scikit-learn=0.21.1 +$script_dir/miniconda/bin/conda create --prefix $script_dir/python-occlum -y python=3.7 numpy=1.18.1 pandas=0.24.2 scipy=1.3.1 Cython scikit-learn=0.21.1 diff --git a/demos/python/python_glibc/python-glibc.yaml b/demos/python/python_glibc/python-glibc.yaml new file mode 100644 index 00000000..c88461b1 --- /dev/null +++ b/demos/python/python_glibc/python-glibc.yaml @@ -0,0 +1,25 @@ +includes: + - base.yaml +targets: + - target: /bin + createlinks: + - src: /opt/python-occlum/bin/python3 + linkname: python3 + # python packages + - target: /opt + copy: + - dirs: + - ../python-occlum + # explicit copy python3 to enable autodep for python3 + - target: /opt/python-occlum/bin + copy: + - files: + - ../python-occlum/bin/python3 + # below are python code and data + - target: / + copy: + - from: .. + dirs: + - dataset + files: + - demo.py diff --git a/demos/python/python_glibc/run_python_on_occlum.sh b/demos/python/python_glibc/run_python_on_occlum.sh index d523235c..a59b02e6 100755 --- a/demos/python/python_glibc/run_python_on_occlum.sh +++ b/demos/python/python_glibc/run_python_on_occlum.sh @@ -7,27 +7,20 @@ NC='\033[0m' script_dir="$( cd "$( dirname "${BASH_SOURCE[0]}" )" >/dev/null 2>&1 && pwd )" python_dir="$script_dir/occlum_instance/image/opt/python-occlum" +cd occlum_instance && rm -rf image +copy_bom -f ../python-glibc.yaml --root image --include-dir /opt/occlum/etc/template + if [ ! -d $python_dir ];then echo "Error: cannot stat '$python_dir' directory" exit 1 fi -cd occlum_instance -# Copy files into Occlum Workspace and build -if [ ! -L "image/bin/python3" ];then - ln -s /opt/python-occlum/bin/python3 image/bin/python3 - cp -f /opt/occlum/glibc/lib/libdl.so.2 image/opt/occlum/glibc/lib/ - cp -f /opt/occlum/glibc/lib/libutil.so.1 image/opt/occlum/glibc/lib/ - cp -f /opt/occlum/glibc/lib/librt.so.1 image/opt/occlum/glibc/lib/ - cp -rf ../dataset image - cp -f ../demo.py image - new_json="$(jq '.resource_limits.user_space_size = "640MB" | - .resource_limits.kernel_space_heap_size = "256MB" | - .process.default_mmap_size = "512MB" | - .env.default += ["PYTHONHOME=/opt/python-occlum"]' Occlum.json)" && \ - echo "${new_json}" > Occlum.json - occlum build -fi +new_json="$(jq '.resource_limits.user_space_size = "640MB" | + .resource_limits.kernel_space_heap_size = "256MB" | + .process.default_mmap_size = "512MB" | + .env.default += ["PYTHONHOME=/opt/python-occlum"]' Occlum.json)" && \ +echo "${new_json}" > Occlum.json +occlum build # Run the python demo echo -e "${BLUE}occlum run /bin/python3 demo.py${NC}"