Skip to content

Commit

Permalink
Merge branch 'master' into feat-576-request-metrics
Browse files Browse the repository at this point in the history
  • Loading branch information
chris-4chain authored Mar 11, 2024
2 parents 51fa862 + 79f5d01 commit 8753c8f
Show file tree
Hide file tree
Showing 3 changed files with 218 additions and 10 deletions.
14 changes: 14 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -331,6 +331,20 @@ There are two way of running this script:
```bash
./start.sh -l
```


Ports which are used:

- 3002 - SPV Wallet web-frontend
- 8180 - SPV Wallet web-backend
- 3003 - SPV Wallet (core service)
- 3000 - SPV Wallet admin
- 5432 - PostgreSQL DB
- 6379 - Redis
- 8080 - Block Headers Service
- 27017 - MongoDB
- 80 - in case of exposing on the paymail domain and its subdomains
- 443 - in case of exposing on the paymail domain and its subdomains
<br/>

## Code Standards
Expand Down
84 changes: 81 additions & 3 deletions docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,13 @@ services:
wallet-frontend:
image: bsvb/spv-wallet-web-frontend:latest
pull_policy: always
labels:
- "traefik.enable=true"
- "traefik.http.routers.walletfrontend.rule=Host(`wallet.${RUN_PAYMAIL_DOMAIN}`)"
- "traefik.http.routers.walletfrontend.entrypoints=websecure"
- "traefik.http.routers.walletfrontend.tls=true"
- "traefik.http.routers.walletfrontend.tls.certresolver=httpsresolver"
- "traefik.http.services.walletfrontend.loadbalancer.server.port=80"
ports:
- "3002:80"
configs:
Expand All @@ -14,9 +21,15 @@ services:
wallet-backend:
image: bsvb/spv-wallet-web-backend:latest
pull_policy: always
labels:
- "traefik.enable=true"
- "traefik.http.routers.walletbackend.rule=Host(`${RUN_API_DOMAIN}`)"
- "traefik.http.routers.walletbackend.entrypoints=websecure"
- "traefik.http.routers.walletbackend.tls=true"
- "traefik.http.routers.walletbackend.tls.certresolver=httpsresolver"
- "traefik.http.services.walletbackend.loadbalancer.server.port=8180"
environment:
SPVWALLET_PAYMAIL_DOMAIN: '${RUN_PAYMAIL_DOMAIN}'
HTTP_SERVER_CORS_ALLOWEDDOMAINS: 'http://localhost:3002'
env_file:
- .env.config
ports:
Expand All @@ -30,16 +43,48 @@ services:
block-headers-service:
image: bsvb/block-headers-service:latest
pull_policy: always
labels:
- "traefik.enable=true"
- "traefik.http.routers.headers.rule=Host(`headers.${RUN_PAYMAIL_DOMAIN}`)"
- "traefik.http.routers.headers.entrypoints=websecure"
- "traefik.http.routers.headers.tls=true"
- "traefik.http.routers.headers.tls.certresolver=httpsresolver"
- "traefik.http.services.headers.loadbalancer.server.port=8080"
command:
- "--preloaded"
ports:
- "8080:8080"
volumes:
- block-headers-service-data:/app/data

spv-wallet-admin:
image: bsvb/spv-wallet-admin:latest
pull_policy: always
labels:
- "traefik.enable=true"
- "traefik.http.routers.admin.rule=Host(`admin.${RUN_PAYMAIL_DOMAIN}`)"
- "traefik.http.routers.admin.entrypoints=websecure"
- "traefik.http.routers.admin.tls=true"
- "traefik.http.routers.admin.tls.certresolver=httpsresolver"
- "traefik.http.services.admin.loadbalancer.server.port=3000"
env_file:
- .env.config
ports:
- "3000:3000"
configs:
- source: admin-env-config
target: /usr/share/nginx/html/env-config.json

spv-wallet:
image: bsvb/spv-wallet:latest
pull_policy: always
labels:
- "traefik.enable=true"
- "traefik.http.routers.wallet.rule=Host(`${RUN_PAYMAIL_DOMAIN}`)"
- "traefik.http.routers.wallet.entrypoints=websecure"
- "traefik.http.routers.wallet.tls=true"
- "traefik.http.routers.wallet.tls.certresolver=httpsresolver"
- "traefik.http.services.wallet.loadbalancer.server.port=3003"
environment:
SPVWALLET_PAYMAIL_DOMAINS: '${RUN_PAYMAIL_DOMAIN}'
env_file:
Expand Down Expand Up @@ -90,6 +135,31 @@ services:
retries: 5
start_period: 40s

