Update bash demo with bom tool and add musl version
Signed-off-by: Zheng, Qi <huaiqing.zq@antgroup.com>
This commit is contained in:
		
							parent
							
								
									e1cebcd488
								
							
						
					
					
						commit
						597f8c9080
					
				| @ -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" | ||||
|         } | ||||
|     ] | ||||
| } | ||||
| @ -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 | ||||
| ``` | ||||
|  | ||||
							
								
								
									
										11
									
								
								demos/bash/bash-musl.yaml
									
									
									
									
									
										Normal file
									
								
							
							
								
								
								
								
								
									
									
								
							
						
						
									
										11
									
								
								demos/bash/bash-musl.yaml
									
									
									
									
									
										Normal file
									
								
							| @ -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 | ||||
							
								
								
									
										11
									
								
								demos/bash/bash.yaml
									
									
									
									
									
										Normal file
									
								
							
							
								
								
								
								
								
									
									
								
							
						
						
									
										11
									
								
								demos/bash/bash.yaml
									
									
									
									
									
										Normal file
									
								
							| @ -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 | ||||
| @ -58,7 +58,7 @@ fi | ||||
| fake_inst || true | ||||
| 
 | ||||
| # Test builtin command | ||||
| cd /opt/occlum/glibc/lib | ||||
| cd /host | ||||
| pwd | ||||
| cd - | ||||
| 
 | ||||
|  | ||||
| @ -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 | ||||
							
								
								
									
										24
									
								
								demos/bash/prepare_busybox.sh
									
									
									
									
									
										Executable file
									
								
							
							
								
								
								
								
								
									
									
								
							
						
						
									
										24
									
								
								demos/bash/prepare_busybox.sh
									
									
									
									
									
										Executable file
									
								
							| @ -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 | ||||
| @ -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 | ||||
|  | ||||
		Loading…
	
		Reference in New Issue
	
	Block a user