Reorganised deployment scripts and added rollback functionality. Updated documentation and workflow for container image builds.
This commit is contained in:
@@ -24,8 +24,13 @@ Optionen:
|
||||
-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.
|
||||
mit Dateimodus 0600 übertragen. Es wird ausschließlich der Deployment-Ordner
|
||||
übertragen; App und Routingdaten-Builder werden als commitgenaue Images aus der
|
||||
in .env.production konfigurierten Gitea Registry geladen.
|
||||
|
||||
Für eine private Registry können WATERMAPS_REGISTRY_USERNAME und
|
||||
WATERMAPS_REGISTRY_TOKEN lokal gesetzt werden. Der Token wird nur über SSH an
|
||||
`docker login --password-stdin` übergeben und nicht auf den Server hochgeladen.
|
||||
USAGE
|
||||
}
|
||||
|
||||
@@ -62,10 +67,49 @@ while [[ "$#" -gt 0 ]]; do
|
||||
done
|
||||
|
||||
command -v rsync >/dev/null 2>&1 || wm_local_die "rsync ist lokal nicht installiert."
|
||||
command -v git >/dev/null 2>&1 || wm_local_die "git 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."
|
||||
|
||||
if [[ -n "$(git -C "$WM_ROOT_DIR" status --porcelain --untracked-files=normal)" ]]; then
|
||||
wm_local_die "Deployment nur aus einem vollständig committeten, sauberen Git-Stand erlaubt."
|
||||
fi
|
||||
revision="$(git -C "$WM_ROOT_DIR" rev-parse HEAD)"
|
||||
[[ "$revision" =~ ^[0-9a-f]{40}$ ]] ||
|
||||
wm_local_die "Aktueller Git-Commit konnte nicht als vollständige SHA ermittelt werden."
|
||||
|
||||
set -a
|
||||
# shellcheck disable=SC1090
|
||||
source "$local_env"
|
||||
set +a
|
||||
registry="${WATERMAPS_REGISTRY:-}"
|
||||
registry_owner="${WATERMAPS_REGISTRY_OWNER:-}"
|
||||
[[ "$registry" =~ ^[a-z0-9][a-z0-9.-]*(:[0-9]{1,5})?$ ]] ||
|
||||
wm_local_die "WATERMAPS_REGISTRY muss ein Registry-Hostname ohne URL-Schema sein."
|
||||
[[ "$registry_owner" =~ ^[A-Za-z0-9_.-]+$ ]] ||
|
||||
wm_local_die "WATERMAPS_REGISTRY_OWNER enthält keinen gültigen Gitea-Besitzer."
|
||||
|
||||
registry_username="${WATERMAPS_REGISTRY_USERNAME:-}"
|
||||
registry_token="${WATERMAPS_REGISTRY_TOKEN:-}"
|
||||
if [[ -n "$registry_username" || -n "$registry_token" ]]; then
|
||||
[[ -n "$registry_username" && -n "$registry_token" ]] ||
|
||||
wm_local_die "WATERMAPS_REGISTRY_USERNAME und WATERMAPS_REGISTRY_TOKEN müssen gemeinsam gesetzt werden."
|
||||
[[ "$registry_username" =~ ^[A-Za-z0-9_.-]+$ ]] ||
|
||||
wm_local_die "WATERMAPS_REGISTRY_USERNAME enthält ungültige Zeichen."
|
||||
fi
|
||||
|
||||
images_env="$(mktemp)"
|
||||
trap 'rm -f "$images_env"' EXIT
|
||||
chmod 0600 "$images_env"
|
||||
{
|
||||
printf 'WATERMAPS_DEPLOY_REVISION=%s\n' "$revision"
|
||||
printf 'WATERMAPS_APP_IMAGE=%s/%s/watermaps:%s\n' \
|
||||
"$registry" "$registry_owner" "$revision"
|
||||
printf 'WATERMAPS_ROUTE_DATA_IMAGE=%s/%s/watermaps-route-data:%s\n' \
|
||||
"$registry" "$registry_owner" "$revision"
|
||||
} >"$images_env"
|
||||
|
||||
wm_local_resolve_ssh "$server_ipv4" "$identity_file"
|
||||
wm_local_wait_for_ssh
|
||||
|
||||
@@ -80,7 +124,7 @@ 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"
|
||||
printf '[watermaps] Übertrage Deployment-Dateien nach %s:/opt/watermaps/deploy\n' "$WM_SSH_TARGET"
|
||||
ssh "${WM_SSH_OPTIONS[@]}" "$WM_SSH_TARGET" \
|
||||
"${remote_prefix}install -d -m 0755 /opt/watermaps /opt/watermaps/deploy"
|
||||
|
||||
@@ -90,24 +134,11 @@ rsync \
|
||||
--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' \
|
||||
--exclude='.env.production' \
|
||||
--exclude='.env.images*' \
|
||||
-e "ssh ${WM_SSH_OPTIONS[*]@Q}" \
|
||||
"$WM_ROOT_DIR/" \
|
||||
"$WM_SSH_TARGET:/opt/watermaps/"
|
||||
"$WM_DEPLOY_DIR/" \
|
||||
"$WM_SSH_TARGET:/opt/watermaps/deploy/"
|
||||
|
||||
rsync \
|
||||
--archive \
|
||||
@@ -117,15 +148,32 @@ rsync \
|
||||
"$local_env" \
|
||||
"$WM_SSH_TARGET:/opt/watermaps/deploy/.env.production"
|
||||
|
||||
rsync \
|
||||
--archive \
|
||||
--chmod=F600 \
|
||||
--rsync-path="$rsync_path" \
|
||||
-e "ssh ${WM_SSH_OPTIONS[*]@Q}" \
|
||||
"$images_env" \
|
||||
"$WM_SSH_TARGET:/opt/watermaps/deploy/.env.images.candidate"
|
||||
|
||||
if [[ -n "$registry_token" ]]; then
|
||||
printf '[watermaps] Aktualisiere den privaten Registry-Login auf dem Server.\n'
|
||||
printf '%s\n' "$registry_token" |
|
||||
ssh "${WM_SSH_OPTIONS[@]}" "$WM_SSH_TARGET" \
|
||||
"${remote_prefix}docker login '$registry' --username '$registry_username' --password-stdin"
|
||||
fi
|
||||
|
||||
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"
|
||||
remote_command+=" && ${remote_prefix}/opt/watermaps/deploy/scripts/deploy.sh --images-file /opt/watermaps/deploy/.env.images.candidate"
|
||||
ssh "${WM_SSH_OPTIONS[@]}" "$WM_SSH_TARGET" "$remote_command"
|
||||
ssh "${WM_SSH_OPTIONS[@]}" "$WM_SSH_TARGET" \
|
||||
"${remote_prefix}rm -f /opt/watermaps/deploy/.env.images.candidate"
|
||||
|
||||
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 '[watermaps] Commit %s wurde aus der Registry deployt. Nach dem DNS-Eintrag:\n' "$revision"
|
||||
printf ' ./deploy/scripts/remote-go-live.sh --host %s\n' "$WM_SERVER_IPV4"
|
||||
fi
|
||||
|
||||
Reference in New Issue
Block a user