Skip to content

Commit

Permalink
chore(raiko): update entrypoint.sh (#228)
Browse files Browse the repository at this point in the history
* update entrypoint.sh

* add k8s conf

Signed-off-by: smtmfft <[email protected]>

---------

Signed-off-by: smtmfft <[email protected]>
  • Loading branch information
smtmfft authored May 22, 2024
1 parent e130557 commit aaf05a7
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 8 deletions.
12 changes: 10 additions & 2 deletions docker/docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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}
Expand All @@ -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"
Expand Down
36 changes: 30 additions & 6 deletions docker/entrypoint.sh
Original file line number Diff line number Diff line change
Expand Up @@ -38,26 +38,45 @@ 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
echo "chain_spec_list.docker.json file not found."
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
}

Expand All @@ -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

Expand Down

0 comments on commit aaf05a7

Please sign in to comment.