From 2ed47e77b5416402a71caf789ba189caed8a8ab9 Mon Sep 17 00:00:00 2001 From: "OpenGenesis (MPL 2.0)" <153564363+opengenesislink@users.noreply.github.com> Date: Sat, 7 Nov 2026 15:23:52 +0100 Subject: [PATCH] feat: migrate Landwelle server builds and deployment to Linux x64 v1.5.75 * feat(x64): add Linux amd64 builds, deploy scripts and regression tests * docs(x64): update release, operations and architecture references * docs(x64): add migration, cutover and rollback runbook * ci(x64): verify Docker runtime and protect container build context --- .dockerignore | 15 +++ .github/workflows/ci.yml | 51 ++++++-- CHANGELOG.md | 8 ++ CHATUEBERGABE.md | 14 +-- CONTRIBUTING.md | 2 +- Dockerfile | 27 +++-- README.md | 38 +++--- architecture_x64_v1575_test.go | 31 +++++ docs/AUTOMATION_CRON.md | 8 +- docs/CURRENT_STATE.md | 2 +- docs/DATABASE_MIGRATOR.md | 12 +- docs/DEPLOYMENT_LINUX_X64.md | 109 ++++++++++++++++++ docs/DEPLOYMENT_RASPBERRY_PI.md | 4 +- docs/GITHUB_WORKFLOW.md | 4 +- docs/OPERATIONS.md | 2 +- docs/POSTGRESQL.md | 2 +- docs/README.md | 3 +- docs/SECURITY.md | 2 +- docs/TESTING.md | 10 +- docs/releases/v1.5.75.md | 10 ++ landwelle-github/README.md | 20 ++-- landwelle-github/docs/GITHUB_WORKFLOW.md | 4 +- main.go | 2 +- main_test.go | 2 +- scripts/build-migrator-x64.sh | 20 ++++ scripts/build-x64.sh | 55 +++++++++ scripts/migrate.sh | 9 +- scripts/setup-admin-on-x64.sh | 60 ++++++++++ scripts/update-migrations-on-x64.sh | 103 +++++++++++++++++ scripts/update-portal-on-x64.sh | 141 +++++++++++++++++++++++ 30 files changed, 692 insertions(+), 78 deletions(-) create mode 100644 .dockerignore create mode 100644 architecture_x64_v1575_test.go create mode 100644 docs/DEPLOYMENT_LINUX_X64.md create mode 100644 docs/releases/v1.5.75.md create mode 100755 scripts/build-migrator-x64.sh create mode 100755 scripts/build-x64.sh create mode 100755 scripts/setup-admin-on-x64.sh create mode 100755 scripts/update-migrations-on-x64.sh create mode 100755 scripts/update-portal-on-x64.sh diff --git a/.dockerignore b/.dockerignore new file mode 100644 index 0000000..e4a5b97 --- /dev/null +++ b/.dockerignore @@ -0,0 +1,15 @@ +.git +.github +dist +release +*.zip +*.dump +*.dump.* +.env +.env.* +!/.env.example +*.pem +*.key +*service-account*.json +node_modules +__pycache__ diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 1b69d41..5685acf 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -37,8 +37,8 @@ jobs: - name: Vet run: go vet ./... - build-arm64: - name: ARM64 production build + build-amd64: + name: Linux x64 production build runs-on: ubuntu-latest timeout-minutes: 20 steps: @@ -55,23 +55,50 @@ jobs: env: CGO_ENABLED: '0' GOOS: linux - GOARCH: arm64 - run: go build -trimpath -o /tmp/landwelle-portal-linux-arm64 . + GOARCH: amd64 + run: go build -trimpath -o /tmp/landwelle-portal-linux-amd64 . - name: Build migrator env: CGO_ENABLED: '0' GOOS: linux - GOARCH: arm64 - run: go build -trimpath -o /tmp/landwelle-migrate-linux-arm64 ./cmd/migrate + GOARCH: amd64 + run: go build -trimpath -o /tmp/landwelle-migrate-linux-amd64 ./cmd/migrate - name: Build adminpass env: CGO_ENABLED: '0' GOOS: linux - GOARCH: arm64 - run: go build -trimpath -o /tmp/landwelle-adminpass-linux-arm64 ./cmd/adminpass + GOARCH: amd64 + run: go build -trimpath -o /tmp/landwelle-adminpass-linux-amd64 ./cmd/adminpass + - name: Verify x64 ELF binaries + run: | + for name in portal migrate adminpass; do + path="/tmp/landwelle-${name}-linux-amd64" + file "$path" | grep -q 'ELF 64-bit.*x86-64' + go version -m "$path" | grep -q 'GOARCH=amd64' + done + - name: Build from production x64 scripts + run: | + ./scripts/build-x64.sh + ./scripts/build-migrator-x64.sh + file dist/landwelle-portal-linux-amd64 | grep -q 'x86-64' + ./dist/landwelle-portal-linux-amd64 --version | grep -q 'Landwelle v' + + container-amd64: + name: Linux x64 container build and smoke test + runs-on: ubuntu-latest + timeout-minutes: 20 + steps: + - name: Checkout + uses: actions/checkout@v4 + - name: Build x64 container + run: docker build --platform linux/amd64 -t landwelle-portal:x64-ci . + - name: Verify x64 container binary + run: | + docker image inspect landwelle-portal:x64-ci --format '{{.Architecture}}' | grep -qx amd64 + docker run --rm --entrypoint /usr/local/bin/landwelle-portal landwelle-portal:x64-ci --version | grep -qx 'Landwelle v1.5.75' frontend-static: name: JavaScript and deployment-script checks runs-on: ubuntu-latest @@ -86,6 +113,12 @@ jobs: node --check "$file" done + - name: Validate x64 script execute permissions + run: | + for file in scripts/build-x64.sh scripts/build-migrator-x64.sh scripts/update-portal-on-x64.sh scripts/update-migrations-on-x64.sh scripts/setup-admin-on-x64.sh; do + test -x "$file" + done + - name: Validate shell scripts run: | find scripts -name '*.sh' -print0 | while IFS= read -r -d '' file; do @@ -96,7 +129,7 @@ jobs: run: | trap 'rm -f destination_one_ci_sentinel.go' EXIT printf 'package main\n' > destination_one_ci_sentinel.go - if ./scripts/build-pi.sh > /tmp/landwelle-build-guard.log 2>&1; then + if ./scripts/build-x64.sh > /tmp/landwelle-build-guard.log 2>&1; then echo "Build unexpectedly accepted an untracked Go source" >&2 exit 1 fi diff --git a/CHANGELOG.md b/CHANGELOG.md index 4061ee3..5e15257 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,11 @@ +## v1.5.75 – Umstellung des Serverprojekts auf Linux x64 +- Neue Linux-x64-Produktionsbuilds (x86_64/Go amd64, GOAMD64=v1) für Portal, PostgreSQL-Migrator und Adminpass. +- Eigenständige Build-, Deployment- und Adminskripte für x64, mit Plattformkontrollen, Versionsprüfung und vorhandenem Rollback. +- migrate.sh wählt auf x64 amd64, auf ARM den bisherigen ARM64-Migrator; alte Pi-Skripte bleiben für einen abgesicherten Rückfall. +- GitHub CI prüft amd64-ELF-Architektur, Go-Tests, Laufzeitversion und x64-Buildskripte. Dockerfile baut das vollständige Portal und enthält psql/ffmpeg. +- Dokumentation für Serverumzug, Backup, Konfigurations-/Dateienübernahme, Reverse Proxy und Cron-Cutover. +- Keine Datenbankmigration. Der Zielserver wird erst nach manueller Datenübernahme und erfolgreichem Test in Betrieb genommen. + ## v1.5.74 - Automatische KI-Nachrichtenaufträge werden atomar in PostgreSQL beansprucht; parallele Cron-Aufrufe können denselben Tages-/Minutenauftrag nicht mehr doppelt starten. - Live-Jobstatus liefert eigenständige Snapshots statt gemeinsam veränderbarer Step-Arrays; abgeschlossene Jobs werden nach sechs Stunden und verwaiste laufende Jobs nach 24 Stunden beim nächsten Auftrag bereinigt. diff --git a/CHATUEBERGABE.md b/CHATUEBERGABE.md index 0704cfd..73f09bf 100644 --- a/CHATUEBERGABE.md +++ b/CHATUEBERGABE.md @@ -1,7 +1,7 @@ # Chatübergabe – Landwelle-Portal -**Aktuelle Referenzversion:** `Landwelle v1.5.70` -**Stand:** 30. September 2026 +**Aktuelle Referenzversion:** `Landwelle v1.5.75` +**Stand:** 7. November 2026 **Referenzpaket:** `landwelle-go-portal-v1.5.70-COMPLETE-source.zip` **Datenbankstand:** Migrationen `0001` bis `0045` plus `9000_landwelle_zuhause_navigation.sql` @@ -14,7 +14,7 @@ Diese Datei ist die verbindliche Übergabe für einen neuen Chat zum Landwelle-G - Go 1.22, modularer Monolith - PostgreSQL als einzige Datenbank - Templates und Assets über `go:embed` -- Linux ARM64 / Raspberry Pi 5 +- Linux x64 (amd64) als neues Ziel; Raspberry Pi 5 bis Cutover als ARM64-Altserver - interner Port `2200` - systemd-Dienst `landwelle-radio.service` - Produktivbinary `/opt/landwelle/landwelle-portal` @@ -221,10 +221,10 @@ v1.5.62 enthält keine neue Migration gegenüber dem Landwelle-Zuhause-Stand. `9 cd /home/users/slmmradio/www/landwelle.de unzip -o /PFAD/landwelle-go-portal-v1.5.62-COMPLETE-source.zip chmod +x scripts/*.sh -./scripts/build-migrator-pi.sh -sudo ./scripts/update-migrations-on-pi.sh -./scripts/build-pi.sh -sudo ./scripts/update-portal-on-pi.sh +./scripts/build-migrator-x64.sh +sudo ./scripts/update-migrations-on-x64.sh +./scripts/build-x64.sh +sudo ./scripts/update-portal-on-x64.sh ``` Prüfen: diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index a26d7e3..3b98d1d 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -58,7 +58,7 @@ Zusätzlich: - Shellskripte mit `bash -n` prüfen - Templates parsen und relevante HTTP-Routen testen - alle Migrationen auf unerlaubte Transaktionsanweisungen prüfen -- Linux-ARM64-Builds für Portal, Migrator und Adminpass erstellen +- Linux-x64-Builds für Portal, Migrator und Adminpass erstellen - Quellpaket auf Secrets und generierte Dateien prüfen - ZIP-Integrität und SHA-256 prüfen diff --git a/Dockerfile b/Dockerfile index fe5716e..1fab380 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,10 +1,23 @@ -FROM golang:1.23-alpine AS build +# Build complete Go portal for Linux x64; does not depend on the builder CPU. +FROM --platform=$BUILDPLATFORM golang:1.24.4-bookworm AS build WORKDIR /src -COPY go.mod main.go ./ -COPY web ./web -RUN CGO_ENABLED=0 GOOS=linux go build -trimpath -ldflags="-s -w" -o /out/landwelle-portal . +COPY go.mod go.sum ./ +RUN go mod download +COPY . . +RUN CGO_ENABLED=0 GOOS=linux GOARCH=amd64 GOAMD64=v1 \ + go build -trimpath -ldflags="-s -w" -o /out/landwelle-portal . -FROM scratch -COPY --from=build /out/landwelle-portal /landwelle-portal +# psql and ffmpeg are required at runtime by the current application. +FROM debian:bookworm-slim +RUN apt-get update && \ + DEBIAN_FRONTEND=noninteractive apt-get install -y --no-install-recommends \ + ca-certificates tzdata postgresql-client ffmpeg && \ + rm -rf /var/lib/apt/lists/* && \ + useradd --system --uid 10001 --home-dir /var/lib/landwelle --shell /usr/sbin/nologin landwelle && \ + install -d -o landwelle -g landwelle -m 0750 /var/lib/landwelle +COPY --from=build /out/landwelle-portal /usr/local/bin/landwelle-portal +ENV ADDR=:2200 LANDWELLE_STATE_DIR=/var/lib/landwelle +USER landwelle +VOLUME ["/var/lib/landwelle"] EXPOSE 2200 -ENTRYPOINT ["/landwelle-portal"] +ENTRYPOINT ["/usr/local/bin/landwelle-portal"] diff --git a/README.md b/README.md index e7a89b8..209d020 100644 --- a/README.md +++ b/README.md @@ -1,8 +1,8 @@ # Landwelle Radio Portal -**Aktueller Stand: Landwelle v1.5.70 – 30. September 2026** +**Quellstand: Landwelle v1.5.75 – Linux x64 Migration (7. November 2026)** -Landwelle ist ein Go-basiertes Radio- und Regionalportal mit öffentlicher Website, geschütztem Adminbereich, PostgreSQL-Datenbank, Radio-App-API und internen Produktionswerkzeugen. Das Portal läuft produktiv als Linux-ARM64-Dienst auf einem Raspberry Pi 5. +Landwelle ist ein Go-basiertes Radio- und Regionalportal mit öffentlicher Website, geschütztem Adminbereich, PostgreSQL-Datenbank, Radio-App-API und internen Produktionswerkzeugen. Die neue Zielplattform ist Linux x64 (x86_64/amd64). Der bisherige ARM64-Server läuft bis zur abgesicherten Umschaltung weiter. ## Aktueller Projektstatus @@ -44,7 +44,7 @@ Der aktuelle Funktionsumfang umfasst insbesondere: - PostgreSQL; kein SQLite - HTML-Templates und statische Assets über `go:embed` - interner Standardport `2200` -- Linux ARM64 / Raspberry Pi 5 +- Zielplattform Linux x64 (x86_64/amd64); Raspberry Pi als Legacy-/Rollback-System - systemd-Dienst `landwelle-radio.service` - Runtime-Binary `/opt/landwelle/landwelle-portal` - Konfiguration `/etc/landwelle/landwelle.env` @@ -87,39 +87,45 @@ go test ./... go vet ./... ``` -GitHub Actions prüft zusätzlich den Linux-ARM64-Produktionsbuild für Portal, Migrator und `adminpass`. +GitHub Actions prüft zusätzlich den Linux-x64-Produktionsbuild für Portal, Migrator und `adminpass`. -## ARM64-Build +## Linux-x64-Build ```bash -./scripts/build-pi.sh -./scripts/build-migrator-pi.sh +./scripts/build-x64.sh +./scripts/build-migrator-x64.sh ``` Alternativ direkt: ```bash -GOOS=linux GOARCH=arm64 go build -o dist/landwelle-portal-linux-arm64 . -GOOS=linux GOARCH=arm64 go build -o dist/landwelle-migrate-linux-arm64 ./cmd/migrate -GOOS=linux GOARCH=arm64 go build -o dist/landwelle-adminpass-linux-arm64 ./cmd/adminpass +GOOS=linux GOARCH=amd64 go build -o dist/landwelle-portal-linux-amd64 . +GOOS=linux GOARCH=amd64 go build -o dist/landwelle-migrate-linux-amd64 ./cmd/migrate +GOOS=linux GOARCH=amd64 go build -o dist/landwelle-adminpass-linux-amd64 ./cmd/adminpass ``` +## Geplanter Umzug auf Linux x64 + +Der Architekturwechsel installiert weder Konfiguration noch Dateien oder Datenbank automatisch. Vor dem Umzug den [x64-Deployment- und Umzugsleitfaden](docs/DEPLOYMENT_LINUX_X64.md) lesen. Er beschreibt Backup, Übernahme von /etc/landwelle und /var/lib/landwelle, PostgreSQL, Reverse Proxy, zentrale Cronjobs, Cutover und Rollback. + +Die bisherigen *-pi.sh-Skripte bleiben als Legacy-/Rollback-Werkzeuge erhalten. Alle **neuen** Deployments verwenden ausschließlich die *-x64.sh-Skripte. + ## Produktives Update aus GitHub Wenn keine neue Migration hinzugekommen ist: ```bash -cd /root/landwelle-github +cd /opt/landwelle git pull --ff-only origin main -./scripts/build-pi.sh -sudo ./scripts/update-portal-on-pi.sh +./scripts/build-x64.sh +sudo ./scripts/update-portal-on-x64.sh ``` Wenn eine neue Migration Bestandteil eines Releases ist, vorher zusätzlich: ```bash -./scripts/build-migrator-pi.sh -sudo ./scripts/update-migrations-on-pi.sh +./scripts/build-migrator-x64.sh +sudo ./scripts/update-migrations-on-x64.sh ``` Anschließend prüfen: @@ -130,7 +136,7 @@ curl -fsS http://127.0.0.1:2200/version curl -fsS http://127.0.0.1:2200/ready ``` -Erwartete Version: `Landwelle v1.5.70`. +Erwartete Version: `Landwelle v1.5.75`. ## Verbindliche Projektdokumente diff --git a/architecture_x64_v1575_test.go b/architecture_x64_v1575_test.go new file mode 100644 index 0000000..604964f --- /dev/null +++ b/architecture_x64_v1575_test.go @@ -0,0 +1,31 @@ +package main + +import ( + "os" + "strings" + "testing" +) +func TestLinuxX64ReleaseBuildAndDeployScripts(t *testing.T) { + for _, path := range []string{"scripts/build-x64.sh","scripts/build-migrator-x64.sh","scripts/update-portal-on-x64.sh","scripts/update-migrations-on-x64.sh"} { + b, err := os.ReadFile(path) + if err != nil {t.Fatal(err)} + s := string(b) + if !strings.Contains(s, "linux-amd64") || !strings.Contains(s,"x86_64") { + t.Fatalf("%s is not configured for Linux x64",path) + } + if strings.Contains(s,"GOARCH=arm64") {t.Errorf("%s still builds ARM64",path)} + } +} +func TestLinuxX64ReleaseCI(t *testing.T) { + for path, tokens := range map[string][]string{ + ".github/workflows/ci.yml":{"build-amd64:", "GOARCH: amd64", "Linux x64 production build"}, + "scripts/migrate.sh":{"TARGET_ARCH=\"amd64\"","TARGET_ARCH=\"arm64\""}, + "Dockerfile":{"GOARCH=amd64","postgresql-client","ffmpeg"}, + } { + content,err := os.ReadFile(path) + if err != nil {t.Fatal(err)} + for _, token := range tokens { + if !strings.Contains(string(content),token) {t.Errorf("%s: missing %q",path,token)} + } + } +} diff --git a/docs/AUTOMATION_CRON.md b/docs/AUTOMATION_CRON.md index 3b67388..c1f04e9 100644 --- a/docs/AUTOMATION_CRON.md +++ b/docs/AUTOMATION_CRON.md @@ -84,10 +84,10 @@ Ist eine Aufgabe deaktiviert, gelöscht oder für einen anderen Wochentag bezieh Beim Update auf v1.5.41 ist Migration `0042_split_ai_auto_tasks.sql` erforderlich: ```bash -./scripts/build-migrator-pi.sh -sudo ./scripts/update-migrations-on-pi.sh -./scripts/build-pi.sh -sudo ./scripts/update-portal-on-pi.sh +./scripts/build-migrator-x64.sh +sudo ./scripts/update-migrations-on-x64.sh +./scripts/build-x64.sh +sudo ./scripts/update-portal-on-x64.sh ``` Der vorhandene KeyHelp-Minutenjob und `LANDWELLE_CRON_TOKEN` bleiben unverändert. Anschließend `/admin/ai/auto-tasks` prüfen. Bestehende Paket-Zeitpläne wurden automatisch in Nachrichten Welt, Sport und Wetter aufgeteilt; neue Zeitpläne werden ausschließlich getrennt angelegt. diff --git a/docs/CURRENT_STATE.md b/docs/CURRENT_STATE.md index 34575c6..9eadbee 100644 --- a/docs/CURRENT_STATE.md +++ b/docs/CURRENT_STATE.md @@ -6,7 +6,7 @@ ## Betriebsmodell -Das Portal ist ein Go-Monolith mit eingebetteten Templates und Assets. PostgreSQL ist die einzige Datenbank. Produktiv läuft das Portal auf Linux ARM64 hinter dem vorhandenen Reverse Proxy; intern lauscht es standardmäßig auf Port `2200`. +Das Portal ist ein Go-Monolith mit eingebetteten Templates und Assets. PostgreSQL ist die einzige Datenbank. Die neue Zielplattform ist Linux x64 (x86_64/amd64) hinter dem vorhandenen Reverse Proxy; der alte ARM64-Server bleibt bis zum Cutover erhalten; intern lauscht es standardmäßig auf Port `2200`. ## Öffentliche Website diff --git a/docs/DATABASE_MIGRATOR.md b/docs/DATABASE_MIGRATOR.md index c17ae2d..54a3485 100644 --- a/docs/DATABASE_MIGRATOR.md +++ b/docs/DATABASE_MIGRATOR.md @@ -30,17 +30,17 @@ DATABASE_URL=postgres://landwelle_app:PASSWORT@127.0.0.1:5432/landwelle?sslmode= Das Datenbankkonto benötigt Rechte zum Erstellen und Ändern der Landwelle-Tabellen. -## Einfachste Aktualisierung auf dem Raspberry Pi +## Einfachste Aktualisierung auf dem Linux-x64-Server Das Paket enthält ein Installationsskript. Im entpackten Projektordner genügt: ```bash -sudo ./scripts/update-migrations-on-pi.sh +sudo ./scripts/update-migrations-on-x64.sh ``` -Das Skript installiert bei Bedarf den PostgreSQL-Client, kopiert den ARM64-Migrator und die offenen SQL-Dateien nach `/opt/landwelle`, setzt die nötigen Rechte, führt die Migrationen als Benutzer `landwelle` aus und startet anschließend `landwelle-radio` neu. +Das Skript installiert bei Bedarf den PostgreSQL-Client, kopiert den x64-Migrator und die offenen SQL-Dateien nach `/opt/landwelle`, setzt die nötigen Rechte, führt die Migrationen als Benutzer `landwelle` aus und startet anschließend `landwelle-radio` neu. -## Ausführen auf dem Raspberry Pi +## Ausführen auf dem Linux-x64-Server Im Installationsordner `/opt/landwelle`: @@ -51,7 +51,7 @@ sudo -u landwelle /opt/landwelle/scripts/migrate.sh Alternativ direkt: ```bash -sudo -u landwelle /opt/landwelle/dist/landwelle-migrate-linux-arm64 \ +sudo -u landwelle /opt/landwelle/dist/landwelle-migrate-linux-amd64 \ --env-file /etc/landwelle/landwelle.env \ --dir /opt/landwelle/migrations \ --archive-dir /opt/landwelle/migrations/applied @@ -115,4 +115,4 @@ Der reguläre Quellstand reicht bis Migration `0045`. Für „Landwelle Zuhause Die letzten Schritte ergänzen Chartgenerierung, atomare Chartpositionen, Redaktionstypen, Forum-Lesestatus, App-Empfangsbestätigungen, öffentliche Inhaltsseiten, Kontaktanfragen, Mediathek, consentbasierte Webstatistik, den ersten Pressebericht zum App-Beta-Test und die Reparatur seiner Absatztrennungen. -Vor Portalupdates ist `update-migrations-on-pi.sh` auszuführen, wenn die Zielumgebung noch nicht alle vorhandenen Migrationen registriert hat. Version v1.5.57 konsolidiert `9000_landwelle_zuhause_navigation.sql`; der Migrator ist vor dem Portalupdate auszuführen, damit der neue Menüpunkt „Landwelle Zuhause“ in bestehenden Installationen angelegt wird. +Vor Portalupdates ist `update-migrations-on-x64.sh` auszuführen, wenn die Zielumgebung noch nicht alle vorhandenen Migrationen registriert hat. Version v1.5.57 konsolidiert `9000_landwelle_zuhause_navigation.sql`; der Migrator ist vor dem Portalupdate auszuführen, damit der neue Menüpunkt „Landwelle Zuhause“ in bestehenden Installationen angelegt wird. diff --git a/docs/DEPLOYMENT_LINUX_X64.md b/docs/DEPLOYMENT_LINUX_X64.md new file mode 100644 index 0000000..a8757e2 --- /dev/null +++ b/docs/DEPLOYMENT_LINUX_X64.md @@ -0,0 +1,109 @@ +# Landwelle auf Linux x64 umziehen + +**Ziel:** Linux x86_64 / Go GOARCH=amd64 (ab v1.5.75). Das Go-Portal bleibt fachlich unverändert. Der bisherige Raspberry Pi (ARM64) bleibt bis zur geprüften Umschaltung erhalten. Ein Build oder Git-Merge kopiert weder Daten noch Konfiguration und schaltet keine Domains um. + +## 1. Vorbereitung + +Auf einem neuen Debian-/Ubuntu-Server mit x86_64 und systemd: + +```bash +uname -m # muss x86_64 ausgeben +go version # Go 1.24.4 verwenden +sudo apt-get update +sudo apt-get install -y git curl rsync ca-certificates postgresql-client ffmpeg +``` + +Go 1.24.4 ggf. vorher aus offizieller Quelle installieren. Der x64-Host braucht Zugriff auf PostgreSQL, AzuraCast, FTP/Audio-Ziele, Firebase, OpenAI/ElevenLabs und ggf. KeyHelp/Reverse Proxy. Die Datenbank bleibt nach Möglichkeit auf ihrem bisherigen Server; es ist keine ARM-zu-x64-Datenkonvertierung nötig. + +## 2. Build getrennt vom alten Produktivsystem + +```bash +sudo useradd --system --home /opt/landwelle --shell /usr/sbin/nologin landwelle 2>/dev/null || true +sudo install -d -o root -g root -m 755 /opt/landwelle +sudo install -d -o root -g landwelle -m 750 /etc/landwelle +sudo install -d -o landwelle -g landwelle -m 750 /var/lib/landwelle +# Bei vorhandenem GitHub-Zugriff auf das private Repository: +sudo git clone https://github.com/opengenesislink/landwelle.git /opt/landwelle +cd /opt/landwelle +./scripts/build-x64.sh +./scripts/build-migrator-x64.sh +file dist/landwelle-portal-linux-amd64 +./dist/landwelle-portal-linux-amd64 --version +``` + +Falls /opt/landwelle bereits das Git-Repository enthält: statt git clone ein `git pull --ff-only origin main` ausführen. Auf dem neuen Rechner **nicht** die alten *-pi.sh-Skripte verwenden. Sie bleiben für den bisherigen Pi erhalten. + +## 3. Daten und Geheimnisse sichern und übertragen + +Vor dem Umzug ein geprüftes PostgreSQL-Backup (`pg_dump`) und ein Backup der Dateien erstellen. Für einen konsistenten letzten Dateiabzug den alten Dienst stoppen und den zentralen Cronjob vorübergehend deaktivieren. + +Zu übernehmen sind mindestens: +- `/etc/landwelle/` einschließlich `landwelle.env`, Firebase-Service-Account-Dateien und etwaigen privaten Schlüsseln +- `/var/lib/landwelle/` vollständig, insbesondere Uploads, Mediendateien, Downloads und `settings.json` +- falls individuell konfiguriert weitere lokale Medien-/Audioordner und den produktiven Proxy-/Cron-Aufbau + +Auf dem **alten** Server nach dem Backup: + +```bash +sudo systemctl stop landwelle-radio +sudo tar -C / -czf /root/landwelle-private-transfer.tar.gz etc/landwelle var/lib/landwelle +sudo chmod 600 /root/landwelle-private-transfer.tar.gz +``` + +Das Archiv über verschlüsseltes SSH auf den neuen Server übertragen, als root entpacken und Rechte prüfen: + +```bash +sudo tar -C / -xzf /PFAD/landwelle-private-transfer.tar.gz +sudo chown -R landwelle:landwelle /var/lib/landwelle +sudo chown root:landwelle /etc/landwelle/landwelle.env +sudo chmod 750 /etc/landwelle +sudo chmod 640 /etc/landwelle/landwelle.env +``` + +Andere private Dateien müssen durch den Dienstbenutzer lesbar bleiben und dürfen nicht öffentlich erreichbar sein. Archiv nach der Verifikation sicher entfernen. **Keine Secrets in GitHub hochladen oder im Chat veröffentlichen.** Falls die PostgreSQL-Instanz auf einen anderen Host umzieht, die Daten separat mit pg_dump/pg_restore übertragen; andernfalls den vorhandenen Datenbankserver beibehalten. + +## 4. Datenbank und Start prüfen + +Die Datenbank-Firewall sowie pg_hba.conf müssen jetzt die **neue** Anwendungsserver-IP zulassen. Netzwerk und `psql` sowie `ffmpeg -version` prüfen. Die neue Instanz darf vor dem Cutover nicht parallel Schreibaufträge oder den zentralen KI-Cron ausführen. + +```bash +cd /opt/landwelle +# Nur eine Vorprüfung – führt keine Datenbankmigration aus: +sudo -u landwelle ./scripts/migrate.sh --dry-run +# Bei ausstehenden SQL-Migrationen erst nach bestätigtem Backup: +# sudo ./scripts/update-migrations-on-x64.sh +sudo ./scripts/update-portal-on-x64.sh +file /opt/landwelle/landwelle-portal +/opt/landwelle/landwelle-portal --version +sudo systemctl status landwelle-radio --no-pager +curl -fsS http://127.0.0.1:2200/ready +curl -fsS http://127.0.0.1:2200/version +``` + +Das Update prüft die x64-Architektur, die Version und `/ready` und führt bei einem fehlgeschlagenen Update einen lokalen Binary-Rollback durch. Es ersetzt **keine** Sicherung des ARM-Altservers. + +## 5. Umschalten + +1. Backups und die Datenübernahme bestätigen; alten ARM-Dienst und alten KeyHelp-Cron nicht gleichzeitig auf dem neuen Host aktivieren. +2. Auf x64 Login, Startseite, Player, Nachrichtenstudio/OpenAI/ElevenLabs/ffmpeg, FTP-Upload, Mediathek/Uploads, Veranstaltungen sowie öffentliche und interne App-APIs testen. +3. Reverse Proxy und nötigenfalls DNS von `landwelle.de` und `api.landwelle.de` auf die neue Ziel-IP schalten; TLS und Forwarding-Header kontrollieren. Port 2200 und PostgreSQL-Port 5432 nicht öffentlich freigeben. +4. Externen KeyHelp-Minutenjob auf den **neuen** erreichbaren Endpunkt umstellen – ein localhost-Aufruf auf dem alten Server würde sonst weiterhin dorthin zeigen. Nur einen aktiven Cron-Taktgeber betreiben. +5. `journalctl -u landwelle-radio -f`, `/health`, `/ready`, Webseiten und Audio-Produktion überwachen. + +## 6. Rückfall und weitere Updates + +Bei Problemen den neuen Cron stoppen, Reverse Proxy auf den alten ARM-Server zurückstellen und dessen bisheriges Binary wieder starten. Nicht beide Server gleichzeitig mit aktiven automatischen oder schreibenden Jobs betreiben. Nach dem Cutover entstandene Uploads und Datenänderungen vor einem Rückfall berücksichtigen; Datenbank-Restore ist immer ein separater, geplanter Vorgang. + +Folgende Befehle gelten **nach** dem erfolgreichen Umzug für Linux x64: + +```bash +cd /opt/landwelle +git pull --ff-only origin main +./scripts/build-x64.sh +# Nur wenn neue Migrationen vorliegen: +# ./scripts/build-migrator-x64.sh +# sudo ./scripts/update-migrations-on-x64.sh +sudo ./scripts/update-portal-on-x64.sh +``` + +Docker ist optional. `docker build --platform linux/amd64` baut das Portal mit Laufzeitwerkzeugen. Im Dockerbetrieb müssen Secrets, Datenverzeichnisse, Ports und Netzwerk separat eingerichtet werden; Standard bleibt systemd. diff --git a/docs/DEPLOYMENT_RASPBERRY_PI.md b/docs/DEPLOYMENT_RASPBERRY_PI.md index 947935e..8ea5627 100644 --- a/docs/DEPLOYMENT_RASPBERRY_PI.md +++ b/docs/DEPLOYMENT_RASPBERRY_PI.md @@ -1,4 +1,6 @@ -# Deployment auf Raspberry Pi 5 +# Deployment auf Raspberry Pi 5 (nur Legacy/Notfall-Rollback) + +Für neue Installationen gilt [DEPLOYMENT_LINUX_X64.md](DEPLOYMENT_LINUX_X64.md). Diese Seite dokumentiert lediglich die historische ARM64-Konfiguration. ## Zielsystem diff --git a/docs/GITHUB_WORKFLOW.md b/docs/GITHUB_WORKFLOW.md index b755a43..7821196 100644 --- a/docs/GITHUB_WORKFLOW.md +++ b/docs/GITHUB_WORKFLOW.md @@ -2,7 +2,7 @@ ## Grundsatz -GitHub `main` ist die verbindliche Quellcode-Basis. Produktive Änderungen werden nicht ausschließlich auf dem Server gepflegt. Änderungen werden zuerst als nachvollziehbarer Commit in GitHub abgelegt und anschließend auf dem Raspberry Pi gebaut bzw. ausgerollt. +GitHub `main` ist die verbindliche Quellcode-Basis. Produktive Änderungen werden nicht ausschließlich auf dem Server gepflegt. Änderungen werden zuerst als nachvollziehbarer Commit in GitHub abgelegt und anschließend auf dem Linux-x64-Server gebaut bzw. ausgerollt. ## Release-Ablauf @@ -37,7 +37,7 @@ Migrationen bleiben unveränderlich, sobald sie produktiv ausgeführt wurden. Ne - `go mod verify` - `go test ./...` - `go vet ./...` -- Linux-ARM64-Build für Portal, Migrator und Adminpass +- Linux-x64-Build für Portal, Migrator und Adminpass ## Abhängigkeiten diff --git a/docs/OPERATIONS.md b/docs/OPERATIONS.md index 94e625c..8e33a00 100644 --- a/docs/OPERATIONS.md +++ b/docs/OPERATIONS.md @@ -134,7 +134,7 @@ Für jede App-/Player-Version archivieren: ## Adminzugang einrichten ```bash -sudo ./scripts/setup-admin-on-pi.sh +sudo ./scripts/setup-admin-on-x64.sh sudo systemctl status landwelle-radio --no-pager ``` diff --git a/docs/POSTGRESQL.md b/docs/POSTGRESQL.md index 66dbfff..3c04e9a 100644 --- a/docs/POSTGRESQL.md +++ b/docs/POSTGRESQL.md @@ -2,7 +2,7 @@ ## Grundsatz -Landwelle verwendet ausschließlich PostgreSQL für persistente Daten. Auf dem Raspberry Pi wird keine SQLite-Datei angelegt. Der vorhandene PostgreSQL-Server bleibt ein separater Dienst im privaten Netz oder auf einem abgesicherten Host. +Landwelle verwendet ausschließlich PostgreSQL für persistente Daten. Auf dem neuen Linux-x64-Host wird keine SQLite-Datei angelegt. Der vorhandene PostgreSQL-Server bleibt ein separater Dienst im privaten Netz oder auf einem abgesicherten Host. ## Empfohlene Datenbankobjekte diff --git a/docs/README.md b/docs/README.md index 44a5b9e..5953fae 100644 --- a/docs/README.md +++ b/docs/README.md @@ -14,7 +14,8 @@ Dieser Ordner enthält dauerhafte technische und fachliche Dokumentation. Releas ## Betrieb und Sicherheit - `CONFIGURATION.md` – Umgebungsvariablen und Konfiguration -- `DEPLOYMENT_RASPBERRY_PI.md` – Bereitstellung auf dem Raspberry Pi +- `DEPLOYMENT_LINUX_X64.md` – neue Zielinstallation und Umzug auf Linux x64 +- `DEPLOYMENT_RASPBERRY_PI.md` – bisheriger Raspberry-Pi-Betrieb (Legacy/Notfallrückfall) - `OPERATIONS.md` – laufender Betrieb, Monitoring und Backups - `DATABASE_MIGRATOR.md` – Migrationsablauf - `POSTGRESQL.md` – Datenbankbetrieb diff --git a/docs/SECURITY.md b/docs/SECURITY.md index f28081d..e59b0d7 100644 --- a/docs/SECURITY.md +++ b/docs/SECURITY.md @@ -14,7 +14,7 @@ - dedizierte Rolle mit minimalen Rechten - TLS je nach Netz- und Serverkonfiguration -- `pg_hba.conf` auf Raspberry-Pi-IP oder Anwendungsnetz begrenzen +- `pg_hba.conf` auf IP des aktuellen Anwendungsservers oder privates Anwendungsnetz begrenzen - parametrisierte Abfragen - Migrationen versionieren - Verbindungsstring nur als Secret diff --git a/docs/TESTING.md b/docs/TESTING.md index 731cc3a..0f388ce 100644 --- a/docs/TESTING.md +++ b/docs/TESTING.md @@ -37,13 +37,13 @@ go build -trimpath -o /tmp/landwelle-portal . /tmp/landwelle-portal --version ``` -Linux ARM64: +Linux x64: ```bash -GOOS=linux GOARCH=arm64 go build -o /tmp/landwelle-portal-arm64 . -GOOS=linux GOARCH=arm64 go build -o /tmp/landwelle-migrate-arm64 ./cmd/migrate -GOOS=linux GOARCH=arm64 go build -o /tmp/landwelle-adminpass-arm64 ./cmd/adminpass -file /tmp/landwelle-*-arm64 +GOOS=linux GOARCH=amd64 go build -o /tmp/landwelle-portal-amd64 . +GOOS=linux GOARCH=amd64 go build -o /tmp/landwelle-migrate-amd64 ./cmd/migrate +GOOS=linux GOARCH=amd64 go build -o /tmp/landwelle-adminpass-amd64 ./cmd/adminpass +file /tmp/landwelle-*-amd64 ``` Der Versionsstring in `main.go`, der lokalen Binary und der ausgelieferten ARM64-Binary muss übereinstimmen. diff --git a/docs/releases/v1.5.75.md b/docs/releases/v1.5.75.md new file mode 100644 index 0000000..7b2d3ae --- /dev/null +++ b/docs/releases/v1.5.75.md @@ -0,0 +1,10 @@ +# Landwelle v1.5.75 – Linux x64 + +- Zielplattform Linux x86_64 (Go amd64, GOAMD64=v1) statt bisheriger Raspberry-Pi-ARM64-Produktionsbuilds. +- Neue Skripte: build-x64.sh, build-migrator-x64.sh, update-portal-on-x64.sh, update-migrations-on-x64.sh, setup-admin-on-x64.sh. +- CI baut Portal, Migrator und Adminpass für amd64, prüft die Architektur der ELF-Dateien sowie die produktiven Buildskripte. +- migrate.sh wählt für den x64-Server amd64, unterstützt für einen Rollback weiterhin ARM64. Alle bisherigen Pi-Skripte bleiben vorerst bestehen. +- Dockerfile wurde an den vollständigen Go-Quellstand und die Laufzeitabhängigkeiten psql/ffmpeg angepasst. +- Kein Schemawechsel und keine automatische Datenübernahme. Vollständige Anleitung: docs/DEPLOYMENT_LINUX_X64.md. + +Die x64-Zielumgebung einschließlich Zugangsdateien, Uploads, PostgreSQL-Netzwerk und Reverse-Proxy-/KeyHelp-Cron-Umschaltung muss manuell eingerichtet und geprüft werden. diff --git a/landwelle-github/README.md b/landwelle-github/README.md index c7f7fc0..706be66 100644 --- a/landwelle-github/README.md +++ b/landwelle-github/README.md @@ -1,8 +1,8 @@ # Landwelle -**Aktueller Stand: Landwelle v1.5.62** +**Aktueller Stand: Landwelle v1.5.75** -Landwelle ist das Go-basierte Radio- und Regionalportal von Landwelle mit öffentlicher Website, Adminbereich, PostgreSQL-Datenbank, Radio-App-API und internen Produktionswerkzeugen. Die produktive Zielplattform ist Linux ARM64 auf einem Raspberry Pi 5. +Landwelle ist das Go-basierte Radio- und Regionalportal von Landwelle mit öffentlicher Website, Adminbereich, PostgreSQL-Datenbank, Radio-App-API und internen Produktionswerkzeugen. Die neue Produktionszielplattform ist Linux x64 (x86_64/amd64); Raspberry Pi bleibt bis zur Umschaltung das Alt-/Fallbacksystem. ## Technische Basis @@ -52,11 +52,11 @@ go test ./... go vet ./... ``` -ARM64-Builds: +Linux-x64-Builds: ```bash -./scripts/build-pi.sh -./scripts/build-migrator-pi.sh +./scripts/build-x64.sh +./scripts/build-migrator-x64.sh ``` ## Produktives Update @@ -64,10 +64,10 @@ ARM64-Builds: Vor jedem Update PostgreSQL und persistente Uploads sichern. Migrationen werden vor dem Portalupdate ausgeführt, wenn neue Migrationsdateien hinzugekommen sind. ```bash -./scripts/build-migrator-pi.sh -sudo ./scripts/update-migrations-on-pi.sh -./scripts/build-pi.sh -sudo ./scripts/update-portal-on-pi.sh +./scripts/build-migrator-x64.sh +sudo ./scripts/update-migrations-on-x64.sh +./scripts/build-x64.sh +sudo ./scripts/update-portal-on-x64.sh ``` Prüfung: @@ -80,7 +80,7 @@ curl -fsS http://127.0.0.1:2200/ready ## GitHub und Releases -`main` ist der verbindliche Quellstand. Jede fachliche Änderung wird zusammen mit Versionsanpassung, `CHANGELOG.md` und den zugehörigen Tests committed. GitHub Actions prüft jeden Push und Pull Request mit `go test`, `go vet` und einem Linux-ARM64-Build. +`main` ist der verbindliche Quellstand. Jede fachliche Änderung wird zusammen mit Versionsanpassung, `CHANGELOG.md` und den zugehörigen Tests committed. GitHub Actions prüft jeden Push und Pull Request mit `go test`, `go vet` und einem Linux-x64-Build. Produktive Secrets, `.env`-Dateien, Firebase-Service-Accounts, Runtime-Daten, Build-Artefakte und Release-ZIPs gehören nicht ins Repository und sind über `.gitignore` ausgeschlossen. diff --git a/landwelle-github/docs/GITHUB_WORKFLOW.md b/landwelle-github/docs/GITHUB_WORKFLOW.md index b755a43..7821196 100644 --- a/landwelle-github/docs/GITHUB_WORKFLOW.md +++ b/landwelle-github/docs/GITHUB_WORKFLOW.md @@ -2,7 +2,7 @@ ## Grundsatz -GitHub `main` ist die verbindliche Quellcode-Basis. Produktive Änderungen werden nicht ausschließlich auf dem Server gepflegt. Änderungen werden zuerst als nachvollziehbarer Commit in GitHub abgelegt und anschließend auf dem Raspberry Pi gebaut bzw. ausgerollt. +GitHub `main` ist die verbindliche Quellcode-Basis. Produktive Änderungen werden nicht ausschließlich auf dem Server gepflegt. Änderungen werden zuerst als nachvollziehbarer Commit in GitHub abgelegt und anschließend auf dem Linux-x64-Server gebaut bzw. ausgerollt. ## Release-Ablauf @@ -37,7 +37,7 @@ Migrationen bleiben unveränderlich, sobald sie produktiv ausgeführt wurden. Ne - `go mod verify` - `go test ./...` - `go vet ./...` -- Linux-ARM64-Build für Portal, Migrator und Adminpass +- Linux-x64-Build für Portal, Migrator und Adminpass ## Abhängigkeiten diff --git a/main.go b/main.go index aba0dd0..6700570 100644 --- a/main.go +++ b/main.go @@ -37,7 +37,7 @@ const ( apiVersion = "v1" apiContractVersion = "1.0.0" applicationName = "Landwelle Radio" - applicationVersion = "1.5.74" + applicationVersion = "1.5.75" ) var publicTemplateFiles = []string{ diff --git a/main_test.go b/main_test.go index b3cae5f..579e664 100644 --- a/main_test.go +++ b/main_test.go @@ -181,7 +181,7 @@ func TestWeatherHelpers(t *testing.T) { } func TestApplicationVersion(t *testing.T) { - if applicationVersion != "1.5.74" { + if applicationVersion != "1.5.75" { t.Fatalf("unexpected application version %q", applicationVersion) } } diff --git a/scripts/build-migrator-x64.sh b/scripts/build-migrator-x64.sh new file mode 100755 index 0000000..56115c5 --- /dev/null +++ b/scripts/build-migrator-x64.sh @@ -0,0 +1,20 @@ +#!/usr/bin/env bash +set -euo pipefail + +ROOT="$(cd "$(dirname "${BASH_SOURCE[0]}")/.." && pwd)" +cd "$ROOT" + +if [[ "$(uname -s)" != "Linux" || "$(uname -m)" != "x86_64" ]]; then + echo "Für diesen x64-Schritt ist ein Linux-x86_64-Rechner erforderlich." >&2 + exit 1 +fi +mkdir -p dist +# Build darf go.mod/go.sum nicht automatisch verändern. +go mod download +go mod verify + +CGO_ENABLED=0 GOOS=linux GOARCH=amd64 GOAMD64=v1 \ + go build -trimpath -ldflags="-s -w" \ + -o dist/landwelle-migrate-linux-amd64 ./cmd/migrate + +echo "Erstellt: dist/landwelle-migrate-linux-amd64" diff --git a/scripts/build-x64.sh b/scripts/build-x64.sh new file mode 100755 index 0000000..368d267 --- /dev/null +++ b/scripts/build-x64.sh @@ -0,0 +1,55 @@ +#!/usr/bin/env bash +set -euo pipefail +ROOT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")/.." && pwd)" +mkdir -p "$ROOT_DIR/dist" +cd "$ROOT_DIR" + +if [[ "$(uname -s)" != "Linux" || "$(uname -m)" != "x86_64" ]]; then + echo "Für diesen x64-Schritt ist ein Linux-x86_64-Rechner erforderlich." >&2 + exit 1 +fi + +# Go compiles all .go files in the package directory, including untracked files. +# A stale local source (e.g. destination_one.go) can break an otherwise green CI. +# Refuse to build instead of silently deleting potentially valuable local work. +if git rev-parse --is-inside-work-tree >/dev/null 2>&1; then + EXTRA_GO="$(git ls-files --others --exclude-standard -- '*.go' | grep -E '^[^/]+\.go$' || true)" + if [[ -n "$EXTRA_GO" ]]; then + printf 'Build abgebrochen: nicht versionierte Go-Dateien im Projektverzeichnis:\n%s\n' "$EXTRA_GO" >&2 + echo "Bitte Dateien sichern und aus dem Projektverzeichnis verschieben, bevor du neu baust." >&2 + exit 1 + fi +fi + +# Startkritische ServeMux-Routen vor dem Build statisch prüfen. +# contentPages() registriert seine Slugs später dynamisch als "/"+slug. Deshalb +# reicht ein grep nach wörtlichen HandleFunc-Aufrufen nicht aus: Ein Slug darf +# nicht gleichzeitig explizit in main.go registriert sein. +EXPLICIT_PUBLIC_ROUTES="$(grep -oE 'mux\.HandleFunc\("/[^"]+"' main.go | sed -E 's/.*HandleFunc\("([^"]+)"/\1/' | sort -u)" +CONTENT_PAGE_SLUGS="$(sed -n '/^func contentPages()/,/^}/p' content.go | sed -nE 's/^[[:space:]]*"([^"]+)"[[:space:]]*:.*/\1/p')" +while IFS= read -r slug; do + [[ -z "$slug" ]] && continue + if grep -Fxq "/$slug" <<<"$EXPLICIT_PUBLIC_ROUTES"; then + printf 'Build abgebrochen: Route /%s wird sowohl explizit als auch dynamisch über contentPages() registriert.\n' "$slug" >&2 + exit 1 + fi +done <<<"$CONTENT_PAGE_SLUGS" + +# Alte Build-Artefakte vor einem neuen Build entfernen. So kann ein fehlgeschlagener +# Build niemals versehentlich ein altes Portal-Binary für das Update stehen lassen. +rm -f "$ROOT_DIR/dist/landwelle-portal-linux-amd64" "$ROOT_DIR/dist/landwelle-adminpass-linux-amd64" +go mod download +go mod verify +COMMIT="$(git rev-parse --short=12 HEAD 2>/dev/null || printf unknown)" +BUILD_TIME="$(date -u +%Y-%m-%dT%H:%M:%SZ)" +LDFLAGS="-s -w -X main.buildCommit=$COMMIT -X main.buildTime=$BUILD_TIME" +CGO_ENABLED=0 GOOS=linux GOARCH=amd64 GOAMD64=v1 go build -trimpath -ldflags="$LDFLAGS" -o dist/landwelle-portal-linux-amd64 . +CGO_ENABLED=0 GOOS=linux GOARCH=amd64 GOAMD64=v1 go build -trimpath -ldflags="-s -w" -o dist/landwelle-adminpass-linux-amd64 ./cmd/adminpass +SOURCE_VERSION="$(sed -nE 's/^[[:space:]]*applicationVersion[[:space:]]*=[[:space:]]*"([^"]+)".*/\1/p' main.go | head -n1)" +BUILT_VERSION="$("$ROOT_DIR/dist/landwelle-portal-linux-amd64" --version 2>/dev/null || true)" +if [[ -z "$SOURCE_VERSION" || "$BUILT_VERSION" != "Landwelle v$SOURCE_VERSION" ]]; then + printf 'Build abgebrochen: Binary-Version passt nicht zum Quellstand (Quelle: %s, Binary: %s).\n' "${SOURCE_VERSION:-unbekannt}" "${BUILT_VERSION:-unbekannt}" >&2 + rm -f "$ROOT_DIR/dist/landwelle-portal-linux-amd64" + exit 1 +fi +printf '%s\n' "x64-Portal erstellt: $ROOT_DIR/dist/landwelle-portal-linux-amd64" "Version: $BUILT_VERSION" "Commit: $COMMIT" "Build-Zeit: $BUILD_TIME" diff --git a/scripts/migrate.sh b/scripts/migrate.sh index 5390b2b..be6e3a5 100755 --- a/scripts/migrate.sh +++ b/scripts/migrate.sh @@ -4,7 +4,14 @@ set -euo pipefail PROJECT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")/.." && pwd)" cd "$PROJECT_DIR" -MIGRATOR="${MIGRATOR:-$PROJECT_DIR/dist/landwelle-migrate-linux-arm64}" +if [[ -z "${MIGRATOR:-}" ]]; then + case "$(uname -m)" in + x86_64) TARGET_ARCH="amd64" ;; + aarch64|arm64) TARGET_ARCH="arm64" ;; + *) echo "Nicht unterstützte CPU-Architektur: $(uname -m)" >&2; exit 1 ;; + esac + MIGRATOR="$PROJECT_DIR/dist/landwelle-migrate-linux-$TARGET_ARCH" +fi ENV_FILE="${ENV_FILE:-/etc/landwelle/landwelle.env}" if [[ ! -x "$MIGRATOR" ]]; then diff --git a/scripts/setup-admin-on-x64.sh b/scripts/setup-admin-on-x64.sh new file mode 100755 index 0000000..dbd9b97 --- /dev/null +++ b/scripts/setup-admin-on-x64.sh @@ -0,0 +1,60 @@ +#!/usr/bin/env bash +set -euo pipefail + +ENV_FILE="/etc/landwelle/landwelle.env" +HASHER="/opt/landwelle/landwelle-adminpass" +ADMIN_USER="${LANDWELLE_ADMIN_USER:-admin}" + +if [[ $EUID -ne 0 ]]; then + echo "Bitte mit sudo starten: sudo ./scripts/setup-admin-on-x64.sh" >&2 + exit 1 +fi +if [[ "$(uname -s)" != "Linux" || "$(uname -m)" != "x86_64" ]]; then + echo "Für diesen x64-Schritt ist ein Linux-x86_64-Rechner erforderlich." >&2 + exit 1 +fi +if [[ ! -x "$HASHER" ]]; then + echo "Passwortwerkzeug fehlt: $HASHER. Installiere zuerst v11 mit update-portal-on-x64.sh." >&2 + exit 1 +fi + +read -rsp "Neues Admin-Passwort (mindestens 12 Zeichen): " PASSWORD +echo +read -rsp "Admin-Passwort wiederholen: " PASSWORD_REPEAT +echo +if [[ "$PASSWORD" != "$PASSWORD_REPEAT" ]]; then + echo "Die Passwörter stimmen nicht überein." >&2 + exit 1 +fi + +HASH=$(LANDWELLE_NEW_ADMIN_PASSWORD="$PASSWORD" "$HASHER") +unset PASSWORD PASSWORD_REPEAT + +install -d -o root -g root -m 750 /etc/landwelle +touch "$ENV_FILE" +TMP=$(mktemp) +grep -vE '^(LANDWELLE_ADMIN_USER|LANDWELLE_ADMIN_PASSWORD|LANDWELLE_ADMIN_PASSWORD_HASH)=' "$ENV_FILE" > "$TMP" || true +{ + cat "$TMP" + echo + echo "# Landwelle Adminbereich" + echo "LANDWELLE_ADMIN_USER=$ADMIN_USER" + echo "LANDWELLE_ADMIN_PASSWORD_HASH=$HASH" + echo "LANDWELLE_ADMIN_SESSION_TTL=12h" +} > "$ENV_FILE" +rm -f "$TMP" +chown root:root "$ENV_FILE" +chmod 600 "$ENV_FILE" + +systemctl restart landwelle-radio +for _ in {1..20}; do + if curl -fsS http://127.0.0.1:2200/health >/dev/null 2>&1; then + echo "Adminzugang ist eingerichtet: /admin" + exit 0 + fi + sleep 1 +done + +echo "Dienst wurde nicht rechtzeitig bereit. Logs:" >&2 +journalctl -u landwelle-radio -n 80 --no-pager >&2 +exit 1 diff --git a/scripts/update-migrations-on-x64.sh b/scripts/update-migrations-on-x64.sh new file mode 100755 index 0000000..ea1fd83 --- /dev/null +++ b/scripts/update-migrations-on-x64.sh @@ -0,0 +1,103 @@ +#!/usr/bin/env bash +set -euo pipefail + +if [[ ${EUID} -ne 0 ]]; then + echo "Bitte mit sudo starten: sudo ./scripts/update-migrations-on-x64.sh" >&2 + exit 1 +fi + +if [[ "$(uname -s)" != "Linux" || "$(uname -m)" != "x86_64" ]]; then + echo "Für diesen x64-Schritt ist ein Linux-x86_64-Rechner erforderlich." >&2 + exit 1 +fi +ROOT="$(cd "$(dirname "${BASH_SOURCE[0]}")/.." && pwd)" +if [[ ! -f "$ROOT/dist/landwelle-migrate-linux-amd64" ]]; then + echo "Migrator fehlt: zuerst ./scripts/build-migrator-x64.sh starten." >&2 + exit 1 +fi +TARGET="${LANDWELLE_DIR:-/opt/landwelle}" +SERVICE="${LANDWELLE_SERVICE:-landwelle-radio}" +APP_USER="${LANDWELLE_USER:-landwelle}" +APP_GROUP="${LANDWELLE_GROUP:-landwelle}" +ENV_FILE="${LANDWELLE_ENV_FILE:-/etc/landwelle/landwelle.env}" + +if ! id "$APP_USER" >/dev/null 2>&1; then + echo "Systembenutzer $APP_USER existiert nicht." >&2 + exit 1 +fi + +if [[ ! -f "$ENV_FILE" ]]; then + echo "Konfiguration fehlt: $ENV_FILE" >&2 + exit 1 +fi + +if ! command -v psql >/dev/null 2>&1; then + echo "PostgreSQL-Client wird einmalig installiert ..." + apt-get update + DEBIAN_FRONTEND=noninteractive apt-get install -y postgresql-client +fi + +install -d -o root -g root -m 755 "$TARGET/dist" "$TARGET/scripts" +install -d -o "$APP_USER" -g "$APP_GROUP" -m 750 \ + "$TARGET/migrations" "$TARGET/migrations/applied" + +install -o root -g root -m 755 \ + "$ROOT/dist/landwelle-migrate-linux-amd64" \ + "$TARGET/dist/landwelle-migrate-linux-amd64" + +install -o root -g root -m 755 \ + "$ROOT/scripts/migrate.sh" \ + "$TARGET/scripts/migrate.sh" + +# Bereinigt die beiden kurzzeitig falsch nummerierten Landwelle-Zuhause-Dateien. +# 0039 und 0040 sind im produktiven Stand bereits durch andere Fachmigrationen belegt. +# Die konsolidierte Zuhause-Navigation verwendet deshalb die bereits eingeführte Nummer 9000. +rm -f \ + "$ROOT/migrations/0039_landwelle_zuhause_navigation.sql" \ + "$ROOT/migrations/0040_landwelle_zuhause_navigation.sql" \ + "$TARGET/migrations/0039_landwelle_zuhause_navigation.sql" \ + "$TARGET/migrations/0040_landwelle_zuhause_navigation.sql" + +shopt -s nullglob +migration_files=("$ROOT"/migrations/*.sql) +if (( ${#migration_files[@]} > 0 )); then + for migration in "${migration_files[@]}"; do + install -o "$APP_USER" -g "$APP_GROUP" -m 640 \ + "$migration" "$TARGET/migrations/$(basename "$migration")" + done +fi + +# Der Dienstbenutzer braucht Leserechte auf die Environment-Datei und +# Ausführungsrecht auf allen übergeordneten Verzeichnissen, um sie öffnen zu können. +ENV_DIR="$(dirname "$ENV_FILE")" +install -d -o root -g "$APP_GROUP" -m 750 "$ENV_DIR" +chown root:"$APP_GROUP" "$ENV_FILE" +chmod 640 "$ENV_FILE" + +if ! runuser -u "$APP_USER" -- test -r "$ENV_FILE"; then + echo "Environment-Datei ist für $APP_USER nicht lesbar: $ENV_FILE" >&2 + echo "Berechtigungen:" >&2 + namei -l "$ENV_FILE" >&2 || true + exit 1 +fi + +if ! grep -q '^DATABASE_URL=' "$ENV_FILE"; then + echo "DATABASE_URL fehlt in $ENV_FILE" >&2 + exit 1 +fi + +echo "Starte PostgreSQL-Migrationen ..." +runuser -u "$APP_USER" -- \ + "$TARGET/scripts/migrate.sh" \ + --env-file "$ENV_FILE" \ + --dir "$TARGET/migrations" \ + --archive-dir "$TARGET/migrations/applied" + +if systemctl list-unit-files "$SERVICE.service" >/dev/null 2>&1; then + systemctl restart "$SERVICE" + systemctl --no-pager --full status "$SERVICE" || true +fi + +echo +echo "Fertig. Erfolgreiche SQL-Dateien liegen unter:" +echo " $TARGET/migrations/applied" diff --git a/scripts/update-portal-on-x64.sh b/scripts/update-portal-on-x64.sh new file mode 100755 index 0000000..b0ccbc0 --- /dev/null +++ b/scripts/update-portal-on-x64.sh @@ -0,0 +1,141 @@ +#!/usr/bin/env bash +set -euo pipefail + +PROJECT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")/.." && pwd)" +SOURCE_BINARY="$PROJECT_DIR/dist/landwelle-portal-linux-amd64" +SOURCE_ADMINPASS="$PROJECT_DIR/dist/landwelle-adminpass-linux-amd64" +TARGET_DIR="/opt/landwelle" +TARGET_BINARY="$TARGET_DIR/landwelle-portal" +SOURCE_SERVICE="$PROJECT_DIR/deploy/landwelle-radio.service" +TARGET_SERVICE="/etc/systemd/system/landwelle-radio.service" +SERVICE="landwelle-radio" + +if [[ $EUID -ne 0 ]]; then + echo "Bitte mit sudo starten: sudo ./scripts/update-portal-on-x64.sh" >&2 + exit 1 +fi + +if [[ "$(uname -s)" != "Linux" || "$(uname -m)" != "x86_64" ]]; then + echo "Für diesen x64-Schritt ist ein Linux-x86_64-Rechner erforderlich." >&2 + exit 1 +fi + +if [[ ! -f "$SOURCE_BINARY" ]]; then + echo "x64-Binary fehlt: $SOURCE_BINARY" >&2 + exit 1 +fi +EXPECTED_VERSION="$($SOURCE_BINARY --version 2>/dev/null || true)" +if [[ -z "$EXPECTED_VERSION" ]]; then + echo "Version der x64-Binary konnte nicht ermittelt werden: $SOURCE_BINARY" >&2 + exit 1 +fi + +SOURCE_VERSION="$(sed -nE 's/^[[:space:]]*applicationVersion[[:space:]]*=[[:space:]]*"([^"]+)".*/\1/p' "$PROJECT_DIR/main.go" | head -n1)" +if [[ -z "$SOURCE_VERSION" ]]; then + echo "Quellversion konnte nicht aus $PROJECT_DIR/main.go ermittelt werden." >&2 + exit 1 +fi +if [[ "$EXPECTED_VERSION" != "Landwelle v$SOURCE_VERSION" ]]; then + echo "Update abgebrochen: dist-Binary ist veraltet oder stammt aus einem anderen Quellstand." >&2 + echo "Quellstand: Landwelle v$SOURCE_VERSION" >&2 + echo "dist-Binary: $EXPECTED_VERSION" >&2 + echo "Bitte zuerst ausführen: ./scripts/build-x64.sh" >&2 + exit 1 +fi + +if [[ ! -f "$SOURCE_ADMINPASS" ]]; then + echo "Admin-Passwortwerkzeug fehlt: $SOURCE_ADMINPASS" >&2 + exit 1 +fi + +install -d -o root -g root -m 755 "$TARGET_DIR" +install -d -o landwelle -g landwelle -m 750 /var/lib/landwelle + +BACKUP_BINARY="" +BACKUP_SERVICE="" +BACKUP_ADMINPASS="" +STAMP="$(date +%Y%m%d-%H%M%S)" +if [[ -f "$TARGET_BINARY" ]]; then + BACKUP_BINARY="$TARGET_BINARY.backup-$STAMP" + cp -a "$TARGET_BINARY" "$BACKUP_BINARY" +fi +if [[ -f "$TARGET_SERVICE" ]]; then + BACKUP_SERVICE="$TARGET_SERVICE.backup-$STAMP" + cp -a "$TARGET_SERVICE" "$BACKUP_SERVICE" +fi +if [[ -f "$TARGET_DIR/landwelle-adminpass" ]]; then + BACKUP_ADMINPASS="$TARGET_DIR/landwelle-adminpass.backup-$STAMP" + cp -a "$TARGET_DIR/landwelle-adminpass" "$BACKUP_ADMINPASS" +fi + +DEPLOY_STARTED=0 +rollback_if_needed() { + result=$? + trap - EXIT + if [[ "$result" -ne 0 && "$DEPLOY_STARTED" -eq 1 ]]; then + echo "Update fehlgeschlagen (Exit-Code $result). Starte automatisches Rollback." >&2 + set +e + systemctl stop "$SERVICE" + if [[ -n "$BACKUP_BINARY" && -f "$BACKUP_BINARY" ]]; then + install -o root -g root -m 755 "$BACKUP_BINARY" "$TARGET_BINARY" + else + rm -f "$TARGET_BINARY" + fi + if [[ -n "$BACKUP_ADMINPASS" && -f "$BACKUP_ADMINPASS" ]]; then + install -o root -g root -m 755 "$BACKUP_ADMINPASS" "$TARGET_DIR/landwelle-adminpass" + fi + if [[ -n "$BACKUP_SERVICE" && -f "$BACKUP_SERVICE" ]]; then + install -o root -g root -m 644 "$BACKUP_SERVICE" "$TARGET_SERVICE" + else + rm -f "$TARGET_SERVICE" + fi + rm -f "$TARGET_BINARY.new" + systemctl daemon-reload + if [[ -n "$BACKUP_BINARY" && -f "$BACKUP_BINARY" ]]; then + systemctl start "$SERVICE" + if curl -fsS --max-time 5 http://127.0.0.1:2200/ready >/dev/null 2>&1; then + echo "Rollback erfolgreich: vorherige Version ist wieder bereit." >&2 + else + echo "ACHTUNG: Vorherige Version ist noch nicht bereit. Bitte 'journalctl -u landwelle-radio' prüfen." >&2 + fi + else + echo "ACHTUNG: Kein vorheriges Portal-Binary vorhanden. Manueller Eingriff erforderlich." >&2 + fi + fi + exit "$result" +} +trap rollback_if_needed EXIT +DEPLOY_STARTED=1 + +if [[ -f "$SOURCE_SERVICE" ]]; then + install -o root -g root -m 644 "$SOURCE_SERVICE" "$TARGET_SERVICE" + systemctl daemon-reload +fi + +systemctl stop "$SERVICE" +install -o root -g root -m 755 "$SOURCE_BINARY" "$TARGET_BINARY.new" +mv -f "$TARGET_BINARY.new" "$TARGET_BINARY" +install -o root -g root -m 755 "$SOURCE_ADMINPASS" "$TARGET_DIR/landwelle-adminpass" +systemctl start "$SERVICE" + +for _ in {1..20}; do + if curl -fsS --max-time 5 http://127.0.0.1:2200/ready >/dev/null 2>&1; then + ACTIVE_VERSION="$(curl -fsS --max-time 5 http://127.0.0.1:2200/version 2>/dev/null | tr -d '\r\n' || true)" + if [[ "$ACTIVE_VERSION" != "$EXPECTED_VERSION" ]]; then + echo "Versionsprüfung fehlgeschlagen: erwartet $EXPECTED_VERSION, aktiv $(printf '%s' "$ACTIVE_VERSION")" >&2 + journalctl -u "$SERVICE" -n 80 --no-pager >&2 || true + exit 1 + fi + DEPLOY_STARTED=0 + echo "$ACTIVE_VERSION ist aktiv: http://127.0.0.1:2200" + if ! grep -qE '^LANDWELLE_ADMIN_PASSWORD(_HASH)?=' /etc/landwelle/landwelle.env 2>/dev/null; then + echo "Adminzugang noch einrichten: sudo ./scripts/setup-admin-on-x64.sh" + fi + exit 0 + fi + sleep 1 +done + +echo "Readiness-Check fehlgeschlagen." >&2 +journalctl -u "$SERVICE" -n 80 --no-pager >&2 || true +exit 1