refactoring
This commit is contained in:
		
							parent
							
								
									c74aa76612
								
							
						
					
					
						commit
						21ea84a747
					
				
							
								
								
									
										4
									
								
								rewrite/.gitignore
									
									
									
									
										vendored
									
									
										Normal file
									
								
							
							
								
								
								
								
								
									
									
								
							
						
						
									
										4
									
								
								rewrite/.gitignore
									
									
									
									
										vendored
									
									
										Normal file
									
								
							| @ -0,0 +1,4 @@ | ||||
| # Occlum building env | ||||
| challenge_instance | ||||
| # The challenge bundle | ||||
| docker/challenge.tar.gz | ||||
| @ -1,9 +1,36 @@ | ||||
| #!/bin/bash | ||||
| 
 | ||||
| set -e | ||||
| 
 | ||||
| script_dir=$(dirname "$0") | ||||
| cd "${script_dir}/.." | ||||
| cd "$script_dir/.." | ||||
| prerequisites=$1 | ||||
| 
 | ||||
| if [ "$prerequisites" == "--prep" ]; then | ||||
|     echo "Preparing the packager environment" | ||||
|     apt update && apt install openssh-client | ||||
|     rustup install stable-x86_64-unknown-linux-gnu | ||||
|     rustup default stable | ||||
|     rustup target add x86_64-unknown-linux-musl | ||||
|     mkdir -p /root/.ssh | ||||
| 
 | ||||
|     echo "docker cp ~/.ssh/config packager:/root/.ssh/config" | ||||
|     echo "docker cp ~/.ssh/gitea_ed25519 packager:/root/.ssh/gitea_ed25519" | ||||
|     echo "Run above commands in another terminal" | ||||
|     while true; do | ||||
|         echo -n "." && sleep 1 | ||||
|         if [ -e ~/.ssh/config ] && [ -e ~/.ssh/gitea_ed25519 ]; then | ||||
|           echo -n "done" | ||||
|           break | ||||
|         fi | ||||
|     done | ||||
| 
 | ||||
|     chown -R root:root /root/.ssh | ||||
|     chmod 600 /root/.ssh/gitea_ed25519 | ||||
|     ssh-keyscan -H gitea.detee.cloud > ~/.ssh/known_hosts | ||||
| fi | ||||
| 
 | ||||
| echo "Building the hacker-challenge signed bundle" | ||||
| occlum-cargo build --release | ||||
| strip target/x86_64-unknown-linux-musl/release/hacker-challenge | ||||
| 
 | ||||
| @ -29,4 +56,3 @@ copy_bom -f ../challenge.yaml --root image --include-dir /opt/occlum/etc/templat | ||||
| # TODO: make sure the bundle needs SGX2 to run since SGX1 is vulnerable to https://x.com/PratyushRT/status/1828183761055330373 | ||||
| occlum build --sign-key ../scripts/signing_key.pem | ||||
| occlum package challenge.tar.gz | ||||
| mv challenge.tar.gz ../scripts/challenge.tar.gz | ||||
|  | ||||
| @ -1,51 +1,93 @@ | ||||
| #!/bin/bash | ||||
| set -e | ||||
| 
 | ||||
| # WARNING: Build and package the hacker-challenge first, see README.md | ||||
| # TODO: check if scripts/challenge.tar.gz exists, if not tell to build first | ||||
| 
 | ||||
| script_dir=$(dirname "$0") | ||||
| cd "${script_dir}/.." | ||||
| cd "${script_dir}/.." # Go to the root of the project | ||||
| 
 | ||||
| rm -rf build && mkdir build | ||||
| function build_mint_sol_tool() { | ||||
|     echo "Building the mint_sol tool for testing" | ||||
| 
 | ||||
| cp scripts/challenge.* build/ && cd build | ||||
| docker build -f challenge.Dockerfile -t hacker-challenge:latest . | ||||
|     if ! command -v cargo 2>&1 >/dev/null | ||||
|     then | ||||
|         echo "cargo not found, run 'curl https://sh.rustup.rs -sSf | sh'" | ||||
|         exit 1 | ||||
|     fi | ||||
| 
 | ||||
|     if ! command -v gcc 2>&1 >/dev/null | ||||
|     then | ||||
|         echo "cc not found, run 'apt update && apt install build-essential'" | ||||
|         exit 1 | ||||
|     fi | ||||
| 
 | ||||
|     if ! command -v protoc 2>&1 >/dev/null | ||||
|     then | ||||
|         echo "protoc not found, run 'apt update && apt install protobuf-compiler'" | ||||
|         exit 1 | ||||
|     fi | ||||
| 
 | ||||
|     cd mint_sol | ||||
|     cargo build --release | ||||
|     cp target/release/mint_sol "../${script_dir}/mint_sol" | ||||
|     cd .. | ||||
| } | ||||
| 
 | ||||
