diff --git a/Dockerfile_inference b/Dockerfile similarity index 100% rename from Dockerfile_inference rename to Dockerfile diff --git a/Dockerfile_worker b/Dockerfile_worker deleted file mode 100644 index 119a53d..0000000 --- a/Dockerfile_worker +++ /dev/null @@ -1,7 +0,0 @@ -FROM alloranetwork/allora-offchain-node:latest - -COPY ./config.json /app/config.json - -ENV ALLORA_OFFCHAIN_NODE_CONFIG_FILE_PATH=/app/config.json - -CMD ["./allora_offchain_node"] \ No newline at end of file diff --git a/docker-compose.yml b/docker-compose.yml index a8c959b..a206f6a 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -1,9 +1,7 @@ services: inference: container_name: inference-basic-eth-pred - build: - context: . - dockerfile: Dockerfile_inference + build: . command: python -u /app/app.py ports: - "8000:8000" @@ -17,9 +15,7 @@ services: updater: container_name: updater-basic-eth-pred - build: - context: . - dockerfile: Dockerfile_inference + build: . environment: - INFERENCE_API_ADDRESS=http://inference:8000 command: > @@ -36,15 +32,14 @@ services: worker: container_name: worker image: alloranetwork/allora-offchain-node:latest - build: - context: . - dockerfile: Dockerfile_worker volumes: - ./worker-data:/data depends_on: inference: condition: service_healthy + env_file: + - ./worker-data/env_file volumes: inference-data: - worker-data: + worker-data: \ No newline at end of file diff --git a/init.config b/init.config new file mode 100755 index 0000000..658fbb5 --- /dev/null +++ b/init.config @@ -0,0 +1,43 @@ +#!/bin/bash + +set -e + +if [ ! -f config.json ]; then + echo "Error: config.json file not found, please provide one" + exit 1 +fi + +nodeName=$(jq -r '.wallet.addressKeyName' config.json) +if [ -z "$nodeName" ]; then + echo "No wallet name provided for the node, please provide your preferred wallet name. config.json >> wallet.addressKeyName" + exit 1 +fi + +json_content=$(cat ./config.json) +stringified_json=$(echo "$json_content" | jq -c .) + +mnemonic=$(jq -r '.wallet.addressRestoreMnemonic' config.json) +if [ -n "$mnemonic" ]; then + echo "ALLORA_OFFCHAIN_NODE_CONFIG_JSON='$stringified_json'" > ./worker-data/env_file + echo "NAME=$nodeName" >> ./worker-data/env_file + echo "ENV_LOADED=true" >> ./worker-data/env_file + + echo "wallet mnemonic already provided by you, loading config.json . Please proceed to run docker compose" + exit 1 +fi + +if [ ! -f ./worker-data/env_file ]; then + echo "ENV_LOADED=false" > ./worker-data/env_file +fi + +ENV_LOADED=$(grep '^ENV_LOADED=' ./worker-data/env_file | cut -d '=' -f 2) +if [ "$ENV_LOADED" = "false" ]; then + json_content=$(cat ./config.json) + stringified_json=$(echo "$json_content" | jq -c .) + + docker run -it --entrypoint=bash -v $(pwd)/worker-data:/data -v $(pwd)/scripts:/scripts -e NAME="${nodeName}" -e ALLORA_OFFCHAIN_NODE_CONFIG_JSON="${stringified_json}" alloranetwork/allora-chain:latest -c "bash /scripts/init.sh" + echo "config.json saved to ./worker-data/env_file" +else + echo "config.json is already loaded, skipping the operation. You can set ENV_LOADED variable to false in ./worker-data/env_file to reload the config.json" +fi + \ No newline at end of file diff --git a/scripts/init.sh b/scripts/init.sh new file mode 100644 index 0000000..0e6af84 --- /dev/null +++ b/scripts/init.sh @@ -0,0 +1,33 @@ +#!/bin/bash + +set -e + +if allorad keys --home=/data/.allorad --keyring-backend test show $NAME > /dev/null 2>&1 ; then + echo "allora account: $NAME already imported" +else + echo "creating allora account: $NAME" + output=$(allorad keys add $NAME --home=/data/.allorad --keyring-backend test 2>&1) + address=$(echo "$output" | grep 'address:' | sed 's/.*address: //') + mnemonic=$(echo "$output" | tail -n 1) + + # Parse and update the JSON string + updated_json=$(echo "$ALLORA_OFFCHAIN_NODE_CONFIG_JSON" | jq --arg name "$NAME" --arg mnemonic "$mnemonic" ' + .wallet.addressKeyName = $name | + .wallet.addressRestoreMnemonic = $mnemonic + ') + + stringified_json=$(echo "$updated_json" | jq -c .) + + echo "ALLORA_OFFCHAIN_NODE_CONFIG_JSON='$stringified_json'" > /data/env_file + echo ALLORA_OFFCHAIN_ACCOUNT_ADDRESS=$address >> /data/env_file + echo "NAME=$NAME" >> /data/env_file + + echo "Updated ALLORA_OFFCHAIN_NODE_CONFIG_JSON saved to /data/env_file" +fi + + +if grep -q "ENV_LOADED=false" /data/env_file; then + sed -i 's/ENV_LOADED=false/ENV_LOADED=true/' /data/env_file +else + echo "ENV_LOADED=true" >> /data/env_file +fi