From 597f8c908066a17b62af7090a2676689bc5d15ff Mon Sep 17 00:00:00 2001 From: "Zheng, Qi" Date: Fri, 24 Sep 2021 15:45:58 +0800 Subject: [PATCH] Update bash demo with bom tool and add musl version Signed-off-by: Zheng, Qi --- demos/bash/Occlum.json | 65 --------------------------------- demos/bash/README.md | 8 ++-- demos/bash/bash-musl.yaml | 11 ++++++ demos/bash/bash.yaml | 11 ++++++ demos/bash/occlum_bash_test.sh | 2 +- demos/bash/prepare_bash_demo.sh | 35 ------------------ demos/bash/prepare_busybox.sh | 24 ++++++++++++ demos/bash/run_bash_demo.sh | 36 +++++++++--------- 8 files changed, 68 insertions(+), 124 deletions(-) delete mode 100644 demos/bash/Occlum.json create mode 100644 demos/bash/bash-musl.yaml create mode 100644 demos/bash/bash.yaml delete mode 100755 demos/bash/prepare_bash_demo.sh create mode 100755 demos/bash/prepare_busybox.sh diff --git a/demos/bash/Occlum.json b/demos/bash/Occlum.json deleted file mode 100644 index 10430810..00000000 --- a/demos/bash/Occlum.json +++ /dev/null @@ -1,65 +0,0 @@ -{ - "resource_limits": { - "user_space_size": "600MB", - "kernel_space_heap_size": "32MB", - "kernel_space_stack_size": "1MB", - "max_num_of_threads": 16 - }, - "process": { - "default_stack_size": "2MB", - "default_heap_size": "16MB", - "default_mmap_size": "80MB" - }, - "entry_points": [ - "/root/bin" - ], - "env": { - "default": [ - "OCCLUM=yes", - "HOME=/root" - ], - "untrusted": [ - ] - }, - "metadata": { - "product_id": 0, - "version_number": 0, - "debuggable": true - }, - "mount": [ - { - "target": "/", - "type": "unionfs", - "options": { - "layers": [ - { - "target": "/", - "type": "sefs", - "source": "./build/mount/__ROOT", - "options": { - "MAC": "" - } - }, - { - "target": "/", - "type": "sefs", - "source": "./run/mount/__ROOT" - } - ] - } - }, - { - "target": "/host", - "type": "hostfs", - "source": "." - }, - { - "target": "/proc", - "type": "procfs" - }, - { - "target": "/dev", - "type": "devfs" - } - ] -} diff --git a/demos/bash/README.md b/demos/bash/README.md index d586185c..57e17ed7 100644 --- a/demos/bash/README.md +++ b/demos/bash/README.md @@ -6,14 +6,14 @@ Bash is the most widely used shell implementation around the world. Previously, Now, Bash is finally supported with modification to the source code of Bash. We have evaluated and all commands defined in `occlum_bash_test.sh` are all supported. -Please follow below steps to run this demo: +Two versions [`musl-libc` and `glibc`] of bash demo is provided: -1. Download and build Busybox and Occlum-version Bash +* musl-libc bash demo ``` -./prepare_bash_demo.sh +./run_bash_demo.sh musl ``` -2. Run Bash script in Occlum +* glibc bash demo ``` ./run_bash_demo.sh ``` diff --git a/demos/bash/bash-musl.yaml b/demos/bash/bash-musl.yaml new file mode 100644 index 00000000..d1f97618 --- /dev/null +++ b/demos/bash/bash-musl.yaml @@ -0,0 +1,11 @@ +includes: + - base.yaml +# musl bash +targets: + # copy bash and busybox + - target: /bin + copy: + - files: + - /opt/occlum/toolchains/bash/musl/bash + - ../busybox/busybox + - ../occlum_bash_test.sh diff --git a/demos/bash/bash.yaml b/demos/bash/bash.yaml new file mode 100644 index 00000000..30633539 --- /dev/null +++ b/demos/bash/bash.yaml @@ -0,0 +1,11 @@ +includes: + - base.yaml +# bash +targets: + # copy bash and busybox + - target: /bin + copy: + - files: + - /opt/occlum/toolchains/bash/glibc/bash + - ../busybox/busybox + - ../occlum_bash_test.sh diff --git a/demos/bash/occlum_bash_test.sh b/demos/bash/occlum_bash_test.sh index 21bd906a..a35a3188 100755 --- a/demos/bash/occlum_bash_test.sh +++ b/demos/bash/occlum_bash_test.sh @@ -58,7 +58,7 @@ fi fake_inst || true # Test builtin command -cd /opt/occlum/glibc/lib +cd /host pwd cd - diff --git a/demos/bash/prepare_bash_demo.sh b/demos/bash/prepare_bash_demo.sh deleted file mode 100755 index 647ceeb7..00000000 --- a/demos/bash/prepare_bash_demo.sh +++ /dev/null @@ -1,35 +0,0 @@ -#! /bin/bash -set -e - -current=$(pwd) -bash_src="$current/bash_for_occlum" -bash_git="https://github.com/occlum/bash.git" -bash_branch="bash_5.1_for_occlum" -busybox_src="$current/busybox" - -if [ ! -d "$bash_src" ]; then - # Download and configure Bash - cd $current - git clone -b $bash_branch $bash_git bash_for_occlum - cd bash_for_occlum && git checkout $bash_branch - if [ "$DEBUG" == "1" ]; then - CFLAGS="-D DEBUG=1 -g -O0" ./configure --enable-debugger - else - ./configure - fi - - # Build - make -j$(nproc) - echo "Bash is ready." -fi - -if [ ! -d "$busybox_src" ]; then - cd $current - busybox_config="$current/../fish/.config" - git clone -b 1_31_1 --depth 1 https://github.com/mirror/busybox.git - cd busybox - # CROSS_COMPILE=/opt/occlum/toolchains/gcc/bin/occlum- - make defconfig - cp $busybox_config . - make -j$(nproc) -fi diff --git a/demos/bash/prepare_busybox.sh b/demos/bash/prepare_busybox.sh new file mode 100755 index 00000000..e970528e --- /dev/null +++ b/demos/bash/prepare_busybox.sh @@ -0,0 +1,24 @@ +#! /bin/bash +set -e + +current=$(pwd) +busybox_src="$current/busybox" +busybox_config="$current/../fish/.config" + +rm -rf $busybox_src +git clone -b 1_31_1 --depth 1 https://github.com/mirror/busybox.git + +pushd $busybox_src +make clean +make defconfig +cp $busybox_config . + +if [[ $1 == "musl" ]]; then + echo "Building musl-libc version of busybox" + sed -e 's/.*CONFIG_CROSS_COMPILER_PREFIX.*/CONFIG_CROSS_COMPILER_PREFIX="occlum-"/' -i .config +else + echo "Building glibc version of busybox" +fi + +make -j +popd diff --git a/demos/bash/run_bash_demo.sh b/demos/bash/run_bash_demo.sh index 4d08d22a..73d69424 100755 --- a/demos/bash/run_bash_demo.sh +++ b/demos/bash/run_bash_demo.sh @@ -1,29 +1,27 @@ #! /bin/bash set -e -current=$(pwd) -bash_src="$current/bash_for_occlum" -busybox_src="$current/busybox" -occlum_instance="$current/occlum_instance" -occlum_glibc_path=$occlum_instance/image/opt/occlum/glibc/lib -# Executable path in Occlum -exec_path=/root/bin +if [[ $1 == "musl" ]]; then + echo "*** Run musl-libc bash demo ***" + ./prepare_busybox.sh musl + bomfile="../bash-musl.yaml" +else + echo "*** Run glibc bash demo ***" + ./prepare_busybox.sh + bomfile="../bash.yaml" +fi rm -rf occlum_instance occlum new occlum_instance -cd occlum_instance +pushd occlum_instance +rm -rf image +copy_bom -f $bomfile --root image --include-dir /opt/occlum/etc/template -cp $bash_src/bash ./image/bin/ -cp /lib/x86_64-linux-gnu/libtinfo.so.5 $occlum_glibc_path -cp /lib/x86_64-linux-gnu/libdl.so.2 $occlum_glibc_path -cp $busybox_src/busybox image/bin -cp /lib/x86_64-linux-gnu/libm.so.6 $occlum_glibc_path -cp /lib/x86_64-linux-gnu/libresolv.so.2 $occlum_glibc_path - -mkdir -p "$occlum_instance/image/$exec_path" -cp "$current/occlum_bash_test.sh" "$occlum_instance/image/$exec_path" -cp "$current/Occlum.json" "$occlum_instance" +new_json="$(jq '.resource_limits.user_space_size = "600MB" ' Occlum.json)" && \ + echo "${new_json}" > Occlum.json occlum build -occlum run /root/bin/occlum_bash_test.sh +occlum run /bin/occlum_bash_test.sh + +popd