Deployment improvements.

This commit is contained in:
Derek Smith 2023-03-09 09:53:07 -05:00
parent 2855218b28
commit fbc6e2b6e5
Signed by: farscapian
GPG Key ID: B443E530A14E1C90
6 changed files with 42 additions and 29 deletions

View File

@ -1,9 +1,9 @@
#!/bin/bash #!/bin/bash
set -eu set -exu
cd "$(dirname "$0")" cd "$(dirname "$0")"
./stub_lxc_profile.sh "$BASE_IMAGE_VM_NAME" bash -c "./stub_lxc_profile.sh --lxd-hostname=$BASE_IMAGE_VM_NAME"
# let's download our base image. # let's download our base image.
if ! lxc image list --format csv --columns l | grep -q "$UBUNTU_BASE_IMAGE_NAME"; then if ! lxc image list --format csv --columns l | grep -q "$UBUNTU_BASE_IMAGE_NAME"; then

View File

@ -371,22 +371,19 @@ for VIRTUAL_MACHINE in www btcpayserver; do
export VPS_HOSTNAME="$VPS_HOSTNAME" export VPS_HOSTNAME="$VPS_HOSTNAME"
export FQDN="$VPS_HOSTNAME.$DOMAIN_NAME" export FQDN="$VPS_HOSTNAME.$DOMAIN_NAME"
DDNS_HOST=
if [ "$VIRTUAL_MACHINE" = www ]; then if [ "$VIRTUAL_MACHINE" = www ]; then
if [ "$SKIP_WWW" = true ]; then if [ "$SKIP_WWW" = true ]; then
echo "INFO: Skipping WWW due to command line argument." echo "INFO: Skipping WWW due to command line argument."
continue continue
fi fi
FQDN="$WWW_HOSTNAME.$DOMAIN_NAME"
VPS_HOSTNAME="$WWW_HOSTNAME" VPS_HOSTNAME="$WWW_HOSTNAME"
MAC_ADDRESS_TO_PROVISION="$WWW_SERVER_MAC_ADDRESS" MAC_ADDRESS_TO_PROVISION="$WWW_SERVER_MAC_ADDRESS"
DDNS_HOST="$WWW_HOSTNAME"
ROOT_DISK_SIZE_GB="$((ROOT_DISK_SIZE_GB + NEXTCLOUD_SPACE_GB))" ROOT_DISK_SIZE_GB="$((ROOT_DISK_SIZE_GB + NEXTCLOUD_SPACE_GB))"
elif [ "$VIRTUAL_MACHINE" = btcpayserver ] || [ "$SKIP_BTCPAY" = true ]; then elif [ "$VIRTUAL_MACHINE" = btcpayserver ] || [ "$SKIP_BTCPAY" = true ]; then
FQDN="$BTCPAY_HOSTNAME.$DOMAIN_NAME"
DDNS_HOST="$BTCPAY_HOSTNAME"
VPS_HOSTNAME="$BTCPAY_HOSTNAME" VPS_HOSTNAME="$BTCPAY_HOSTNAME"
MAC_ADDRESS_TO_PROVISION="$BTCPAYSERVER_MAC_ADDRESS" MAC_ADDRESS_TO_PROVISION="$BTCPAYSERVER_MAC_ADDRESS"
if [ "$BITCOIN_CHAIN" = mainnet ]; then if [ "$BITCOIN_CHAIN" = mainnet ]; then
@ -396,21 +393,19 @@ for VIRTUAL_MACHINE in www btcpayserver; do
fi fi
elif [ "$VIRTUAL_MACHINE" = "$BASE_IMAGE_VM_NAME" ]; then elif [ "$VIRTUAL_MACHINE" = "$BASE_IMAGE_VM_NAME" ]; then
DDNS_HOST="$BASE_IMAGE_VM_NAME" export FQDN="$BASE_IMAGE_VM_NAME"
ROOT_DISK_SIZE_GB=8 ROOT_DISK_SIZE_GB=8
else else
echo "ERROR: VIRTUAL_MACHINE not within allowable bounds." echo "ERROR: VIRTUAL_MACHINE not within allowable bounds."
exit exit
fi fi
export DDNS_HOST="$DDNS_HOST" export FQDN="$FQDN"
export FQDN="$DDNS_HOST.$DOMAIN_NAME"
export LXD_VM_NAME="${FQDN//./-}" export LXD_VM_NAME="${FQDN//./-}"
export VIRTUAL_MACHINE="$VIRTUAL_MACHINE"
export REMOTE_CERT_DIR="$REMOTE_CERT_BASE_DIR/$FQDN" export REMOTE_CERT_DIR="$REMOTE_CERT_BASE_DIR/$FQDN"
export MAC_ADDRESS_TO_PROVISION="$MAC_ADDRESS_TO_PROVISION" export MAC_ADDRESS_TO_PROVISION="$MAC_ADDRESS_TO_PROVISION"
./deploy_vms.sh ./deploy_vm.sh
if [ "$VIRTUAL_MACHINE" = www ]; then if [ "$VIRTUAL_MACHINE" = www ]; then
# this tells our local docker client to target the remote endpoint via SSH # this tells our local docker client to target the remote endpoint via SSH

View File

