Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

test scripts with fixed nodekey #142

Open
wants to merge 6 commits into
base: dev
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions local-docker-env/Dockerfile.boot
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
ARG UBUNTU_VERSION

# Stage 1: Build stage
FROM golang:1.19 as builder
FROM golang:1.19 AS builder

# Set environment variables
ENV PATH=/usr/local/go/bin:$PATH
Expand Down Expand Up @@ -42,7 +42,7 @@ RUN apt-get remove -y \
apt-get clean

# Stage 2: Runtime stage
FROM ubuntu:${UBUNTU_VERSION}
FROM ubuntu:${UBUNTU_VERSION:-latest}

# Update and upgrade the package list
RUN apt-get update && \
Expand Down
4 changes: 2 additions & 2 deletions local-docker-env/Dockerfile.boot.git
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
ARG UBUNTU_VERSION

# Stage 1: Build stage
FROM golang:1.19 as builder
FROM golang:1.19 AS builder

# Set environment variables
ENV PATH=/usr/local/go/bin:$PATH
Expand Down Expand Up @@ -52,7 +52,7 @@ RUN apt-get remove -y \
apt-get clean

# Stage 2: Runtime stage
FROM ubuntu:${UBUNTU_VERSION}
FROM ubuntu:${UBUNTU_VERSION:-latest}

# Set environment variables
ENV SSL_CERT_FILE=/etc/ssl/certs/ca-certificates.crt
Expand Down
4 changes: 2 additions & 2 deletions local-docker-env/Dockerfile.node
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
ARG UBUNTU_VERSION

# Stage 1: Build stage
FROM golang:1.19 as builder
FROM golang:1.19 AS builder

# Set environment variables
ENV PATH=/usr/local/go/bin:$PATH
Expand Down Expand Up @@ -42,7 +42,7 @@ RUN apt-get remove -y \
apt-get clean

# Stage 2: Runtime stage
FROM ubuntu:${UBUNTU_VERSION}
FROM ubuntu:${UBUNTU_VERSION:-latest}

# Update and upgrade the package list
RUN apt-get update && \
Expand Down
4 changes: 2 additions & 2 deletions local-docker-env/Dockerfile.node.git
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
ARG UBUNTU_VERSION

# Stage 1: Build stage
FROM golang:1.19 as builder
FROM golang:1.19 AS builder

# Set environment variables
ENV PATH=/usr/local/go/bin:$PATH
Expand Down Expand Up @@ -52,7 +52,7 @@ RUN apt-get remove -y \
apt-get clean

# Stage 2: Runtime stage
FROM ubuntu:${UBUNTU_VERSION}
FROM ubuntu:${UBUNTU_VERSION:-latest}

# Set environment variables
ENV SSL_CERT_FILE=/etc/ssl/certs/ca-certificates.crt
Expand Down
30 changes: 10 additions & 20 deletions local-docker-env/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,32 +11,22 @@ This document explains how to set up a local testing environment based on the `g
### local-docker.sh

- **Purpose**: Integrated running script for local testing based on the local repository.
- **Usage**: `./local-docker-env/local-docker.sh -a <account_num> -v <ubuntu_version>(optional)`
- **Usage**: `./local-docker-env/local-docker.sh -a <account_num> -v <ubuntu_version>(optional) --keep-nodekey(optional)`

### local-docker-git.sh

- **Purpose**: Integrated running script for local testing based on the Git repository.
- **Usage**: `./local-docker-env/local-docker-git.sh -a <account_num> -b <branch> -r <repo> -v <ubuntu_version>(optional)`
- **Usage**: `./local-docker-env/local-docker-git.sh -a <account_num> -b <branch> -r <repo> -v <ubuntu_version>(optional --keep-nodekey(optional)`

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

<ubuntu_version>(optional) --keep-nodekey(optional)


### key-gen.sh
### gen-nodekey.sh

- **Purpose**: Generates an account in the `keystore` folder and creates a nodekey in the `nodekey` folder.
- **Usage**: `./key-gen.sh -a <account_num>`
- **Purpose**: Script for generating a nodekey for the node.
- **Usage**: `./local-docker-env/gen-nodekey.sh -a <nodekey_num>`

### config-gen.sh
### gen-account.sh

- **Purpose**: Generates the `config.json` file.
- **Usage**: `./config-gen.sh -a <account_num> -f <output_config_file>`

### docker-compose-gen.sh

- **Purpose**: Generates the `docker-compose.yml` file based on the local repository.
- **Usage**: `./docker-compose-gen.sh -a <account_num> -f <output_file_path> -v <ubuntu_version>(optional)`

### docker-compose-gen-git.sh

- **Purpose**: Generates the `docker-compose.yml` file based on the Git repository.
- **Usage**: `./docker-compose-gen-git.sh -a <account_num> -f <output_file_path> -r <repo_url> -b <branch_name> -v <ubuntu_version>(optional)`
- **Purpose**: Script for generating a nodekey for the node.
- **Usage**: `./local-docker-env/gen-account.sh -a <account_num>`

### init-boot.sh

Expand Down Expand Up @@ -66,11 +56,11 @@ This document explains how to set up a local testing environment based on the `g
### Execution based on the local repository code

```bash
./local-docker-env/local-docker.sh -a <account_num> -v <ubuntu_version>(optional)
./local-docker-env/local-docker.sh -a <account_num> -v <ubuntu_version> (optional) --keep-nodekey (optional)
```

### Execution based on the Git repository code

```bash
./local-docker-env/local-docker-git.sh -a <account_num> -b <branch> -r <repo> -v <ubuntu_version>(optional)
./local-docker-env/local-docker-git.sh -a <account_num> -b <branch> -r <repo> -v <ubuntu_version> (optional) --keep-nodekey (optional)
```
21 changes: 5 additions & 16 deletions local-docker-env/key-gen.sh → local-docker-env/gen-account.sh
Original file line number Diff line number Diff line change
@@ -1,33 +1,32 @@
#!/bin/bash

# 필수 인수 확인
# Check required arguments
if [ "$#" -ne 2 ]; then
echo "Usage: $0 -a <account_num>"
exit 1
fi

# 옵션 파싱
# Option parsing
while getopts "a:" opt; do
case ${opt} in
a)
ACCOUNT_NUM=$OPTARG
;;
\?)
echo "Usage: $0 -a <account_num> -f <output_config_file>"
echo "Usage: $0 -a <account_num>"
exit 1
;;
esac
done

