Imrove control flow.

This commit is contained in:
Derek Smith 2023-04-04 11:08:22 -04:00
parent 29038cfb0a
commit 4c214cf7ad
Signed by: farscapian
GPG Key ID: B443E530A14E1C90
8 changed files with 124 additions and 91 deletions

View File

@ -5,13 +5,7 @@ cd "$(dirname "$0")"
export DOCKER_HOST="ssh://ubuntu@$BTCPAY_FQDN" export DOCKER_HOST="ssh://ubuntu@$BTCPAY_FQDN"
# run the btcpay setup script if it hasn't been done before. ./stub_btcpay_setup.sh
if ssh "$BTCPAY_FQDN" "[ ! -f "$REMOTE_DATA_PATH/btcpay.complete" ]"; then
./stub_btcpay_setup.sh
BACKUP_BTCPAY=false
fi
RUN_SERVICES=true
# we will re-run the btcpayserver provisioning scripts if directed to do so. # we will re-run the btcpayserver provisioning scripts if directed to do so.
# if an update does occur, we grab another backup. # if an update does occur, we grab another backup.
@ -49,7 +43,7 @@ if [ "$BACKUP_BTCPAY" = true ]; then
./backup_btcpay.sh ./backup_btcpay.sh
fi fi
if [ "$RUN_SERVICES" = true ] && [ "$STOP_SERVICES" = false ]; then if [ "$STOP_SERVICES" = false ]; then
# The default is to resume services, though admin may want to keep services off (eg., for a migration) # The default is to resume services, though admin may want to keep services off (eg., for a migration)
# we bring the services back up by default. # we bring the services back up by default.
ssh "$FQDN" "bash -c $BTCPAY_SERVER_APPPATH/btcpay-up.sh" ssh "$FQDN" "bash -c $BTCPAY_SERVER_APPPATH/btcpay-up.sh"

View File

@ -3,6 +3,8 @@
set -e set -e
cd "$(dirname "$0")" cd "$(dirname "$0")"
# default is for regtest # default is for regtest
CLIGHTNING_WEBSOCKET_PORT=9736 CLIGHTNING_WEBSOCKET_PORT=9736
if [ "$BITCOIN_CHAIN" = testnet ]; then if [ "$BITCOIN_CHAIN" = testnet ]; then
@ -13,6 +15,7 @@ fi
export CLIGHTNING_WEBSOCKET_PORT="$CLIGHTNING_WEBSOCKET_PORT" export CLIGHTNING_WEBSOCKET_PORT="$CLIGHTNING_WEBSOCKET_PORT"
# export BTCPAY_FASTSYNC_ARCHIVE_FILENAME="utxo-snapshot-bitcoin-testnet-1445586.tar" # export BTCPAY_FASTSYNC_ARCHIVE_FILENAME="utxo-snapshot-bitcoin-testnet-1445586.tar"
# BTCPAY_REMOTE_RESTORE_PATH="/var/lib/docker/volumes/generated_bitcoin_datadir/_data" # BTCPAY_REMOTE_RESTORE_PATH="/var/lib/docker/volumes/generated_bitcoin_datadir/_data"

View File

@ -315,6 +315,16 @@ if ! lxc image list --format csv | grep -q "$DOCKER_BASE_IMAGE_NAME"; then
fi fi
for VIRTUAL_MACHINE in www btcpayserver; do for VIRTUAL_MACHINE in www btcpayserver; do
if [ "$VIRTUAL_MACHINE" = btcpayserver ] && [ "$SKIP_BTCPAY" = true ]; then
continue
fi
if [ "$VIRTUAL_MACHINE" = www ] && [ "$SKIP_WWW" = true ]; then
continue
fi
export VIRTUAL_MACHINE="$VIRTUAL_MACHINE" export VIRTUAL_MACHINE="$VIRTUAL_MACHINE"
FQDN= FQDN=

View File