wallet-gateway:
image: traefik:v2.11
container_name: traefik
command:
- "--log.level=DEBUG"
- "--api.insecure=true"
- "--providers.docker=true"
- "--providers.docker.exposedbydefault=false"
- "--entrypoints.web.address=:80"
- "--entrypoints.websecure.address=:443"
- "--entrypoints.web.http.redirections.entrypoint.to=websecure"
- "--entrypoints.web.http.redirections.entrypoint.scheme=https"
- "--entrypoints.web.http.redirections.entrypoint.permanent=true"
- "--certificatesresolvers.httpsresolver.acme.storage=/gateway/acme.json"
- "--certificatesresolvers.httpsresolver.acme.tlschallenge=true"
ports:
- "80:80"
- "443:443"
volumes:
- "/var/run/docker.sock:/var/run/docker.sock:ro"
- "wallet-gateway-data:/gateway"
labels:
- "traefik.enable=true"


volumes:
wallet-postgresql-data:
driver: local
Expand All @@ -99,12 +169,20 @@ volumes:
driver: local
block-headers-service-data:
driver: local
wallet-gateway-data:
driver: local

configs:
frontend-env-config:
content: |
{
"paymailDomain": "${RUN_PAYMAIL_DOMAIN}",
"apiUrl": "http://localhost:8180",
"wsUrl": "ws://localhost:8180/api/websocket"
"apiUrl": "http${RUN_SECURED_PROTOCOL_SUFFIX}://${RUN_API_DOMAIN}",
"wsUrl": "ws${RUN_SECURED_PROTOCOL_SUFFIX}://${RUN_API_DOMAIN}/api/websocket"
}
admin-env-config:
content: |
{
"serverUrl": "http${RUN_SECURED_PROTOCOL_SUFFIX}://${RUN_SPVWALLET_DOMAIN}/v1",
"hideServerUrl": false
}
130 changes: 123 additions & 7 deletions start.sh
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,19 @@ color_user="\033[0;35m" # purple
color_reset="\033[0m"
choice=''

# Constants
default_xpriv_value="xprv9s21ZrQH143K3CbJXirfrtpLvhT3Vgusdo8coBritQ3rcS7Jy7sxWhatuxG5h2y1Cqj8FKmPp69536gmjYRpfga2MJdsGyBsnB12E19CESK"

function print_debug() {
if [ "$debug" == "true" ]; then
echo -e "${color_debug}$1${color_reset}"
fi
}

function print_info() {
echo -e "$1"
}

