Files
landwelle/scripts/build-x64.sh
T
OpenGenesis (MPL 2.0) 2ed47e77b5 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
2026-11-07 15:23:52 +01:00

56 lines
3.2 KiB
Bash
Executable File

#!/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"