diff --git a/.github/workflows/demo_test.yml b/.github/workflows/demo_test.yml index 03523993..dff10c6c 100644 --- a/.github/workflows/demo_test.yml +++ b/.github/workflows/demo_test.yml @@ -509,3 +509,36 @@ jobs: run: | sleep ${{ env.nap_time }}; docker exec vault_test bash -c "cd /root/occlum/demos/golang/vault && ./run_occlum_vault_test.sh" + + sofaboot_test: + runs-on: ubuntu-18.04 + steps: + - uses: actions/checkout@v1 + with: + submodules: true + + - name: Get occlum version + run: echo "OCCLUM_VERSION=$(grep "Version =" src/pal/include/occlum_version.h | awk '{print $4}')" >> $GITHUB_ENV + + - name: Create container + run: docker run -itd --name=sofaboot_test -v $GITHUB_WORKSPACE:/root/occlum occlum/occlum:${{ env.OCCLUM_VERSION }}-ubuntu18.04 + + - name: Install Maven + run: docker exec sofaboot_test bash -c "apt update && apt install -y maven" + + - name: Build dependencies + run: docker exec sofaboot_test bash -c "cd /root/occlum; make submodule" + + - name: Make install + run: docker exec sofaboot_test bash -c "cd /root/occlum; OCCLUM_RELEASE_BUILD=y make install" + + - name: Download and compile sofaboot web demos + run: docker exec sofaboot_test bash -c "cd /root/occlum/demos/sofaboot && ./download_compile_sofaboot.sh" + + - name: Run SOFABoot web demo + run: docker exec sofaboot_test bash -c "cd /root/occlum/demos/sofaboot && SGX_MODE=SIM ./run_sofaboot_on_occlum.sh" + + - name: Check SOFABoot result + run: | + sleep ${{ env.nap_time }}; + docker exec sofaboot_test bash -c "curl http://localhost:8080/actuator/versions" diff --git a/demos/sofaboot/README.md b/demos/sofaboot/README.md new file mode 100644 index 00000000..4aa25e36 --- /dev/null +++ b/demos/sofaboot/README.md @@ -0,0 +1,18 @@ +# A Simple SOFABoot usage demo + +This project demonstrates how to execute an unmodified sofaboot projects with Occlum. + +1. Download and build sofaboot project +``` +./download_compile_sofaboot.sh +``` + +2. Run `sofaboot sample standard web` on Occlum +``` +./run_sofaboot_on_occlum.sh +``` + +3. Test the web services +``` +curl http://localhost:8080/actuator/versions +``` diff --git a/demos/sofaboot/download_compile_sofaboot.sh b/demos/sofaboot/download_compile_sofaboot.sh new file mode 100755 index 00000000..1a59ad1f --- /dev/null +++ b/demos/sofaboot/download_compile_sofaboot.sh @@ -0,0 +1,7 @@ +#!/bin/bash +if [ ! -d "sofa-boot-guides" ]; then + git clone https://github.com/sofastack-guides/sofa-boot-guides.git +fi +cd sofa-boot-guides/sofaboot-sample-standard/ +mvn compile +mvn package diff --git a/demos/sofaboot/run_sofaboot_on_occlum.sh b/demos/sofaboot/run_sofaboot_on_occlum.sh new file mode 100755 index 00000000..992e708e --- /dev/null +++ b/demos/sofaboot/run_sofaboot_on_occlum.sh @@ -0,0 +1,50 @@ +#!/bin/bash +set -e + +BLUE='\033[1;34m' +NC='\033[0m' + +check_file_exist() { + file=$1 + if [ ! -f ${file} ];then + echo "Error: cannot stat file '${file}'" + echo "Please see README and build it" + exit 1 + fi +} + +init_instance() { + # Init Occlum instance + rm -rf occlum_instance && occlum new occlum_instance + cd occlum_instance + new_json="$(jq '.resource_limits.user_space_size = "1680MB" | + .resource_limits.kernel_space_heap_size="64MB" | + .resource_limits.max_num_of_threads = 64 | + .process.default_heap_size = "256MB" | + .process.default_mmap_size = "1400MB" | + .entry_points = [ "/usr/lib/jvm/java-11-alibaba-dragonwell/jre/bin" ] | + .env.default = [ "LD_LIBRARY_PATH=/usr/lib/jvm/java-11-alibaba-dragonwell/jre/lib/server:/usr/lib/jvm/java-11-alibaba-dragonwell/jre/lib:/usr/lib/jvm/java-11-alibaba-dragonwell/jre/../lib" ]' Occlum.json)" && \ + echo "${new_json}" > Occlum.json +} + +build_sofa() { + # Copy JVM and JAR file into Occlum instance and build + mkdir -p image/usr/lib/jvm + cp -r /opt/occlum/toolchains/jvm/java-11-alibaba-dragonwell image/usr/lib/jvm + cp /usr/local/occlum/x86_64-linux-musl/lib/libz.so.1 image/lib + mkdir -p image/usr/lib/spring + cp ../${jar_path} image/usr/lib/spring/ + occlum build +} + +run_sofa() { + jar_path=./sofa-boot-guides/sofaboot-sample-standard/target/boot/sofaboot-sample-standard-web-0.0.1-SNAPSHOT-executable.jar + check_file_exist ${jar_path} + jar_file=`basename "${jar_path}"` + init_instance + build_sofa + echo -e "${BLUE}occlum run SOFABoot demo${NC}" + occlum run /usr/lib/jvm/java-11-alibaba-dragonwell/jre/bin/java -Xmx512m -XX:-UseCompressedOops -XX:MaxMetaspaceSize=64m -Dos.name=Linux -jar /usr/lib/spring/${jar_file} & +} + +run_sofa