| function build_challenge_image() { | ||||
|     echo "Building the hacker-challenge docker image" | ||||
| 
 | ||||
|     if ! command -v docker 2>&1 >/dev/null | ||||
|     then | ||||
|         echo "docker not found, please install docker" | ||||
|         exit 1 | ||||
|     fi | ||||
| 
 | ||||
|     if [ ! -e challenge_instance/challenge.tar.gz ]; then | ||||
|       echo "Please build the challenge first, see README.md" | ||||
|       exit 1 | ||||
|     fi | ||||
| 
 | ||||
|     cd docker | ||||
|     cp ../challenge_instance/challenge.tar.gz challenge.tar.gz | ||||
|     docker build -f challenge.Dockerfile -t hacker-challenge:latest . | ||||
|     cd .. | ||||
| } | ||||
| 
 | ||||
| build_challenge_image | ||||
| build_mint_sol_tool | ||||
| 
 | ||||
| # Cleanup old containers and run the network root | ||||
| docker ps -a | grep 'hacker-challenge' | awk '{ print $NF }' | xargs docker rm -f || true | ||||
| 
 | ||||
| docker run --device /dev/sgx/enclave --device /dev/sgx/provision -d --name "hacker-challenge_0" \ | ||||
|   hacker-challenge:latest | ||||
| 
 | ||||
| cd "../${script_dir}/../../mint_sol" | ||||
| # TODO: build the mint_sol as part of the build process | ||||
| cargo build --release | ||||
| 
 | ||||
| sleep 3 | ||||
| 
 | ||||
| address=$(docker logs hacker-challenge_0 | grep 'SOL' | awk '{ print $NF }') | ||||
| 
 | ||||
| echo "sending SOL to wallet" | ||||
| 
 | ||||
| ./target/release/mint_sol $address | ||||
| 
 | ||||
| echo "Waiting for the network root to start" | ||||
| docker run --device /dev/sgx/enclave \ | ||||
|            --device /dev/sgx/provision \ | ||||
|            --name "hacker-challenge" \ | ||||
|            -d hacker-challenge:latest | ||||
| while true; do | ||||
|   echo "Waiting for mint to be created..." | ||||
|   sleep 5 | ||||
|   docker logs hacker-challenge_0 | grep "Mint created" && break | ||||
|     echo -n "." && sleep 1 | ||||
|     docker logs hacker-challenge | grep "SOL" && break | ||||
| done | ||||
| 
 | ||||
| # for i in {1..10} | ||||
| for i in {11..20} | ||||
| do | ||||
|   docker run --device /dev/sgx/enclave --device /dev/sgx/provision -d --name "hacker-challenge_$i" -p 313${i}:31372 \ | ||||
|     --env INIT_NODES="172.17.0.2 172.17.0.3 172.17.0.4" \ | ||||
|     hacker-challenge:latest | ||||
| echo "Sending SOL to the root and waiting for the mint" | ||||
| address=$(docker logs hacker-challenge | grep 'SOL' | awk '{ print $NF }') | ||||
| "${script_dir}"/mint_sol "${address}" | ||||
| while true; do | ||||
|     echo -n "." && sleep 1 | ||||
|     docker logs hacker-challenge | grep "Mint created" && break | ||||
| done | ||||
| 
 | ||||
| sleep 3 | ||||
| echo "Creating the cluster" | ||||
| for p in {31311..31320}; do | ||||
|     echo -n "." | ||||
|     docker run --device /dev/sgx/enclave \ | ||||
|                --device /dev/sgx/provision \ | ||||
|                --env INIT_NODES="172.17.0.2 172.17.0.3 172.17.0.4" \ | ||||
|                --name "hacker-challenge${p}" -p "${p}:31372" \ | ||||
|                -d hacker-challenge:latest | ||||
| done | ||||
| 
 | ||||
| for i in {11..20} | ||||
| do | ||||
| curl -X POST 127.0.0.1:313${i}/mint  --json '{"wallet": "EZT16iP1SQVUFf1AJN6oiE5BZPnyBUqaKDkZ4oZRsvhR"}' | ||||
| sleep 5 # Wait for the cluster to start | ||||
| 
 | ||||
| echo "Running the test mint" | ||||
| for p in {31311..31320}; do | ||||
|     curl -X POST "127.0.0.1:${p}/mint"  --json '{"wallet": "EZT16iP1SQVUFf1AJN6oiE5BZPnyBUqaKDkZ4oZRsvhR"}' | ||||
| done | ||||
		Loading…
	
		Reference in New Issue
	
	Block a user