./priv/roles/Backend.sh in stacco-0.1.68 vs ./priv/roles/Backend.sh in stacco-0.1.70
- old
+ new
@@ -1,11 +1,8 @@
-frontend_image="bexio/bexng-frontend:${FRONTEND_IMAGE_TAG}"
-backend_image="bexio/bexng:${BACKEND_IMAGE_TAG}"
-
-# create bexng file-based config
+step "setting up /target directory for bexbackend"
mkdir -p /etc/bexng
-echo "${DOMAIN}" > /etc/bexng/name
+
cat >"/etc/bexng/secrets.exs" <<EOF
[
authy_url: "${AUTHY_URL}",
authy_key: "${AUTHY_KEY}",
@@ -30,67 +27,144 @@
]}
]
]
EOF
-cat >/usr/local/sbin/bexng-before-start <<EOF
-docker pull bexio/postgresql:latest && \
-docker run --rm \
- \$(docker-utils container-links-for -w 'postgresql') \
- -e "DB_ADMIN_USERNAME=\${DB_ADMIN_USERNAME}" \
- -e "DB_ADMIN_PASSWORD=\${DB_ADMIN_PASSWORD}" \
- 'bexio/postgresql:latest' \
- db:create 'bexng' "\${BEXNG_DB_SECRET}"
-EOF
-chmod a+x /usr/local/sbin/bexng-before-start
+step_done
-echo "starting docker operations"
-gem update docker-utils
+step "updating docker basefiles"
+gem update 'docker-utils' --no-rdoc --no-ri
+docker pull 'bexio/base:latest' >/dev/null 2>&1
+docker pull 'bexio/toolchain:elixir-upgrade' >/dev/null 2>&1
+step_done
-docker pull tianon/true:latest
-docker pull bexio/base:latest
-docker pull bexio/amb:latest
-docker pull bexio/bitcoind:latest
-docker pull bexio/armoryd:latest
-docker pull bexio/postgresql:latest
-docker pull "${backend_image}"
-docker pull "${frontend_image}"
+start_bitcoind() {
if [ "${WALLET_NETWORK}" = "testnet3" ]; then
- docker run --name='bitcoind-data' --volumes-from='tbtc-data' tianon/true:latest
+ bitcoin_data_volume='tbtc-data'
else
- docker run --name='bitcoind-data' --volumes-from='btc-data' tianon/true:latest
+ bitcoin_data_volume='btc-data'
fi
-docker-utils define-ambassador-service "postgresql" \
+docker pull 'scratch:latest' >/dev/null 2>&1
+
+docker run \
+ --name='bitcoind-data' \
+ --volumes-from="${bitcoin_data_volume}" \
+ --entrypoint 'volume' \
+ 'scratch:latest' || :
+
+step "starting bitcoind"
+
+docker pull 'bexio/bitcoind:latest' >/dev/null 2>&1
+
+docker run -d --restart=always \
+ --name='bitcoind' \
+ -e "NETWORK=${WALLET_NETWORK}" \
+ --volumes-from='bitcoind-data' \
+ 'bexio/bitcoind:latest'
+
+step_done
+}
+
+
+start_db() {
+docker pull 'bexio/amb:latest' >/dev/null 2>&1
+
+step "starting db"
+
+docker run -d \
+ --name='rds-postgres-1' \
+ "bexio/amb:latest" \
"${DB_HOST}" "${DB_PORT}"
-docker-utils define-service "bexio/bitcoind" \
- -e "NETWORK=${WALLET_NETWORK}"
+docker-utils block-until-port-open 'rds-postgres-1' '5432'
-docker-utils define-service "bexio/armoryd" \
- -e "NETWORK=${WALLET_NETWORK}"
+docker pull 'bexio/pgproxy:latest' >/dev/null 2>&1
-docker-utils define-service "${backend_image}" \
- --dependency "bitcoind" \
- --dependency "postgresql" \
- --dependency "armoryd" \
- --before-start "$(cat /usr/local/sbin/bexng-before-start)" \
+docker run --rm -i -t \
+ --name='bexng-db-init-task' \
+ --link="rds-postgres-1:postgresql" \
+ -e "NO_PROXY=1" \
+ "bexio/pgproxy:latest" \
+ "${DB_ADMIN_USERNAME}" "${DB_ADMIN_PASSWORD}" \
+ 'bexng' "${BEXNG_DB_SECRET}"
+
+docker kill 'rds-postgres-1'
+docker rm 'rds-postgres-1'
+
+docker run -d --restart=always \
+ --name='rds-postgres' \
+ "bexio/amb:latest" \
+ "${DB_HOST}" "${DB_PORT}"
+
+step_done
+
+
+}
+
+
+start_armoryd() {
+step "starting armoryd"
+
+docker pull 'bexio/armoryd:latest' >/dev/null 2>&1
+
+docker run -d --restart=always \
+ --name="armoryd" \
+ -e "NETWORK=${WALLET_NETWORK}" \
+ "bexio/armoryd:latest"
+
+step_done
+}
+
+start_bexbackend() {
+docker-utils block-until-port-open 'rds-postgres' '5432'
+docker-utils block-until-port-open 'bitcoind' '8333'
+docker-utils block-until-port-open 'armoryd' '80'
+
+step "starting bexbackend"
+
+docker pull "bexio/bexng:${BACKEND_IMAGE_TAG}" >/dev/null 2>&1
+
+export DEPLOY_TARGET="${DOMAIN}"
+
+docker run -d --restart=always \
+ --name='bexbackend' \
+ --link='rds-postgres:postgresql' \
+ --link='bitcoind:bitcoind' \
+ --link='armoryd:armoryd' \
--volume "/etc/bexng:/target" \
--publish="51607:51607" \
- -e "DB_SECRET=${BEXNG_DB_SECRET}" \
- -e "DEPLOY_TARGET=${DOMAIN}"
+ -e "BEXNG_DB_SECRET" \
+ -e "DEPLOY_TARGET" \
+ "bexio/bexng:${BACKEND_IMAGE_TAG}"
-docker-utils define-service "${frontend_image}" \
- -e "BEXNG_PORT_51607_TCP=tcp://backend:51607" \
- --link="bexng:backend" \
- --publish="80:8080"
+step_done
+}
+start_bexfrontend() {
+docker-utils block-until-port-open 'bexbackend' '51607'
-echo "starting docker-container services..."
-start bitcoind
-start armoryd
-start postgresql
-start bexng
-start bexng-frontend
+step "starting bexfrontend"
+
+docker pull "bexio/frontend:${FRONTEND_IMAGE_TAG}" >/dev/null 2>&1
+
+docker run -d --restart=always \
+ --name='bexfrontend' \
+ --link="bexbackend:backend" \
+ -e 'BEXNG_PORT_51608_TCP=tcp://backend:51608' \
+ --publish='80:8081' \
+ "bexio/frontend:${FRONTEND_IMAGE_TAG}"
+
+step_done
+}
+
+
+start_bitcoind &
+start_db &
+start_armoryd &
+start_bexbackend &
+start_bexfrontend &
+wait
+