# 필수 인수 확인
# Check required arguments
if [ -z "$ACCOUNT_NUM" ]; then
exit 1
fi

mkdir local-docker-env/keystore
mkdir local-docker-env/nodekey

# 계정 및 노드 키 생성
# Create accounts
for ((i = 1; i <= ACCOUNT_NUM; i++)); do
if [ -f "local-docker-env/keystore/account$i" ]; then
rm local-docker-env/keystore/account$i
Expand All @@ -39,14 +38,4 @@ for ((i = 1; i <= ACCOUNT_NUM; i++)); do
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
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
26 changes: 13 additions & 13 deletions local-docker-env/config-gen.sh → local-docker-env/gen-config.sh
Original file line number Diff line number Diff line change
@@ -1,39 +1,39 @@
#!/bin/bash

# 필수 인수 확인
# Check required arguments
if [ "$#" -ne 4 ]; then
echo "Usage: $0 -a <account_num> -f <output_config_file>"
echo "Usage: $0 -a <node_num> -f <output_config_file>"
exit 1
fi

# 옵션 파싱
# Option parsing
while getopts "a:f:" opt; do
case ${opt} in
a)
ACCOUNT_NUM=$OPTARG
NODE_NUM=$OPTARG
;;
f)
OUTPUT_CONFIG_FILE=$OPTARG
;;
\?)
echo "Usage: $0 -a <account_num> -f <output_config_file>"
echo "Usage: $0 -a <node_num> -f <output_config_file>"
exit 1
;;
esac
done

# 필수 인수 확인
if [ -z "$ACCOUNT_NUM" ] || [ -z "$OUTPUT_CONFIG_FILE" ]; then
# Check required arguments
if [ -z "$NODE_NUM" ] || [ -z "$OUTPUT_CONFIG_FILE" ]; then
exit 1
fi

# 초기화
# Initialize
echo '{"members":[], "accounts":[]}' >"$OUTPUT_CONFIG_FILE"

# 파일을 JSON 형식으로 로드
# Load file as JSON
json_content=$(cat "$OUTPUT_CONFIG_FILE")

# 고정된 env 값을 포함한 JSON 객체
# JSON object with fixed env values
ENV_JSON='{
"ballotDurationMin": 86400,
"ballotDurationMax": 604800,
Expand All @@ -53,8 +53,8 @@ ENV_JSON='{
json_content=$(echo "$json_content" | jq --argjson env "$ENV_JSON" \
'.env = $env| .extraData = "chain for local test"')

# JSON 구성 파일 생성
for ((i = 1; i <= ACCOUNT_NUM; i++)); do
# Generate JSON config file
for ((i = 1; i <= NODE_NUM; i++)); do
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"
Expand All @@ -74,6 +74,6 @@ for ((i = 1; i <= ACCOUNT_NUM; i++)); do
fi
done

# 수정된 내용을 파일에 저장
# Save modified content to file
echo "$json_content" >"$OUTPUT_CONFIG_FILE"
echo "Updated config saved to $OUTPUT_CONFIG_FILE"
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
#!/bin/bash

