From 6c07ff70d01a254114d4137ce11e3169fe721ea9 Mon Sep 17 00:00:00 2001 From: Carlos Alejandro Gutierrez Sandoval Date: Thu, 19 Oct 2023 14:06:45 -0600 Subject: [PATCH 1/2] update up/down scripts --- devenv/common.sh | 51 +++++++++++++++++ devenv/docker-compose.yml | 104 +++++----------------------------- devenv/down.sh | 8 ++- devenv/min-docker-compose.yml | 95 +++++++++++++++++++++++++++++++ devenv/up.sh | 11 ++-- 5 files changed, 174 insertions(+), 95 deletions(-) create mode 100644 devenv/common.sh create mode 100644 devenv/min-docker-compose.yml diff --git a/devenv/common.sh b/devenv/common.sh new file mode 100644 index 00000000..34ddb188 --- /dev/null +++ b/devenv/common.sh @@ -0,0 +1,51 @@ +show_help() { + echo "Usage: $0 [-h|--help] " + echo "Available profiles: min (bitcoin, stacks, electrs), full" + echo "Configs and runtimes may change depending on the profile." + exit 0 +} + +docker_runner() { + if [ "$profile" == "min" ]; then + docker compose -f min-docker-compose.yml $1 $2 + elif [ "$profile" == "full" ]; then + docker compose $1 $2 + else + echo "Invalid profile. Available profiles: min, full" + fi +} + +run() { + local profile="" + while [[ $# -gt 0 ]]; do + key="$1" + + case $key in + -h | --help) + show_help + ;; + min | full) + if ! [ -z "$profile" ]; then + echo "Profile '$profile' already set" + show_help + exit 1 + fi + profile="$1" + shift + ;; + *) + echo "Unknown option: $1" + show_help + ;; + esac + done + + if [ -z "$profile" ]; then + echo "You must specify a profile (min or full)" + show_help + exit 1 + fi + + local subcommand=$(basename $0 .sh) + docker_runner $subcommand "$FLAGS" +} diff --git a/devenv/docker-compose.yml b/devenv/docker-compose.yml index 15dd6628..30625416 100644 --- a/devenv/docker-compose.yml +++ b/devenv/docker-compose.yml @@ -2,34 +2,13 @@ version: '3.2' services: bitcoin: - image: bitcoin:latest - container_name: bitcoin - stop_grace_period: 5s - build: - context: ./bitcoin/docker - args: - VERSION: '25.0' - ports: - - 18444:18444 - - 18443:18443 - - 18433:18433 - environment: - - 'BTC_NETWORK=regtest' - - 'BTC_DISABLEWALLET=0' - - 'BTC_TXINDEX=1' - - 'BTC_RPCBIND=0.0.0.0' - - 'BTC_RPCALLOWIP=0.0.0.0/0' - - 'BTC_RPCPASSWORD=devnet' - - 'BTC_RPCUSER=devnet' + extends: + file: min-docker-compose.yml + service: bitcoin postgres: - image: postgres:15-alpine - container_name: postgres - stop_grace_period: 5s - ports: - - 5432:5432 - environment: - - POSTGRES_USER=postgres - - POSTGRES_PASSWORD=postgres + extends: + file: min-docker-compose.yml + service: postgres mongodb: image: mongo:6.0 container_name: mongodb @@ -63,56 +42,13 @@ services: INIT_BTC_BLOCKS: 200 BTC_BLOCK_GEN_TIME: 10 stacks: - image: stacks:latest - container_name: stacks - stop_grace_period: 5s - build: - context: ./stacks/docker - args: - STACKS_NODE_VERSION: '2.4.0.0.0' - GIT_URI: https://github.com/stacks-network/stacks-blockchain.git - GIT_BRANCH: develop - ports: - - 20444:20444 - - 20443:20443 - depends_on: - - bitcoin - - miner - environment: - - STACKS_LOG_DEBUG=0 - - STACKS_LOG_JSON=0 + extends: + file: min-docker-compose.yml + service: stacks stacks-api: - image: stacks-api:latest - container_name: stacks-api - stop_grace_period: 5s - build: - context: ./stacks-api/docker - args: - GIT_URI: 'https://github.com/hirosystems/stacks-blockchain-api.git' - GIT_BRANCH: 'v7.3.0' - ports: - - 3999:3999 - - 3700:3700 - depends_on: - - postgres - - stacks - - bitcoin - environment: - - NODE_ENV=production - - GIT_TAG=master - - PG_HOST=postgres - - PG_PORT=5432 - - PG_USER=postgres - - PG_PASSWORD=postgres - - PG_DATABASE=postgres - - STACKS_CHAIN_ID=0x80000000 - - STACKS_CORE_EVENT_PORT=3700 - - STACKS_CORE_EVENT_HOST=0.0.0.0 - - STACKS_BLOCKCHAIN_API_PORT=3999 - - STACKS_BLOCKCHAIN_API_HOST=0.0.0.0 - - STACKS_CORE_RPC_HOST=stacks - - STACKS_CORE_RPC_PORT=20443 - - API_DOCS_URL=http://localhost:3999/doc + extends: + file: min-docker-compose.yml + service: stacks-api stacks-explorer: image: stacks-explorer container_name: stacks-explorer @@ -133,19 +69,9 @@ services: environment: - NEXT_PUBLIC_MAINNET_API_SERVER=http://127.0.0.1:3999 electrs: - image: electrs:latest - container_name: electrs - stop_grace_period: 5s - build: - context: ./electrs/docker - ports: - - 60401:60401 - - 3002:3002 - depends_on: - - bitcoin - - miner - environment: - RUST_BACKTRACE: 1 + extends: + file: min-docker-compose.yml + service: electrs sbtc: image: sbtc:latest container_name: sbtc diff --git a/devenv/down.sh b/devenv/down.sh index 06f560b7..f6ce30c2 100755 --- a/devenv/down.sh +++ b/devenv/down.sh @@ -1,2 +1,8 @@ #!/usr/bin/env bash -docker compose down + +set -ueo >/dev/null + +FLAGS="" +source ./common.sh + +run $@ diff --git a/devenv/min-docker-compose.yml b/devenv/min-docker-compose.yml new file mode 100644 index 00000000..7504a588 --- /dev/null +++ b/devenv/min-docker-compose.yml @@ -0,0 +1,95 @@ +version: '3.2' + +services: + bitcoin: + image: bitcoin:latest + container_name: bitcoin + stop_grace_period: 5s + build: + context: ./bitcoin/docker + args: + VERSION: '25.0' + ports: + - 18444:18444 + - 18443:18443 + - 18433:18433 + environment: + - 'BTC_NETWORK=regtest' + - 'BTC_DISABLEWALLET=0' + - 'BTC_TXINDEX=1' + - 'BTC_RPCBIND=0.0.0.0' + - 'BTC_RPCALLOWIP=0.0.0.0/0' + - 'BTC_RPCPASSWORD=devnet' + - 'BTC_RPCUSER=devnet' + electrs: + image: electrs:latest + container_name: electrs + stop_grace_period: 5s + build: + context: ./electrs/docker + ports: + - 60401:60401 + - 3002:3002 + depends_on: + - bitcoin + environment: + RUST_BACKTRACE: 1 + stacks: + image: stacks:latest + container_name: stacks + stop_grace_period: 5s + build: + context: ./stacks/docker + args: + STACKS_NODE_VERSION: '2.4.0.0.0' + GIT_URI: https://github.com/stacks-network/stacks-blockchain.git + GIT_BRANCH: develop + ports: + - 20444:20444 + - 20443:20443 + depends_on: + - bitcoin + environment: + - STACKS_LOG_DEBUG=0 + - STACKS_LOG_JSON=0 + postgres: + image: postgres:15-alpine + container_name: postgres + stop_grace_period: 5s + ports: + - 5432:5432 + environment: + - POSTGRES_USER=postgres + - POSTGRES_PASSWORD=postgres + stacks-api: + image: stacks-api:latest + container_name: stacks-api + stop_grace_period: 5s + build: + context: ./stacks-api/docker + args: + GIT_URI: 'https://github.com/hirosystems/stacks-blockchain-api.git' + GIT_BRANCH: 'v7.3.0' + ports: + - 3999:3999 + - 3700:3700 + depends_on: + - postgres + - stacks + - bitcoin + environment: + - NODE_ENV=production + - GIT_TAG=master + - PG_HOST=postgres + - PG_PORT=5432 + - PG_USER=postgres + - PG_PASSWORD=postgres + - PG_DATABASE=postgres + - STACKS_CHAIN_ID=0x80000000 + - STACKS_CORE_EVENT_PORT=3700 + - STACKS_CORE_EVENT_HOST=0.0.0.0 + - STACKS_BLOCKCHAIN_API_PORT=3999 + - STACKS_BLOCKCHAIN_API_HOST=0.0.0.0 + - STACKS_CORE_RPC_HOST=stacks + - STACKS_CORE_RPC_PORT=20443 + - API_DOCS_URL=http://localhost:3999/doc diff --git a/devenv/up.sh b/devenv/up.sh index ba87fb47..a2d46c0c 100755 --- a/devenv/up.sh +++ b/devenv/up.sh @@ -1,7 +1,8 @@ #!/usr/bin/env bash -if [ $? -eq 0 ]; then - docker compose up -d -else - echo "Build failed, not starting devenv" -fi +set -ueo >/dev/null + +FLAGS="-d --remove-orphans" +source ./common.sh + +run $@ From 89516e2cad25642ffbb1e5708424ba08811119ec Mon Sep 17 00:00:00 2001 From: Carlos Alejandro Gutierrez Sandoval Date: Mon, 6 Nov 2023 12:28:01 -0600 Subject: [PATCH 2/2] miner in min devenv --- devenv/docker-compose.yml | 13 +++---------- devenv/min-docker-compose.yml | 10 ++++++++++ 2 files changed, 13 insertions(+), 10 deletions(-) diff --git a/devenv/docker-compose.yml b/devenv/docker-compose.yml index 30625416..be34151f 100644 --- a/devenv/docker-compose.yml +++ b/devenv/docker-compose.yml @@ -31,16 +31,9 @@ services: MYSQL_PASSWORD: "mempool" MYSQL_ROOT_PASSWORD: "admin" miner: - image: miner:latest - container_name: miner - stop_grace_period: 5s - build: - context: ./miner/docker - depends_on: - - bitcoin - environment: - INIT_BTC_BLOCKS: 200 - BTC_BLOCK_GEN_TIME: 10 + extends: + file: min-docker-compose.yml + service: miner stacks: extends: file: min-docker-compose.yml diff --git a/devenv/min-docker-compose.yml b/devenv/min-docker-compose.yml index 7504a588..2508dade 100644 --- a/devenv/min-docker-compose.yml +++ b/devenv/min-docker-compose.yml @@ -21,6 +21,16 @@ services: - 'BTC_RPCALLOWIP=0.0.0.0/0' - 'BTC_RPCPASSWORD=devnet' - 'BTC_RPCUSER=devnet' + miner: + image: miner:latest + stop_grace_period: 5s + build: + context: ./miner/docker + depends_on: + - bitcoin + environment: + INIT_BTC_BLOCKS: 101 + BTC_BLOCK_GEN_TIME: 5 electrs: image: electrs:latest container_name: electrs