feat: add Docker/OpenTofu deployment and DE/NL routing
This commit is contained in:
Executable
+131
@@ -0,0 +1,131 @@
|
||||
#!/usr/bin/env bash
|
||||
|
||||
set -Eeuo pipefail
|
||||
|
||||
WM_DEPLOY_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")/.." && pwd)"
|
||||
WM_ROOT_DIR="$(cd "$WM_DEPLOY_DIR/.." && pwd)"
|
||||
# shellcheck source=remote-common.sh
|
||||
source "$WM_DEPLOY_DIR/scripts/remote-common.sh"
|
||||
|
||||
server_ipv4=""
|
||||
identity_file=""
|
||||
run_go_live=false
|
||||
|
||||
usage() {
|
||||
cat <<'USAGE'
|
||||
Verwendung:
|
||||
./deploy/scripts/upload-and-deploy.sh [Optionen]
|
||||
|
||||
Optionen:
|
||||
--host IPV4 Server-IP statt `tofu output -raw server_ipv4`
|
||||
--identity DATEI Privater SSH-Key (alternativ WATERMAPS_SSH_KEY)
|
||||
--user BENUTZER SSH-Benutzer; Standard: deploy
|
||||
--go-live Nach dem Deployment sofort den SSL-Livegang versuchen
|
||||
-h, --help Hilfe anzeigen
|
||||
|
||||
Die Datei deploy/.env.production muss lokal vorhanden sein. Sie wird separat
|
||||
mit Dateimodus 0600 übertragen. Terraform-State, .terraform, data,
|
||||
node_modules, lokale Env-Dateien und Git-Metadaten werden ausgeschlossen.
|
||||
USAGE
|
||||
}
|
||||
|
||||
while [[ "$#" -gt 0 ]]; do
|
||||
case "$1" in
|
||||
--host)
|
||||
[[ "$#" -ge 2 ]] || wm_local_die "Wert für --host fehlt."
|
||||
server_ipv4="$2"
|
||||
shift 2
|
||||
;;
|
||||
--identity)
|
||||
[[ "$#" -ge 2 ]] || wm_local_die "Wert für --identity fehlt."
|
||||
identity_file="$2"
|
||||
shift 2
|
||||
;;
|
||||
--user)
|
||||
[[ "$#" -ge 2 ]] || wm_local_die "Wert für --user fehlt."
|
||||
WATERMAPS_SSH_USER="$2"
|
||||
export WATERMAPS_SSH_USER
|
||||
shift 2
|
||||
;;
|
||||
--go-live)
|
||||
run_go_live=true
|
||||
shift
|
||||
;;
|
||||
-h|--help)
|
||||
usage
|
||||
exit 0
|
||||
;;
|
||||
*)
|
||||
wm_local_die "Unbekannte Option: $1"
|
||||
;;
|
||||
esac
|
||||
done
|
||||
|
||||
command -v rsync >/dev/null 2>&1 || wm_local_die "rsync ist lokal nicht installiert."
|
||||
local_env="$WM_DEPLOY_DIR/.env.production"
|
||||
[[ -f "$local_env" ]] ||
|
||||
wm_local_die "Bitte zuerst deploy/.env.production aus der Vorlage erstellen und konfigurieren."
|
||||
|
||||
wm_local_resolve_ssh "$server_ipv4" "$identity_file"
|
||||
wm_local_wait_for_ssh
|
||||
|
||||
remote_prefix=""
|
||||
rsync_path="rsync"
|
||||
if [[ -n "$WM_REMOTE_SUDO" ]]; then
|
||||
remote_prefix="$WM_REMOTE_SUDO "
|
||||
rsync_path="$WM_REMOTE_SUDO rsync"
|
||||
fi
|
||||
|
||||
printf '[watermaps] Warte auf Cloud-init und das persistente Hetzner-Volume.\n'
|
||||
ssh "${WM_SSH_OPTIONS[@]}" "$WM_SSH_TARGET" \
|
||||
"cloud-init status --wait && ${remote_prefix}systemctl start watermaps-volume-setup.service && mountpoint --quiet /srv/watermaps-data"
|
||||
|
||||
printf '[watermaps] Übertrage Projekt nach %s:/opt/watermaps\n' "$WM_SSH_TARGET"
|
||||
ssh "${WM_SSH_OPTIONS[@]}" "$WM_SSH_TARGET" \
|
||||
"${remote_prefix}install -d -m 0755 /opt/watermaps /opt/watermaps/deploy"
|
||||
|
||||
rsync \
|
||||
--archive \
|
||||
--compress \
|
||||
--delete-delay \
|
||||
--human-readable \
|
||||
--rsync-path="$rsync_path" \
|
||||
--exclude='.git/' \
|
||||
--exclude='.terraform/' \
|
||||
--exclude='.terraform.tfstate.lock.info' \
|
||||
--exclude='*.tfvars' \
|
||||
--exclude='*.tfvars.json' \
|
||||
--exclude='*.tfplan' \
|
||||
--exclude='*.tfstate*' \
|
||||
--exclude='crash.log' \
|
||||
--exclude='crash.*.log' \
|
||||
--exclude='/data/' \
|
||||
--exclude='/.tools/' \
|
||||
--exclude='node_modules/' \
|
||||
--exclude='**/.env' \
|
||||
--exclude='**/.env.*' \
|
||||
--exclude='/deploy/.env.production' \
|
||||
-e "ssh ${WM_SSH_OPTIONS[*]@Q}" \
|
||||
"$WM_ROOT_DIR/" \
|
||||
"$WM_SSH_TARGET:/opt/watermaps/"
|
||||
|
||||
rsync \
|
||||
--archive \
|
||||
--chmod=F600 \
|
||||
--rsync-path="$rsync_path" \
|
||||
-e "ssh ${WM_SSH_OPTIONS[*]@Q}" \
|
||||
"$local_env" \
|
||||
"$WM_SSH_TARGET:/opt/watermaps/deploy/.env.production"
|
||||
|
||||
remote_command="${remote_prefix}chmod +x /opt/watermaps/deploy/scripts/*.sh"
|
||||
remote_command+=" && ${remote_prefix}/opt/watermaps/deploy/scripts/bootstrap-server.sh"
|
||||
remote_command+=" && ${remote_prefix}/opt/watermaps/deploy/scripts/deploy.sh"
|
||||
ssh "${WM_SSH_OPTIONS[@]}" "$WM_SSH_TARGET" "$remote_command"
|
||||
|
||||
if [[ "$run_go_live" == "true" ]]; then
|
||||
ssh "${WM_SSH_OPTIONS[@]}" "$WM_SSH_TARGET" \
|
||||
"${remote_prefix}/opt/watermaps/deploy/scripts/go-live.sh '$WM_SERVER_IPV4'"
|
||||
else
|
||||
printf '[watermaps] Deployment abgeschlossen. Nach dem DNS-Eintrag:\n'
|
||||
printf ' ./deploy/scripts/remote-go-live.sh --host %s\n' "$WM_SERVER_IPV4"
|
||||
fi
|
||||
Reference in New Issue
Block a user