From cbb326e3fdbe8bdc3e93903f8d59f9ced4589b8b Mon Sep 17 00:00:00 2001 From: "Zheng, Qi" Date: Sun, 26 Sep 2021 13:51:17 +0800 Subject: [PATCH] Update fish demo with copy_bom tool Signed-off-by: Zheng, Qi --- demos/fish/Occlum.json | 65 ----------------------- demos/fish/fish.yaml | 24 +++++++++ demos/fish/run_fish_test.sh | 25 ++++----- demos/fish/run_per_process_config_test.sh | 25 ++++----- 4 files changed, 48 insertions(+), 91 deletions(-) delete mode 100644 demos/fish/Occlum.json create mode 100644 demos/fish/fish.yaml diff --git a/demos/fish/Occlum.json b/demos/fish/Occlum.json deleted file mode 100644 index 4367e367..00000000 --- a/demos/fish/Occlum.json +++ /dev/null @@ -1,65 +0,0 @@ -{ - "resource_limits": { - "user_space_size": "512MB", - "kernel_space_heap_size": "64MB", - "kernel_space_stack_size": "1MB", - "max_num_of_threads": 32 - }, - "process": { - "default_stack_size": "4MB", - "default_heap_size": "32MB", - "default_mmap_size": "80MB" - }, - "entry_points": [ - "/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/fish/fish.yaml b/demos/fish/fish.yaml new file mode 100644 index 00000000..07af5122 --- /dev/null +++ b/demos/fish/fish.yaml @@ -0,0 +1,24 @@ +includes: + - base.yaml +# fish +targets: + - target: /usr/bin + # copy bins + copy: + - files: + - ../fish-shell/build/fish + - ../busybox/busybox + - target: /bin + # copy script + copy: + - files: + - ../fish_script.sh + - ../test_per_process_config.sh + # busybox links + createlinks: + - src: /usr/bin/busybox + linkname: cat + - src: /usr/bin/busybox + linkname: echo + - src: /usr/bin/busybox + linkname: awk diff --git a/demos/fish/run_fish_test.sh b/demos/fish/run_fish_test.sh index e3c1e014..e17a1d93 100755 --- a/demos/fish/run_fish_test.sh +++ b/demos/fish/run_fish_test.sh @@ -1,19 +1,20 @@ #!/bin/bash set -e +SCRIPT_DIR=$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd ) +bomfile=${SCRIPT_DIR}/fish.yaml + rm -rf occlum-instance -mkdir occlum-instance && cd occlum-instance -occlum init -mkdir -p image/usr/bin -cp ../Occlum.json . -cp ../fish-shell/build/fish image/usr/bin -cp ../busybox/busybox image/usr/bin -cp ../fish_script.sh image/bin -pushd image/bin -ln -s /usr/bin/busybox cat -ln -s /usr/bin/busybox echo -ln -s /usr/bin/busybox awk -popd +occlum new occlum-instance +cd occlum-instance + +new_json="$(jq '.resource_limits.user_space_size = "512MB" | + .resource_limits.kernel_space_heap_size = "64MB" | + .env.default = [ "OCCLUM=yes", "HOME=/root" ]' Occlum.json)" && \ + echo "${new_json}" > Occlum.json + +rm -rf image +copy_bom -f $bomfile --root image --include-dir /opt/occlum/etc/template occlum build echo -e "\nBuild done. Running fish script ..." diff --git a/demos/fish/run_per_process_config_test.sh b/demos/fish/run_per_process_config_test.sh index 7d6f0885..57ef1d1f 100755 --- a/demos/fish/run_per_process_config_test.sh +++ b/demos/fish/run_per_process_config_test.sh @@ -1,28 +1,25 @@ #!/bin/bash set -e +SCRIPT_DIR=$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd ) +bomfile=${SCRIPT_DIR}/fish.yaml + option=$1 rm -rf occlum-test -mkdir occlum-test && cd occlum-test -occlum init -mkdir -p image/usr/bin -cp ../Occlum.json . -cp ../fish-shell/build/fish image/usr/bin -cp ../busybox/busybox image/usr/bin -cp ../test_per_process_config.sh image/bin +occlum new occlum-test && cd occlum-test # Set process memory space size to very small values and will fail when running target script using default configuration -new_json="$(jq '.process.default_stack_size = "1MB" | +new_json="$(jq '.resource_limits.user_space_size = "512MB" | + .resource_limits.kernel_space_heap_size= "64MB" | + .process.default_stack_size = "1MB" | .process.default_heap_size = "1MB" | - .process.default_mmap_size = "10MB"' Occlum.json)" && \ + .process.default_mmap_size = "10MB" | + .env.default = [ "OCCLUM=yes", "HOME=/root" ]' Occlum.json)" && \ echo "${new_json}" > Occlum.json -pushd image/bin -ln -s /usr/bin/busybox cat -ln -s /usr/bin/busybox echo -ln -s /usr/bin/busybox awk -popd +rm -rf image +copy_bom -f $bomfile --root image --include-dir /opt/occlum/etc/template # If `--without-ulimit` is specified, run without ulimit command and thus will fail if [[ $1 == "--without-ulimit" ]]; then