Automate immutable production deployments
Test and publish container images / test (push) Successful in 2m43s
Test and publish container images / publish (push) Successful in 2m56s

This commit is contained in:
BuTzZ
2026-07-29 13:00:50 +02:00
parent 2e84f4eae4
commit 2064570913
34 changed files with 1779 additions and 215 deletions
+64 -4
View File
@@ -44,10 +44,14 @@ install -d -m 0755 \
"$WATERMAPS_RUNTIME_DIR/locks" \
"$WATERMAPS_RUNTIME_DIR/deployments"
wm_acquire_route_lock ||
wm_die "Deployment abgebrochen, weil gerade Routingdaten aktualisiert werden."
if ! wm_acquire_route_lock; then
wm_log "Deployment wird später erneut versucht, weil gerade Routingdaten aktualisiert werden."
exit 75
fi
active_images_file="$WM_DEPLOY_DIR/.env.images"
active_images_file="${WATERMAPS_ACTIVE_IMAGES_FILE:-${WATERMAPS_IMAGES_ENV_FILE:-$WM_DEPLOY_DIR/.env.images}}"
[[ "$active_images_file" == /* ]] ||
wm_die "WATERMAPS_ACTIVE_IMAGES_FILE muss ein absoluter Pfad sein."
rollback_images_file=""
resolved_images_file=""
deployment_complete=false
@@ -65,7 +69,9 @@ wm_finish_deployment() {
trap - EXIT HUP INT TERM
set +e
if [[ "$status" -ne 0 && "$deployment_complete" != "true" ]]; then
if [[ "$status" -ne 0 &&
"$deployment_complete" != "true" &&
"${WATERMAPS_DISABLE_INTERNAL_ROLLBACK:-false}" != "true" ]]; then
if [[ -n "$rollback_images_file" && -f "$rollback_images_file" ]]; then
wm_log "Deployment fehlgeschlagen; vorheriges Container-Release wird wiederhergestellt."
wm_use_images_env "$rollback_images_file"
@@ -122,6 +128,60 @@ wm_log "Persistentes PostGIS wird vor App und Datenimport gestartet."
wm_compose up --detach --no-build postgres
wm_wait_for_health postgres 240
wm_log "Versionierte Datenbankmigrationen für Commit $revision werden angewendet."
wm_compose exec --no-TTY postgres \
psql \
--no-psqlrc \
--username seacompass \
--dbname seacompass \
--set ON_ERROR_STOP=1 \
--command '
CREATE TABLE IF NOT EXISTS watermaps_schema_migrations (
version text PRIMARY KEY,
applied_at timestamptz NOT NULL DEFAULT now()
);
'
shopt -s nullglob
migration_files=("$WM_ROOT_DIR"/database/migrations/*.sql)
shopt -u nullglob
[[ "${#migration_files[@]}" -gt 0 ]] ||
wm_die "Keine Datenbankmigrationen im Release gefunden."
for migration_file in "${migration_files[@]}"; do
migration_name="$(basename "$migration_file")"
[[ "$migration_name" =~ ^[0-9]{4}_[a-z0-9_]+\.sql$ ]] ||
wm_die "Ungültiger Migrationsdateiname: $migration_name"
migration_version="${migration_name%.sql}"
migration_applied="$(
wm_postgres_query "
SELECT EXISTS (
SELECT 1
FROM watermaps_schema_migrations
WHERE version = '$migration_version'
);
"
)"
migration_applied="${migration_applied//[[:space:]]/}"
if [[ "$migration_applied" == "t" ]]; then
continue
fi
wm_log "Wende Datenbankmigration $migration_version atomar an."
wm_compose exec --no-TTY postgres \
psql \
--no-psqlrc \
--username seacompass \
--dbname seacompass \
--set ON_ERROR_STOP=1 \
--single-transaction \
--file "/docker-entrypoint-initdb.d/migrations/$migration_name" \
--command "
INSERT INTO watermaps_schema_migrations (version)
VALUES ('$migration_version');
"
done
data_update_required=false
update_args=()
if [[ "${WATERMAPS_REBUILD_ROUTE_DATA:-false}" == "true" ]]; then