From aaf05a7464c6c4b6f61718152a6400533694986a Mon Sep 17 00:00:00 2001 From: smtmfft <99081233+smtmfft@users.noreply.github.com> Date: Wed, 22 May 2024 09:34:59 +0800 Subject: [PATCH] chore(raiko): update entrypoint.sh (#228) * update entrypoint.sh * add k8s conf Signed-off-by: smtmfft --------- Signed-off-by: smtmfft --- docker/docker-compose.yml | 12 ++++++++++-- docker/entrypoint.sh | 36 ++++++++++++++++++++++++++++++------ 2 files changed, 40 insertions(+), 8 deletions(-) diff --git a/docker/docker-compose.yml b/docker/docker-compose.yml index 4748a1ead..f8d6e5485 100644 --- a/docker/docker-compose.yml +++ b/docker/docker-compose.yml @@ -66,6 +66,8 @@ services: # Set to 0 (which is the default) to run on real hardware; use 1 for testing - SGX_DIRECT=${SGX_DIRECT} - SGX_INSTANCE_ID=${SGX_INSTANCE_ID} + - ETHEREUM_RPC=${ETHEREUM_RPC} + - ETHEREUM_CHAIN_ID=${ETHEREUM_CHAIN_ID} - HOLESKY_RPC=${HOLESKY_RPC} - HOLESKY_BEACON_RPC=${HOLESKY_BEACON_RPC} - TAIKO_A7_RPC=${TAIKO_A7_RPC} @@ -91,11 +93,17 @@ services: - ${HOME}/.config/gramine:/root/.config/gramine - ${HOME}/.config/raiko:/root/.config/raiko - ${HOME}/.config/raiko/config/config.sgx.json:/etc/raiko/config.sgx.json + - ${HOME}/.config/raiko/config/chain_spec_list.docker.json:/etc/raiko/chain_spec_list.docker.json ports: - "8080:8080" - # environment: + environment: # you can use your own PCCS host - #- PCCS_HOST=host.docker.internal:8081 + # - PCCS_HOST=host.docker.internal:8081 + - ETHEREUM_RPC=${ETHEREUM_RPC} + - ETHEREUM_CHAIN_ID=${ETHEREUM_CHAIN_ID} + - HOLESKY_RPC=${HOLESKY_RPC} + - HOLESKY_BEACON_RPC=${HOLESKY_BEACON_RPC} + - TAIKO_A7_RPC=${TAIKO_A7_RPC} # use the host's network to connect to the PCCS #extra_hosts: # - "host.docker.internal:host-gateway" diff --git a/docker/entrypoint.sh b/docker/entrypoint.sh index d97746429..938acb5a4 100755 --- a/docker/entrypoint.sh +++ b/docker/entrypoint.sh @@ -38,6 +38,20 @@ function bootstrap_with_self_register() { cd - } +function update_chain_spec_json() { + CONFIG_FILE=$1 + CHAIN_NAME=$2 + KEY_NAME=$3 + UPDATE_VALUE=$4 + jq \ + --arg update_value "$UPDATE_VALUE" \ + --arg chain_name "$CHAIN_NAME" \ + --arg key_name "$KEY_NAME" \ + 'map(if .name == $chain_name then .[$key_name] = $update_value else . end)' $CONFIG_FILE \ + > /tmp/config_tmp.json && mv /tmp/config_tmp.json $CONFIG_FILE; + echo "Updated $CONFIG_FILE $CHAIN_NAME.$KEY_NAME=$UPDATE_VALUE" +} + function update_docker_chain_specs() { CONFIG_FILE="$RAIKO_CONF_DIR/chain_spec_list.docker.json" if [ ! -f $CONFIG_FILE ]; then @@ -45,19 +59,24 @@ function update_docker_chain_specs() { return 1 fi + if [ -n "${ETHEREUM_RPC}" ]; then + update_chain_spec_json $CONFIG_FILE "ethereum" "rpc" $ETHEREUM_RPC + fi + + if [ -n "${ETHEREUM_BEACON_RPC}" ]; then + update_chain_spec_json $CONFIG_FILE "ethereum" "beacon_rpc" $ETHEREUM_BEACON_RPC + fi + if [ -n "${HOLESKY_RPC}" ]; then - jq --arg rpc "$HOLESKY_RPC" 'map(if .name == "holesky" then .rpc = $rpc else . end)' $CONFIG_FILE > /tmp/config_tmp.json && mv /tmp/config_tmp.json $CONFIG_FILE; - echo "Updated config.json with .rpc=$HOLESKY_RPC" + update_chain_spec_json $CONFIG_FILE "holesky" "rpc" $HOLESKY_RPC fi if [ -n "${HOLESKY_BEACON_RPC}" ]; then - jq --arg beacon_rpc "$HOLESKY_BEACON_RPC" 'map(if .name == "holesky" then .beacon_rpc = $beacon_rpc else . end)' $CONFIG_FILE > /tmp/config_tmp.json && mv /tmp/config_tmp.json $CONFIG_FILE; - echo "Updated config.json with .beacon_rpc=$HOLESKY_BEACON_RPC" + update_chain_spec_json $CONFIG_FILE "holesky" "beacon_rpc" $HOLESKY_BEACON_RPC fi if [ -n "${TAIKO_A7_RPC}" ]; then - jq --arg taiko_a7_rpc "$TAIKO_A7_RPC" 'map(if .name == "taiko_a7" then .rpc = $taiko_a7_rpc else . end)' $CONFIG_FILE > /tmp/config_tmp.json && mv /tmp/config_tmp.json $CONFIG_FILE; - echo "Updated config.json with .taiko_a7_rpc=$TAIKO_A7_RPC" + update_chain_spec_json $CONFIG_FILE "taiko_a7" "rpc" $TAIKO_A7_RPC fi } @@ -67,6 +86,11 @@ else MY_PCCS_HOST=${PCCS_HOST} fi +if [[ -n $TEST ]]; then + echo "TEST mode, to test bash functions." + return 0 +fi + sed -i "s/https:\/\/localhost:8081/https:\/\/${MY_PCCS_HOST}/g" /etc/sgx_default_qcnl.conf /restart_aesm.sh