From 8864b2659b7c64b89dc978c5992916decfc3fc76 Mon Sep 17 00:00:00 2001 From: conache Date: Fri, 9 Aug 2024 22:47:52 +0300 Subject: [PATCH 1/4] Remove utility scripts and add worker-data to .gitignore --- .gitignore | 1 + Dockerfile => Dockerfile_inference | 0 Dockerfile_worker | 7 +++++ docker-compose.yml | 13 ++++++--- init.config | 42 ------------------------------ worker-data/env_file | 3 --- worker-data/scripts/init.sh | 33 ----------------------- 7 files changed, 17 insertions(+), 82 deletions(-) rename Dockerfile => Dockerfile_inference (100%) create mode 100644 Dockerfile_worker delete mode 100755 init.config delete mode 100644 worker-data/env_file delete mode 100644 worker-data/scripts/init.sh diff --git a/.gitignore b/.gitignore index 97056b3..f8947f5 100644 --- a/.gitignore +++ b/.gitignore @@ -6,6 +6,7 @@ logs/* .allorad .cache inference-data +worker-data config.json env diff --git a/Dockerfile b/Dockerfile_inference similarity index 100% rename from Dockerfile rename to Dockerfile_inference diff --git a/Dockerfile_worker b/Dockerfile_worker new file mode 100644 index 0000000..119a53d --- /dev/null +++ b/Dockerfile_worker @@ -0,0 +1,7 @@ +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 5d856e3..a8c959b 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -1,7 +1,9 @@ services: inference: container_name: inference-basic-eth-pred - build: . + build: + context: . + dockerfile: Dockerfile_inference command: python -u /app/app.py ports: - "8000:8000" @@ -15,7 +17,9 @@ services: updater: container_name: updater-basic-eth-pred - build: . + build: + context: . + dockerfile: Dockerfile_inference environment: - INFERENCE_API_ADDRESS=http://inference:8000 command: > @@ -32,13 +36,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: diff --git a/init.config b/init.config deleted file mode 100755 index 2057f07..0000000 --- a/init.config +++ /dev/null @@ -1,42 +0,0 @@ -#!/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 -e NAME="${nodeName}" -e ALLORA_OFFCHAIN_NODE_CONFIG_JSON="${stringified_json}" alloranetwork/allora-chain:latest -c "bash /data/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/worker-data/env_file b/worker-data/env_file deleted file mode 100644 index c5ab53a..0000000 --- a/worker-data/env_file +++ /dev/null @@ -1,3 +0,0 @@ -ALLORA_OFFCHAIN_NODE_CONFIG_JSON='{"wallet":{"addressKeyName":"test-basic","addressRestoreMnemonic":"your mnemonic will go here","alloraHomeDir":"","gas":"1000000","gasAdjustment":1,"nodeRpc":"https://allora-rpc.devnet.behindthecurtain.xyz","maxRetries":1,"delay":1,"submitTx":false},"worker":[{"topicId":1,"inferenceEntrypointName":"api-worker-reputer","loopSeconds":5,"parameters":{"InferenceEndpoint":"http://inference:8000/inference/{Token}","Token":"ETH"}}]}' -NAME=test-basic -ENV_LOADED=true diff --git a/worker-data/scripts/init.sh b/worker-data/scripts/init.sh deleted file mode 100644 index 0e6af84..0000000 --- a/worker-data/scripts/init.sh +++ /dev/null @@ -1,33 +0,0 @@ -#!/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 From d703835d291ca8fa01fc7dfc87e50476f40903cd Mon Sep 17 00:00:00 2001 From: conache Date: Sat, 10 Aug 2024 01:04:19 +0300 Subject: [PATCH 2/4] Revert initial changes and use simpler approach --- Dockerfile_inference => Dockerfile | 0 Dockerfile_worker | 7 ----- docker-compose.yml | 15 ++++------- init.config | 43 ++++++++++++++++++++++++++++++ scripts/init.sh | 33 +++++++++++++++++++++++ 5 files changed, 81 insertions(+), 17 deletions(-) rename Dockerfile_inference => Dockerfile (100%) delete mode 100644 Dockerfile_worker create mode 100755 init.config create mode 100644 scripts/init.sh 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 From cddba4c19e82bdb641d435a43b5252cd030f62d9 Mon Sep 17 00:00:00 2001 From: conache Date: Sat, 10 Aug 2024 01:06:41 +0300 Subject: [PATCH 3/4] Revert formats --- init.config | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/init.config b/init.config index 658fbb5..038439c 100755 --- a/init.config +++ b/init.config @@ -21,7 +21,6 @@ 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 @@ -34,10 +33,8 @@ 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 +fi \ No newline at end of file From a4d66dd9e23c5a9f823acfed6ae1f622c2b15e5b Mon Sep 17 00:00:00 2001 From: conache Date: Sat, 10 Aug 2024 01:22:37 +0300 Subject: [PATCH 4/4] Create ./worker-data/env_file if it doesn't exist --- init.config | 3 +++ 1 file changed, 3 insertions(+) diff --git a/init.config b/init.config index 038439c..25833ae 100755 --- a/init.config +++ b/init.config @@ -25,6 +25,9 @@ if [ -n "$mnemonic" ]; then exit 1 fi +# Ensure the worker-data directory exists +mkdir -p ./worker-data + if [ ! -f ./worker-data/env_file ]; then echo "ENV_LOADED=false" > ./worker-data/env_file fi