Skip to content

Commit

Permalink
Merge pull request godwokenrises#281 from sopium/exec-godwoken
Browse files Browse the repository at this point in the history
Make docker ps more accurate and start/stop faster
  • Loading branch information
keroro520 authored Jun 20, 2022
2 parents 6081043 + 2a891f5 commit 319930c
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 23 deletions.
15 changes: 10 additions & 5 deletions docker/docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ services:
command: [ "run", "-C", "/var/lib/ckb" ]

ckb-miner:
init: true
image: nervos/ckb:v0.103.0
user: root
volumes:
Expand All @@ -54,6 +55,7 @@ services:

ckb-indexer:
image: nervos/ckb-indexer:0.3.2
init: true
environment:
CKB_RPC: http://ckb:8114
ports:
Expand All @@ -71,11 +73,12 @@ services:

godwoken:
image: ghcr.io/flouse/godwoken-prebuilds:1.2-gw-pull-721-merge-202206140118
init: true
healthcheck:
test: /var/lib/layer2/healthcheck.sh
start_period: 10s
interval: 30s
retries: 600
start_period: 600s
interval: 10s
retries: 3
environment:
RUST_LOG: info,gw_generator=debug
GODWOKEN_MODE: fullnode
Expand All @@ -93,7 +96,7 @@ services:
deploy:
restart_policy:
condition: on-failure
max_attempts: 1
max_attempts: 10
depends_on:
postgres:
condition: service_started
Expand Down Expand Up @@ -137,11 +140,12 @@ services:

web3:
image: nervos/godwoken-web3-prebuilds:v1.1.2-rc1
init: true
healthcheck:
test: curl http://127.0.0.1:8024 || exit 1
start_period: 10s
interval: 10s
retries: 30
retries: 3
volumes:
- ./layer2/config/web3-config.env:/godwoken-web3/packages/api-server/.env
- ./web3/entrypoint.sh:/var/lib/web3/entrypoint.sh
Expand Down Expand Up @@ -170,6 +174,7 @@ services:

web3-indexer:
image: nervos/godwoken-web3-indexer-prebuilds:v1.1.2-rc1
init: true
volumes:
- ./layer2/config:/var/lib/layer2/config
- ./web3/indexer_entrypoint.sh:/var/lib/web3-indexer/entrypoint.sh
Expand Down
34 changes: 17 additions & 17 deletions docker/layer2/entrypoint.sh
Original file line number Diff line number Diff line change
Expand Up @@ -25,11 +25,9 @@ function stop-ckb-miner() {
fi
}

function start-godwoken-at-background() {
function wait-for-godwoken-started() {
log "Starting"
start_time=$(date +%s)
godwoken run -c $CONFIG_DIR/godwoken-config.toml & # &> /dev/null &
GODWOKEN_PID=$!
while true; do
sleep 1
result=$(curl http://127.0.0.1:8119 &> /dev/null || echo "Godwoken not started")
Expand Down Expand Up @@ -219,6 +217,15 @@ EOF
log "Finished"
}

function post-godwoken-start-setup() {
wait-for-godwoken-started

# Should make sure that the Polyjuice root account was created and the layer2 block was synced
create-polyjuice-root-account

generate-web3-indexer-config
}

function log() {
echo "[${FUNCNAME[1]}] $1"
}
Expand All @@ -227,26 +234,19 @@ function main() {
godwoken --version
gw-tools --version

if [ -f "$CONFIG_DIR/web3-indexer-config.toml" ]; then
exec godwoken run -c $CONFIG_DIR/godwoken-config.toml
fi

# Setup Godwoken at the first time
deploy-scripts
deploy-rollup-genesis
generate-godwoken-config

start-godwoken-at-background
# Exec godwoken and finish setup in the background.
post-godwoken-start-setup &

# Should make sure that the Polyjuice root account was created and the layer2 block was synced
create-polyjuice-root-account

generate-web3-indexer-config

# Godwoken daemon
while true; do
result=$(curl http://127.0.0.1:8119 &> /dev/null || echo "wake up")
if [ "$result" == "wake up" ]; then
godwoken run -c $CONFIG_DIR/godwoken-config.toml || echo "Godwoken exit"
fi
sleep 30
done
exec godwoken run -c $CONFIG_DIR/godwoken-config.toml
}

main "$@"
2 changes: 1 addition & 1 deletion docker/web3/entrypoint.sh
Original file line number Diff line number Diff line change
Expand Up @@ -10,4 +10,4 @@ mkdir -p /usr/local/godwoken-web3/address-mapping
cd /godwoken-web3

yarn knex migrate:latest
yarn run start
yarn run start:prod

0 comments on commit 319930c

Please sign in to comment.