Skip to content

Commit

Permalink
chore: Refactor local-docker-env scripts for key generation and confi…
Browse files Browse the repository at this point in the history
…guration
  • Loading branch information
paul-ahn-wm committed Jul 4, 2024
1 parent 26dae7d commit bf489bf
Show file tree
Hide file tree
Showing 5 changed files with 45 additions and 20 deletions.
4 changes: 4 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -170,6 +170,10 @@ After getting enodes of mining nodes, run gwemix as follows.

See documentation [here](docs/container.md)

### Starting Nodes For Local Test With Docker

See documentation [here](local-docker-env/README.md)

### The original go-ethereum README follows...

## Go Ethereum
Expand Down
8 changes: 4 additions & 4 deletions local-docker-env/config-gen.sh
Original file line number Diff line number Diff line change
Expand Up @@ -55,22 +55,22 @@ json_content=$(echo "$json_content" | jq --argjson env "$ENV_JSON" \

# JSON 구성 파일 생성
for ((i = 1; i <= ACCOUNT_NUM; i++)); do
ids=$(gwemix wemix nodeid local-docker-env/nodekey/nodekey$i)
ids=$(gwemix wemix nodeid local-docker-env/nodekey/nodekey$i) || { echo "Failed to get node ID"; exit 1; }
idv5=$(echo "$ids" | awk '/idv5:/ {print $2}')
idv5="0x$idv5"
ip="172.16.237.$((i+10))"

address=$(jq -r '.address' "local-docker-env/keystore/account$i")
address=$(jq -r '.address' "local-docker-env/keystore/account$i") || { echo "Failed to get address"; exit 1; }
address="0x$address"
name="localtest$i"

json_content=$(echo "$json_content" | jq --arg addr "$address" --arg name "$name" --arg id "$idv5" --arg ip "$ip" --argjson index $((i - 1)) \
'.members += [{"addr": $addr, "stake": 1500000000000000000000000, "name": $name, "id": $id, "ip": $ip, "port": 8589, "bootnode": false}]
| .accounts += [{"addr": $addr, "balance": 2000000000000000000000000}]')
| .accounts += [{"addr": $addr, "balance": 2000000000000000000000000}]') || { echo "Failed to update JSON content"; exit 1; }

if [ $i -eq 1 ]; then
json_content=$(echo "$json_content" | jq --arg addr "$address" \
'.staker = $addr | .ecosystem = $addr | .maintanence = $addr | .feecollector = $addr | .members[0].bootnode = true')
'.staker = $addr | .ecosystem = $addr | .maintanence = $addr | .feecollector = $addr | .members[0].bootnode = true') || { echo "Failed to update JSON content"; exit 1; }
fi
done

Expand Down
15 changes: 13 additions & 2 deletions local-docker-env/key-gen.sh
Original file line number Diff line number Diff line change
Expand Up @@ -32,10 +32,21 @@ for ((i = 1; i <= ACCOUNT_NUM; i++)); do
if [ -f "local-docker-env/keystore/account$i" ]; then
rm local-docker-env/keystore/account$i
fi
yes "test" | head -n 2 | gwemix wemix new-account --out local-docker-env/keystore/account$i

if yes "test" | head -n 2 | gwemix wemix new-account --out local-docker-env/keystore/account$i; then
echo "Account $i created successfully"
else
echo "Failed to create account $i"
exit 1
fi

if [ -f "local-docker-env/nodekey/nodekey$i" ]; then
rm local-docker-env/nodekey/nodekey$i
fi
gwemix wemix new-nodekey --out local-docker-env/nodekey/nodekey$i
if gwemix wemix new-nodekey --out local-docker-env/nodekey/nodekey$i; then
echo "Nodekey $i created successfully"
else
echo "Failed to create nodekey $i"
exit 1
fi
done
19 changes: 12 additions & 7 deletions local-docker-env/local-docker-git.sh
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
#!/bin/bash

# gwemix path를 환경변수에 추가
current_dir=$(pwd)
export PATH=$PATH:${current_dir}/go-wemix/build/bin

# 필수 인수 확인
if [ "$#" -ne 6 ]; then
echo "Usage: $0 -a <account_num> -b <branch> -r <repo>"
Expand Down Expand Up @@ -27,25 +31,26 @@ done

# 필수 인수 확인
if [ -z "$ACCOUNT_NUM" ] || [ -z "$BRANCH" ] || [ -z "$REPO" ]; then
echo "Missing required arguments."
exit 1
fi

# key-gen.sh 실행
chmod +x local-docker-env/key-gen.sh
./local-docker-env/key-gen.sh -a "$ACCOUNT_NUM"
./local-docker-env/key-gen.sh -a "$ACCOUNT_NUM" || { echo "Failed to execute key-gen.sh."; exit 1; }

# config-gen.sh 실행
chmod +x local-docker-env/config-gen.sh
./local-docker-env/config-gen.sh -a "$ACCOUNT_NUM" -f local-docker-env/config.json
./local-docker-env/config-gen.sh -a "$ACCOUNT_NUM" -f local-docker-env/config.json || { echo "Failed to execute config-gen.sh."; exit 1; }

# BRANCH와 REPO 정보를 입력으로 받아 docker-compose-gen.sh 실행
chmod +x local-docker-env/docker-compose-gen-git.sh
./local-docker-env/docker-compose-gen-git.sh -a "$ACCOUNT_NUM" -b "$BRANCH" -r "$REPO"
./local-docker-env/docker-compose-gen-git.sh -a "$ACCOUNT_NUM" -b "$BRANCH" -r "$REPO" || { echo "Failed to execute docker-compose-gen-git.sh."; exit 1; }

# Dockerfile.boot.git 및 Dockerfile.node.git 파일 복사
cp local-docker-env/Dockerfile.boot.git ./
cp local-docker-env/Dockerfile.node.git ./
cp local-docker-env/Dockerfile.boot.git ./ || { echo "Failed to copy Dockerfile.boot.git."; exit 1; }
cp local-docker-env/Dockerfile.node.git ./ || { echo "Failed to copy Dockerfile.node.git."; exit 1; }

# docker-compose.yml 파일을 이용해 docker-compose build 및 up 실행
docker compose -f docker-compose.yml build --no-cache
docker compose -f docker-compose.yml up -d
docker compose -f docker-compose.yml build --no-cache || { echo "Failed to build docker-compose."; exit 1; }
docker compose -f docker-compose.yml up -d || { echo "Failed to start docker-compose."; exit 1; }
19 changes: 12 additions & 7 deletions local-docker-env/local-docker.sh
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
#!/bin/bash

# gwemix path를 환경변수에 추가
current_dir=$(pwd)
export PATH=$PATH:${current_dir}/go-wemix/build/bin

# 필수 인수 확인
if [ "$#" -ne 2 ]; then
echo "Usage: $0 -a <account_num>"
Expand All @@ -21,25 +25,26 @@ done

# 필수 인수 확인
if [ -z "$ACCOUNT_NUM" ]; then
echo "Account number is required."
exit 1
fi

# key-gen.sh 실행
chmod +x local-docker-env/key-gen.sh
./local-docker-env/key-gen.sh -a "$ACCOUNT_NUM"
./local-docker-env/key-gen.sh -a "$ACCOUNT_NUM" || { echo "Failed to execute key-gen.sh."; exit 1; }

# config-gen.sh 실행
chmod +x local-docker-env/config-gen.sh
./local-docker-env/config-gen.sh -a "$ACCOUNT_NUM" -f local-docker-env/config.json
./local-docker-env/config-gen.sh -a "$ACCOUNT_NUM" -f local-docker-env/config.json || { echo "Failed to execute config-gen.sh."; exit 1; }

# docker-compose-gen.sh 실행
chmod +x local-docker-env/docker-compose-gen.sh
./local-docker-env/docker-compose-gen.sh -a "$ACCOUNT_NUM"
./local-docker-env/docker-compose-gen.sh -a "$ACCOUNT_NUM" || { echo "Failed to execute docker-compose-gen.sh."; exit 1; }

# Dockerfile.boot 및 Dockerfile.node 파일 복사
cp local-docker-env/Dockerfile.boot ./
cp local-docker-env/Dockerfile.node ./
cp local-docker-env/Dockerfile.boot ./ || { echo "Failed to copy Dockerfile.boot."; exit 1; }
cp local-docker-env/Dockerfile.node ./ || { echo "Failed to copy Dockerfile.node."; exit 1; }

# docker-compose.yml 파일을 이용해 docker-compose build 및 up 실행
docker compose -f docker-compose.yml build --no-cache
docker compose -f docker-compose.yml up -d
docker compose -f docker-compose.yml build --no-cache || { echo "Failed to build docker-compose."; exit 1; }
docker compose -f docker-compose.yml up -d || { echo "Failed to start docker-compose."; exit 1; }

0 comments on commit bf489bf

Please sign in to comment.