@ -130,6 +130,13 @@ if [ "$RESTART_FRONT_END" = true ]; then
./backup_path.sh ./backup_path.sh
fi fi
done done
else
exit 0
fi
# build the clams docker image
if [ "$BUILD_CLAMS" = true ]; then
./clams/build.sh
fi fi
# nginx gets deployed first since it "owns" the docker networks of downstream services. # nginx gets deployed first since it "owns" the docker networks of downstream services.
@ -141,6 +148,8 @@ fi
./stub/gitea_yml.sh ./stub/gitea_yml.sh
./stub/nostr_yml.sh ./stub/nostr_yml.sh
# # start a browser session; point it to port 80 to ensure HTTPS redirect. # # start a browser session; point it to port 80 to ensure HTTPS redirect.
# # WWW_FQDN is in our certificate, so we resolve to that. # # WWW_FQDN is in our certificate, so we resolve to that.
# wait-for-it -t 320 "$WWW_FQDN:80" # wait-for-it -t 320 "$WWW_FQDN:80"

View File

@ -46,3 +46,10 @@ for DOMAIN_NAME in ${DOMAIN_LIST//,/ }; do
done done
done done
done done
# remove the nginx stack
if docker stack list --format "{{.Name}}" | grep -q reverse-proxy; then
docker stack rm reverse-proxy
sleep 5
fi

View File

@ -3,6 +3,7 @@
set -eu set -eu
cd "$(dirname "$0")" cd "$(dirname "$0")"
DEPLOY_STACK=false
for DOMAIN_NAME in ${DOMAIN_LIST//,/ }; do for DOMAIN_NAME in ${DOMAIN_LIST//,/ }; do
export DOMAIN_NAME="$DOMAIN_NAME" export DOMAIN_NAME="$DOMAIN_NAME"
export SITE_PATH="$SITES_PATH/$DOMAIN_NAME" export SITE_PATH="$SITES_PATH/$DOMAIN_NAME"
@ -12,6 +13,10 @@ for DOMAIN_NAME in ${DOMAIN_LIST//,/ }; do
source "$SITE_PATH/site.conf" source "$SITE_PATH/site.conf"
source ../../domain_env.sh source ../../domain_env.sh
if [ "$DEPLOY_GHOST" = true ]; then
DEPLOY_STACK=true
fi
# for each language specified in the site.conf, we spawn a separate ghost container # for each language specified in the site.conf, we spawn a separate ghost container
# at https://www.domain.com/$LANGUAGE_CODE # at https://www.domain.com/$LANGUAGE_CODE
for LANGUAGE_CODE in ${SITE_LANGUAGE_CODES//,/ }; do for LANGUAGE_CODE in ${SITE_LANGUAGE_CODES//,/ }; do
@ -103,7 +108,7 @@ EOL
EOL EOL
fi fi
if [ "$STOP_SERVICES" = false ]; then if [ "$DEPLOY_STACK" = true ] && [ "$STOP_SERVICES" = false ]; then
docker stack deploy -c "$DOCKER_YAML_PATH" "$DOMAIN_IDENTIFIER-ghost-$LANGUAGE_CODE" docker stack deploy -c "$DOCKER_YAML_PATH" "$DOMAIN_IDENTIFIER-ghost-$LANGUAGE_CODE"
sleep 2 sleep 2
fi fi

View File

@ -307,17 +307,19 @@ EOL
EOL EOL
fi fi
echo " # set up cache paths for nginx caching" >>"$NGINX_CONF_PATH"
for LANGUAGE_CODE in ${SITE_LANGUAGE_CODES//,/ }; do if [ "$DEPLOY_GHOST" = true ]; then
STACK_NAME="$DOMAIN_IDENTIFIER-$LANGUAGE_CODE" echo " # set up cache paths for nginx caching" >>"$NGINX_CONF_PATH"
cat >>"$NGINX_CONF_PATH" <<EOL for LANGUAGE_CODE in ${SITE_LANGUAGE_CODES//,/ }; do
STACK_NAME="$DOMAIN_IDENTIFIER-$LANGUAGE_CODE"
cat >>"$NGINX_CONF_PATH" <<EOL
proxy_cache_path /tmp/${STACK_NAME} levels=1:2 keys_zone=${STACK_NAME}:600m max_size=100m inactive=24h; proxy_cache_path /tmp/${STACK_NAME} levels=1:2 keys_zone=${STACK_NAME}:600m max_size=100m inactive=24h;
EOL EOL
done done
# the open server block for the HTTPS listener for ghost # the open server block for the HTTPS listener for ghost
cat >>"$NGINX_CONF_PATH" <<EOL cat >>"$NGINX_CONF_PATH" <<EOL
# Main HTTPS listener for https://${WWW_FQDN} # Main HTTPS listener for https://${WWW_FQDN}
server { server {
@ -337,20 +339,20 @@ EOL
EOL EOL
for LANGUAGE_CODE in ${SITE_LANGUAGE_CODES//,/ }; do for LANGUAGE_CODE in ${SITE_LANGUAGE_CODES//,/ }; do
STACK_NAME="$DOMAIN_IDENTIFIER-$LANGUAGE_CODE" STACK_NAME="$DOMAIN_IDENTIFIER-$LANGUAGE_CODE"
if [ "$LANGUAGE_CODE" = en ]; then if [ "$LANGUAGE_CODE" = en ]; then
cat >>"$NGINX_CONF_PATH" <<EOL cat >>"$NGINX_CONF_PATH" <<EOL
location ~ ^/(ghost/|p/|private/) { location ~ ^/(ghost/|p/|private/) {
EOL EOL
else else
cat >>"$NGINX_CONF_PATH" <<EOL cat >>"$NGINX_CONF_PATH" <<EOL
location ~ ^/${LANGUAGE_CODE}/(ghost/|p/|private/) { location ~ ^/${LANGUAGE_CODE}/(ghost/|p/|private/) {
EOL EOL
fi fi
cat >>"$NGINX_CONF_PATH" <<EOL cat >>"$NGINX_CONF_PATH" <<EOL
proxy_set_header X-Real-IP \$remote_addr; proxy_set_header X-Real-IP \$remote_addr;
proxy_set_header Host \$host; proxy_set_header Host \$host;
proxy_set_header X-Forwarded-For \$proxy_add_x_forwarded_for; proxy_set_header X-Forwarded-For \$proxy_add_x_forwarded_for;
@ -361,22 +363,22 @@ EOL
EOL EOL
done done
ROOT_SITE_LANGUAGE_CODES="$SITE_LANGUAGE_CODES" ROOT_SITE_LANGUAGE_CODES="$SITE_LANGUAGE_CODES"
for LANGUAGE_CODE in ${ROOT_SITE_LANGUAGE_CODES//,/ }; do for LANGUAGE_CODE in ${ROOT_SITE_LANGUAGE_CODES//,/ }; do
cat >>"$NGINX_CONF_PATH" <<EOL cat >>"$NGINX_CONF_PATH" <<EOL
# Location block to back https://${WWW_FQDN}/${LANGUAGE_CODE} or https://${WWW_FQDN}/ if english. # Location block to back https://${WWW_FQDN}/${LANGUAGE_CODE} or https://${WWW_FQDN}/ if english.
EOL EOL
if [ "$LANGUAGE_CODE" = en ]; then if [ "$LANGUAGE_CODE" = en ]; then
cat >>"$NGINX_CONF_PATH" <<EOL cat >>"$NGINX_CONF_PATH" <<EOL
location / { location / {
EOL EOL
if (( "$LANGUAGE_CODE_COUNT" > 1 )); then if (( "$LANGUAGE_CODE_COUNT" > 1 )); then
# we only need this clause if we know there is more than once lanuage being rendered. # we only need this clause if we know there is more than once lanuage being rendered.
cat >>"$NGINX_CONF_PATH" <<EOL cat >>"$NGINX_CONF_PATH" <<EOL
# Redirect the user to the correct language using the map above. # Redirect the user to the correct language using the map above.
if ( \$http_accept_language !~* '^en(.*)\$' ) { if ( \$http_accept_language !~* '^en(.*)\$' ) {
#rewrite (.*) \$1/\$lang; #rewrite (.*) \$1/\$lang;
@ -384,15 +386,15 @@ EOL
} }
EOL EOL
fi fi
else else
cat >>"$NGINX_CONF_PATH" <<EOL cat >>"$NGINX_CONF_PATH" <<EOL
location /${LANGUAGE_CODE} { location /${LANGUAGE_CODE} {
EOL EOL
fi fi
cat >>"$NGINX_CONF_PATH" <<EOL cat >>"$NGINX_CONF_PATH" <<EOL
proxy_set_header X-Real-IP \$remote_addr; proxy_set_header X-Real-IP \$remote_addr;
proxy_set_header Host \$host; proxy_set_header Host \$host;
@ -430,7 +432,7 @@ EOL
EOL EOL
done done
# this is the closing server block for the ghost HTTPS segment # this is the closing server block for the ghost HTTPS segment
cat >>"$NGINX_CONF_PATH" <<EOL cat >>"$NGINX_CONF_PATH" <<EOL
@ -438,7 +440,7 @@ EOL
} }
EOL EOL
fi
if [ "$DEPLOY_NEXTCLOUD" = true ]; then if [ "$DEPLOY_NEXTCLOUD" = true ]; then
cat >>"$NGINX_CONF_PATH" <<EOL cat >>"$NGINX_CONF_PATH" <<EOL

View File

@ -18,57 +18,60 @@ services:
networks: networks:
EOL EOL
for DOMAIN_NAME in ${DOMAIN_LIST//,/ }; do for DOMAIN_NAME in ${DOMAIN_LIST//,/ }; do
export DOMAIN_NAME="$DOMAIN_NAME" export DOMAIN_NAME="$DOMAIN_NAME"
export SITE_PATH="$SITES_PATH/$DOMAIN_NAME" export SITE_PATH="$SITES_PATH/$DOMAIN_NAME"
# source the site path so we know what features it has. # source the site path so we know what features it has.
source ../../../../defaults.sh source ../../../../defaults.sh
source "$SITE_PATH/site.conf" source "$SITE_PATH/site.conf"
source ../../domain_env.sh source ../../domain_env.sh
for LANGUAGE_CODE in ${SITE_LANGUAGE_CODES//,/ }; do for LANGUAGE_CODE in ${SITE_LANGUAGE_CODES//,/ }; do
# We create another ghost instance under / # We create another ghost instance under /
if [ "$DEPLOY_GHOST" = true ]; then
cat >> "$DOCKER_YAML_PATH" <<EOL cat >> "$DOCKER_YAML_PATH" <<EOL
- ghostnet-$DOMAIN_IDENTIFIER-$LANGUAGE_CODE - ghostnet-$DOMAIN_IDENTIFIER-$LANGUAGE_CODE
EOL EOL
fi
if [ "$LANGUAGE_CODE" = en ]; then if [ "$LANGUAGE_CODE" = en ]; then
if [ "$DEPLOY_GITEA" = "true" ]; then if [ "$DEPLOY_GITEA" = "true" ]; then
cat >> "$DOCKER_YAML_PATH" <<EOL cat >> "$DOCKER_YAML_PATH" <<EOL
- giteanet-$DOMAIN_IDENTIFIER-en - giteanet-$DOMAIN_IDENTIFIER-en
EOL EOL
fi fi
if [ "$DEPLOY_NEXTCLOUD" = "true" ]; then if [ "$DEPLOY_NEXTCLOUD" = "true" ]; then
cat >> "$DOCKER_YAML_PATH" <<EOL cat >> "$DOCKER_YAML_PATH" <<EOL
- nextcloudnet-$DOMAIN_IDENTIFIER-en - nextcloudnet-$DOMAIN_IDENTIFIER-en
EOL EOL
fi fi
if [ "$DEPLOY_NOSTR" = true ]; then if [ "$DEPLOY_NOSTR" = true ]; then
cat >> "$DOCKER_YAML_PATH" <<EOL cat >> "$DOCKER_YAML_PATH" <<EOL
- nostrnet-$DOMAIN_IDENTIFIER-en - nostrnet-$DOMAIN_IDENTIFIER-en
EOL EOL
fi fi
fi fi
done
done done
cat >> "$DOCKER_YAML_PATH" <<EOL done
cat >> "$DOCKER_YAML_PATH" <<EOL
volumes: volumes:
- ${REMOTE_DATA_PATH}/letsencrypt:/etc/letsencrypt:ro - ${REMOTE_DATA_PATH_LETSENCRYPT}:/etc/letsencrypt:ro
EOL EOL
if [ "$DEPLOY_CLAMS" = true ]; then if [ "$DEPLOY_CLAMS" = true ]; then
cat >> "$DOCKER_YAML_PATH" <<EOL cat >> "$DOCKER_YAML_PATH" <<EOL
- ${REMOTE_CLAMS_PATH}:/browser-app - ${REMOTE_CLAMS_PATH}:/browser-app
EOL EOL
fi fi
cat >> "$DOCKER_YAML_PATH" <<EOL cat >> "$DOCKER_YAML_PATH" <<EOL
configs: configs:
- source: nginx-config - source: nginx-config
target: /etc/nginx/nginx.conf target: /etc/nginx/nginx.conf
@ -85,46 +88,43 @@ EOL
################ NETWORKS SECTION ################ NETWORKS SECTION
cat >> "$DOCKER_YAML_PATH" <<EOL
cat >> "$DOCKER_YAML_PATH" <<EOL
networks: networks:
EOL EOL
for DOMAIN_NAME in ${DOMAIN_LIST//,/ }; do
export DOMAIN_NAME="$DOMAIN_NAME"
export SITE_PATH="$SITES_PATH/$DOMAIN_NAME"
for DOMAIN_NAME in ${DOMAIN_LIST//,/ }; do # source the site path so we know what features it has.
export DOMAIN_NAME="$DOMAIN_NAME" source ../../../../defaults.sh
export SITE_PATH="$SITES_PATH/$DOMAIN_NAME" source "$SITE_PATH/site.conf"
source ../../domain_env.sh
# source the site path so we know what features it has. # for each language specified in the site.conf, we spawn a separate ghost container
source ../../../../defaults.sh # at https://www.domain.com/$LANGUAGE_CODE
source "$SITE_PATH/site.conf" for LANGUAGE_CODE in ${SITE_LANGUAGE_CODES//,/ }; do
source ../../domain_env.sh if [ "$DEPLOY_GHOST" = true ]; then
# for each language specified in the site.conf, we spawn a separate ghost container
# at https://www.domain.com/$LANGUAGE_CODE
for LANGUAGE_CODE in ${SITE_LANGUAGE_CODES//,/ }; do
cat >> "$DOCKER_YAML_PATH" <<EOL cat >> "$DOCKER_YAML_PATH" <<EOL
ghostnet-$DOMAIN_IDENTIFIER-$LANGUAGE_CODE: ghostnet-$DOMAIN_IDENTIFIER-$LANGUAGE_CODE:
attachable: true attachable: true
EOL EOL
fi
if [ "$LANGUAGE_CODE" = en ]; then if [ "$LANGUAGE_CODE" = en ]; then
if [ "$DEPLOY_GITEA" = true ]; then if [ "$DEPLOY_GITEA" = true ]; then
cat >> "$DOCKER_YAML_PATH" <<EOL cat >> "$DOCKER_YAML_PATH" <<EOL
giteanet-$DOMAIN_IDENTIFIER-en: giteanet-$DOMAIN_IDENTIFIER-en:
attachable: true attachable: true
EOL EOL
fi fi
if [ "$DEPLOY_NEXTCLOUD" = true ]; then if [ "$DEPLOY_NEXTCLOUD" = true ]; then
cat >> "$DOCKER_YAML_PATH" <<EOL cat >> "$DOCKER_YAML_PATH" <<EOL
nextcloudnet-$DOMAIN_IDENTIFIER-en: nextcloudnet-$DOMAIN_IDENTIFIER-en:
attachable: true attachable: true
EOL EOL
fi fi
if [ "$DEPLOY_NOSTR" = true ]; then if [ "$DEPLOY_NOSTR" = true ]; then
cat >> "$DOCKER_YAML_PATH" <<EOL cat >> "$DOCKER_YAML_PATH" <<EOL
@ -133,9 +133,12 @@ EOL
EOL EOL
fi fi
fi
done
done
if [ "$STOP_SERVICES" = false ]; then if [ "$STOP_SERVICES" = false ]; then
docker stack deploy -c "$DOCKER_YAML_PATH" "reverse-proxy" docker stack deploy -c "$DOCKER_YAML_PATH" reverse-proxy
# iterate over all our domains and create the nginx config file. # iterate over all our domains and create the nginx config file.
sleep 1 sleep 3
fi fi