@ -30,7 +30,7 @@ if ! lxc list --format csv | grep -q "$LXD_VM_NAME"; then
exit 1 exit 1
fi fi
./stub_lxc_profile.sh "$LXD_VM_NAME" bash -c "./stub_lxc_profile.sh --vm=$VIRTUAL_MACHINE --lxd-hostname=$LXD_VM_NAME"
# now let's create a new VM to work with. # now let's create a new VM to work with.
#lxc init --profile="$LXD_VM_NAME" "$BASE_IMAGE_VM_NAME" "$LXD_VM_NAME" --vm #lxc init --profile="$LXD_VM_NAME" "$BASE_IMAGE_VM_NAME" "$LXD_VM_NAME" --vm
@ -43,7 +43,7 @@ if ! lxc list --format csv | grep -q "$LXD_VM_NAME"; then
lxc start "$LXD_VM_NAME" lxc start "$LXD_VM_NAME"
bash -c "./wait_for_lxc_ip.sh --lxc-name=$LXD_VM_NAME" bash -c "./wait_for_lxc_ip.sh --lxd-name=$LXD_VM_NAME"
fi fi
# scan the remote machine and install it's identity in our SSH known_hosts file. # scan the remote machine and install it's identity in our SSH known_hosts file.

View File

@ -1,9 +1,28 @@
#!/bin/bash #!/bin/bash
set -eu set -exu
cd "$(dirname "$0")" cd "$(dirname "$0")"
LXD_HOSTNAME="${1:-}" VIRTUAL_MACHINE=
LXD_HOSTNAME=
# grab any modifications from the command line.
for i in "$@"; do
case $i in
--lxd-hostname=*)
LXD_HOSTNAME="${i#*=}"
shift
;;
--vm=*)
VIRTUAL_MACHINE="${i#*=}"
shift
;;
*)
echo "Unexpected option: $1"
exit 1
;;
esac
done
# generate the custom cloud-init file. Cloud init installs and configures sshd # generate the custom cloud-init file. Cloud init installs and configures sshd
SSH_AUTHORIZED_KEY=$(<"$SSH_PUBKEY_PATH") SSH_AUTHORIZED_KEY=$(<"$SSH_PUBKEY_PATH")
@ -37,7 +56,8 @@ EOF
fi fi
if [ "$LXD_HOSTNAME" = "$BASE_IMAGE_VM_NAME" ]; then # if VIRTUAL_MACHINE is undefined, then we doing the base image.
if [ -z "$VIRTUAL_MACHINE" ]; then
# this is for the base image only... # this is for the base image only...
cat >> "$YAML_PATH" <<EOF cat >> "$YAML_PATH" <<EOF
user.vendor-data: | user.vendor-data: |
@ -132,7 +152,7 @@ EOF
#- sudo apt-get install -y docker-ce docker-ce-cli containerd.io docker-buildx-plugin docker-compose-plugin #- sudo apt-get install -y docker-ce docker-ce-cli containerd.io docker-buildx-plugin docker-compose-plugin
else else
# all other machines. # all other machines that are not the base image
cat >> "$YAML_PATH" <<EOF cat >> "$YAML_PATH" <<EOF
user.vendor-data: | user.vendor-data: |
#cloud-config #cloud-config
@ -163,7 +183,7 @@ EOF
fi fi
# If we are deploying the www, we attach the vm to the underlay via macvlan. # All profiles get a root disk and cloud-init config.
cat >> "$YAML_PATH" <<EOF cat >> "$YAML_PATH" <<EOF
description: Default LXD profile for ${FILENAME} description: Default LXD profile for ${FILENAME}
devices: devices:
@ -177,9 +197,7 @@ devices:
EOF EOF
# Stub out the network piece for the base image. # Stub out the network piece for the base image.
if [ "$LXD_HOSTNAME" = "$BASE_IMAGE_VM_NAME" ] ; then if [ -z "$VIRTUAL_MACHINE" ]; then
#
cat >> "$YAML_PATH" <<EOF cat >> "$YAML_PATH" <<EOF
enp6s0: enp6s0:
name: enp6s0 name: enp6s0

View File

@ -7,7 +7,7 @@ LXC_INSTANCE_NAME=
# grab any modifications from the command line. # grab any modifications from the command line.
for i in "$@"; do for i in "$@"; do
case $i in case $i in
--lxc-name=*) --lxd-name=*)
LXC_INSTANCE_NAME="${i#*=}" LXC_INSTANCE_NAME="${i#*=}"
shift shift
;; ;;

View File

@ -21,7 +21,7 @@ for DOMAIN_NAME in ${DOMAIN_LIST//,/ }; do
source ../../../../defaults.sh source ../../../../defaults.sh
source "$SITE_PATH/site_definition" source "$SITE_PATH/site_definition"
source ../../domain_env.sh source ../../domain_env.sh
echo "after"
if [ $iteration = 0 ]; then if [ $iteration = 0 ]; then
cat >>"$NGINX_CONF_PATH" <<EOL cat >>"$NGINX_CONF_PATH" <<EOL
events { events {
@ -250,7 +250,7 @@ EOL
# Route everything to the real BTCPay server # Route everything to the real BTCPay server
location / { location / {
# URL of BTCPay Server # URL of BTCPay Server
proxy_pass http://10.139.144.10:80; proxy_pass http://$LXD_VM_NAME.lxd:80;
proxy_set_header Host \$http_host; proxy_set_header Host \$http_host;
proxy_set_header X-Forwarded-Proto \$scheme; proxy_set_header X-Forwarded-Proto \$scheme;
proxy_set_header X-Real-IP \$remote_addr; proxy_set_header X-Real-IP \$remote_addr;