function print_success() {
echo -e "${color_success}$1${color_reset}"
}
Expand Down Expand Up @@ -242,17 +249,25 @@ while [[ $# -gt 0 ]]; do
paymail_domain="$2"
shift
;;
-l|--load)
load_config="true"
# no additional arguments so now `shift` command
-a|--admin-panel)
admin_panel="$2"
shift
;;
-e|--expose)
expose="$2"
shift
;;
-b|--background)
background="true"
# no additional arguments so now `shift` command
background="$2"
shift
;;
-l|--load)
load_config="true"
# no additional arguments so no `shift` command
;;
-d|--debug)
debug="true"
# no additional arguments so now `shift` command
# no additional arguments so no `shift` command
;;
-h|--help)
echo -e "Usage: ./start.sh [OPTIONS]"
Expand All @@ -261,8 +276,9 @@ while [[ $# -gt 0 ]]; do
echo ""
echo -e "Options:"
echo -e " -pm, --paymail\t\t PayMail domain for which to run all applications"
echo -e " -e, --expose\t\t Whether to expose the services PayMail domain and its subdomains - true/false"
echo -e " -l, --load\t\t\t Load previously stored config from .env.config file"
echo -e " -b, --background\t\t Whether the applications should be run in background"
echo -e " -b, --background\t\t Whether the applications should be run in background - true/false"
echo -e " -d, --debug\t\t\t Run in debug mode"
echo -e " -h, --help\t\t\t Show this message"
echo -e ""
Expand All @@ -279,6 +295,9 @@ while [[ $# -gt 0 ]]; do
echo -e " -wf, --wallet-frontend\t Whether the wallet-frontend should be run - true/false"
echo -e " -wb, --wallet-backend\t Whether the wallet-backend should be run - true/false"
echo -e " --xprv\t\t\t Define admin xPriv"
echo ""
echo -e "<---------- SPV WALLET ADMIN SECTION"
echo -e " -a, --admin-panel\t Whether the spv-wallet-admin should be run - true/false"
exit 1;
shift
;;
Expand Down Expand Up @@ -309,10 +328,12 @@ if [ "$load_config" == "true" ]; then
load_from 'RUN_SPVWALLET_FRONTEND' wallet_frontend
load_from 'RUN_SPVWALLET_BACKEND' wallet_backend
load_from 'RUN_PAYMAIL_DOMAIN' paymail_domain
load_from 'RUN_EXPOSED' expose
load_from 'RUN_IN_BACKGROUND' background
load_from 'RUN_WITH_DEFAULT_XPUB' default_xpub
load_from 'SPVWALLET_AUTH_ADMIN_KEY' admin_xpub
load_from 'SPVWALLET_ADMIN_XPRIV' admin_xpriv
load_from 'RUN_ADMIN_PANEL' admin_panel
done < ".env.config"
print_success "Config loaded from .env.config file"
print_debug "Config after loading .env.config:"
Expand Down Expand Up @@ -354,6 +375,13 @@ if [ "$spv_wallet" == "" ]; then
print_debug "spv_wallet: $spv_wallet"
fi

# <---------- SPV WALLET ADMIN SECTION
if [ "$admin_panel" == "" ]; then
ask_for_yes_or_no "Do you want to run spv-wallet-admin?"
admin_panel="$choice"
print_debug "admin_panel: $admin_panel"
fi

# <---------- BLOCK HEADERS SERVICE SECTION
if [ "$block_headers_service" == "" ]; then
ask_for_yes_or_no "Do you want to run block-headers-service?"
Expand All @@ -379,25 +407,68 @@ if [ "$spv_wallet" == "true" ] && [ "$admin_xpub" == "" ] && [ "$default_xpub" !

if [[ -n "$choice" ]]; then
admin_xpub=$choice
default_xpub="false"
else
default_xpub="true"
fi
print_debug "admin_xpub: $admin_xpub"
print_debug "default_xpub: $default_xpub"
fi

if [ "$spv_wallet" != "true" ] && [ "$wallet_backend" == "true" ] && [ "$admin_xpriv" == "" ]; then
ask_for_value "Define admin xPriv (Leave empty to use the default one)" 'xprv'

if [[ -n "$choice" ]]; then
admin_xpriv=$choice
default_xpub="false"
else
default_xpub="true"
fi
print_debug "default_xpub: $default_xpub"
print_debug "admin_xpriv: $admin_xpriv"
fi

if [ "$wallet_backend" == "true" ] && [ "$admin_xpriv" == "" ] && [ "$default_xpub" != "true" ]; then
ask_for_value "Define admin xPriv (Leave empty to use the default one)" 'xprv'
admin_xpriv=$choice
print_debug "admin_xpriv: $admin_xpriv"
fi

if [ "$admin_panel" == "true" ] && [ "$default_xpub" == "true" ]; then
print_warning "To login to the admin panel, you will need to provide the admin xPriv."
print_warning "You choose to use default admin xPub, so you can use the following xPriv:"
print_warning "$default_xpriv_value"
elif [ "$spv_wallet" == "true" ] && [ "$admin_panel" == "true" ] && [ "$default_xpub" != "true" ]; then
print_warning "To login to the admin panel, you will need to provide the admin xPriv."
print_warning "You choose to use custom admin xPub, therefore ensure you have xPriv for it to use in admin panel"
elif [ "$spv_wallet" != "true" ] && [ "$admin_panel" == "true" ] && [ "$default_xpub" != "true" ]; then
print_warning "To login to the admin panel, you will need to provide the admin xPriv."
print_warning "You choose to not start spv-wallet, therefore ensure you have xPriv for it to use in admin panel"
print_warning "By default it should be:"
print_warning "$default_xpriv_value"
fi

if [ "$paymail_domain" == "" ] && { [ "$wallet_backend" == "true" ] || [ "$wallet_frontend" == "true" ] || [ "$spv_wallet" == "true" ]; }; then
ask_for_value "What PayMail domain should be configured in applications?"
paymail_domain=$choice
print_debug "paymail_domain: $paymail_domain"
fi

if [ "$expose" == "" ]; then
ask_for_yes_or_no "Do you want to expose the services on $paymail_domain and its subdomains?" "false"
expose="$choice"
print_debug "expose: $expose"
fi

if [ "$expose" == "true" ]; then
print_warning "Following domains/subdomains should be registered"
print_warning "$paymail_domain => where the spv-wallet will be running"
print_warning "wallet.$paymail_domain => where the web frontend will be running"
print_warning "api.$paymail_domain => where the web backend will be running"
print_warning "headers.$paymail_domain => where the block-headers-service will be running"
print_warning "admin.$paymail_domain => where the admin panel will be running"
fi

if [ "$background" == "" ]; then
ask_for_yes_or_no "Do you want to run everything in the background?" "false"
background="$choice"
Expand All @@ -418,10 +489,25 @@ save_to 'RUN_BLOCK_HEADERS_SERVICE' block_headers_service
save_to 'RUN_PAYMAIL_DOMAIN' paymail_domain
save_to 'RUN_SPVWALLET_FRONTEND' wallet_frontend
save_to 'RUN_SPVWALLET_BACKEND' wallet_backend
save_to 'RUN_EXPOSED' expose
save_to 'RUN_IN_BACKGROUND' background
save_to 'RUN_WITH_DEFAULT_XPUB' default_xpub
save_to 'SPVWALLET_AUTH_ADMIN_KEY' admin_xpub
save_to 'SPVWALLET_ADMIN_XPRIV' admin_xpriv
if [ "$admin_panel" == "true" ] && [ "$default_xpub" == "true" ]; then
{
echo "# Use the following xPriv to login to the admin panel:" >> ".env.config"
echo "# $default_xpriv_value"
} >> ".env.config"
elif [ "$spv_wallet" != "true" ] && [ "$admin_panel" == "true" ] && [ "$default_xpub" != "true" ]; then
{
echo "# You choose to not start spv-wallet, to log in to admin you need admin xPriv"
echo "# By default it is:"
echo "# $default_xpriv_value"
} >> ".env.config"
fi

save_to 'RUN_ADMIN_PANEL' admin_panel
case $database in
postgresql)
save_value 'SPVWALLET_DB_SQL_HOST' "wallet-postgresql"
Expand Down Expand Up @@ -452,6 +538,13 @@ if [ "$block_headers_service" == "true" ]; then
else
save_value 'SPVWALLET_PAYMAIL_BEEF_BLOCK_HEADER_SERVICE_URL' "http://host.docker.internal:8080/api/v1/chain/merkleroot/verify"
fi

if [ "$expose" == "true" ]; then
save_value 'HTTP_SERVER_CORS_ALLOWEDDOMAINS' "https://wallet.$paymail_domain"
else
save_value 'HTTP_SERVER_CORS_ALLOWEDDOMAINS' "http://localhost:3002"
fi

print_debug "Exporting RUN_PAYMAIL_DOMAIN environment variable"
export RUN_PAYMAIL_DOMAIN="$paymail_domain"

Expand Down Expand Up @@ -498,6 +591,29 @@ if [ "$wallet_frontend" == "true" ]; then
servicesToHideLogs+=("wallet-frontend")
fi

if [ "$expose" == "true" ]; then
servicesToRun+=("wallet-gateway")
if [ "$debug" != "true" ]; then
servicesToHideLogs+=("wallet-gateway")
fi
export RUN_API_DOMAIN="api.$paymail_domain"
export RUN_SPVWALLET_DOMAIN="$paymail_domain"
export RUN_SECURED_PROTOCOL_SUFFIX="s"
else
export RUN_API_DOMAIN="localhost:8180"
export RUN_SPVWALLET_DOMAIN="localhost:3003"
export RUN_SECURED_PROTOCOL_SUFFIX=""
fi
print_debug "Exporting following variables:"
print_debug " RUN_API_DOMAIN=$RUN_API_DOMAIN"
print_debug " RUN_SPVWALLET_DOMAIN=$RUN_SPVWALLET_DOMAIN"
print_debug " RUN_SECURED_PROTOCOL_SUFFIX=$RUN_SECURED_PROTOCOL_SUFFIX"

if [ "$admin_panel" == "true" ]; then
servicesToRun+=("spv-wallet-admin")
servicesToHideLogs+=("spv-wallet-admin")
fi

if [ "$background" == "true" ]; then
additionalFlags+=("-d")
fi
Expand Down

0 comments on commit 8753c8f

Please sign in to comment.