# Usage: ./gen-docker-compose.sh -a <account_num> -f <output_config_file> -r <repo_url> -b <branch_name>
# -a: 계정 수
# -f: 출력 파일
# -r: 레포지토리 URL
# -b: 브랜치 이름
# -a 옵션은 필수이며, -f 옵션은 선택적
# -f 옵션을 지정하지 않으면, 현재 디렉토리에 docker-compose.yml 파일을 생성
# -f 옵션을 지정하면, 해당 경로에 docker-compose.yml 파일을 생성
# -a: number of accounts
# -f: output file
# -r: repository URL
# -b: branch name
# -a option is mandatory, -f option is optional
# If -f option is not specified, a docker-compose.yml file will be created in the current directory
# If -f option is specified, a docker-compose.yml file will be created at the specified path

# Parse command line arguments
while getopts "a:f:r:b:v:" opt; do
Expand Down Expand Up @@ -63,7 +63,7 @@ fi

# Set default version if not provided
if [ -z "$version" ]; then
version="latest"
version="22.04"
fi

# Generate docker-compose.yml content
Expand Down
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
#!/bin/bash

# Usage: ./gen-docker-compose.sh -a <account_num> -f <output_config_file>
# -a: 계정 수
# -f: 출력 파일
# -a 옵션은 필수이며, -f, -v 옵션은 선택적
# -f 옵션을 지정하지 않으면, 현재 디렉토리에 docker-compose.yml 파일을 생성
# -f 옵션을 지정하면, 해당 경로에 docker-compose.yml 파일을 생성
# -v 옵션을 지정하지 않으면, latest 버전으로 설정
# -v 옵션을 지정하면, 해당 버전으로 설정
# -a: number of accounts
# -f: output file
# -a option is required, -f and -v options are optional
# If -f option is not specified, a docker-compose.yml file will be created in the current directory
# If -f option is specified, a docker-compose.yml file will be created at the specified path
# If -v option is not specified, the version will be set to latest
# If -v option is specified, the version will be set to the specified version

# Parse command line arguments
while getopts "a:f:v:" opt; do
Expand Down Expand Up @@ -45,7 +45,7 @@ fi

# Set default version if not provided
if [ -z "$version" ]; then
version="latest"
version="22.04"
fi

# Generate docker-compose.yml content
Expand Down
40 changes: 40 additions & 0 deletions local-docker-env/gen-nodekey.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
#!/bin/bash

# Check required arguments
if [ "$#" -ne 2 ]; then
echo "Usage: $0 -a <nodekey_num>"
exit 1
fi

# Option parsing
while getopts "a:" opt; do
case ${opt} in
a)
NODEKEY_NUM=$OPTARG
;;
\?)
echo "Usage: $0 -a <nodekey_num>"
exit 1
;;
esac
done

# Check required arguments
if [ -z "$NODEKEY_NUM" ]; then
exit 1
fi

mkdir local-docker-env/nodekey

# Create nodekeys
for ((i = 1; i <= NODEKEY_NUM; i++)); do
if [ -f "local-docker-env/nodekey/nodekey$i" ]; then
rm local-docker-env/nodekey/nodekey$i
fi
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
6 changes: 3 additions & 3 deletions local-docker-env/init-boot.sh
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@ chmod a+x bin/gwemix.sh
bin/gwemix.sh init "" conf/config.json
bin/gwemix.sh start

# gwemix 서비스가 정상적으로 시작되었는지 확인
# Check if gwemix service has started successfully
check_gwemix_started() {
local log_file="logs/log" # gwemix 로그 파일 경로
local log_file="logs/log"
local success_message="HTTP server started"
local max_retries=30
local retries=0
Expand All @@ -32,7 +32,7 @@ check_gwemix_started() {
fi
}

# gwemix 서비스가 정상적으로 시작되었는지 확인
# Check if gwemix service has started successfully
check_gwemix_started

bin/gwemix.sh init-gov "" conf/config.json keystore/account1 test
Expand Down
11 changes: 9 additions & 2 deletions local-docker-env/init-node.sh
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#!/bin/bash

# gwemix 서비스 시작
# Set the permissions for the gwemix binary
chmod a+x bin/gwemix

# Check if the boot node has started
Expand Down Expand Up @@ -31,5 +31,12 @@ check_boot_node_started() {

check_boot_node_started

bin/gwemix wemix download-genesis --url http://172.16.237.11:8588 --out genesis.json
bin/gwemix wemix download-genesis --url http://172.16.237.11:8588 --out /usr/local/wemix/genesis.json

# Check if the genesis.json file has been created
if [ ! -f /usr/local/wemix/genesis.json ]; then
echo "Failed to create genesis.json file."
exit 1
fi

bin/gwemix --datadir /usr/local/wemix --metrics --http --http.addr 0.0.0.0 --mine --http.port 8588 --ws --ws.addr 0.0.0.0 --ws.port 8598 --syncmode full --gcmode archive --port 8589
Loading
Loading