Files
Heimdall/install/install-server.sh
T
arnaud.dartois 24a2400610
Heimdall Gitea / Detect CI scope (push) Successful in 5s
Heimdall Gitea / Build and tests (push) Successful in 18m50s
Heimdall Gitea / Build and scan agent image (push) Skipped
Heimdall Gitea / Build and scan NVIDIA Agent image (push) Skipped
Heimdall Gitea / Build and scan server image (push) Successful in 9m14s
Heimdall Gitea / Publish versioned installer release (push) Skipped
Heimdall Gitea / CI policy (push) Successful in 1s
ci(release): publish versioned installer bundles (#315)
Refs #314

## Résumé

- Réduit les builds d’images aux graphes réellement touchés; les PR ne publient aucune image. Les pushes `main` publient seulement les images affectées sur Docker Hub; un tag semver produit la version et les tags d’images.
- Le job de release réutilise les images déjà vérifiées. Gitea reçoit le ZIP Central versionné et les seuls assets nécessaires aux mises à jour Agent signées, sans couches Docker, archive serveur ou métadonnées internes CI.
- Les installateurs Central `.sh` et `.ps1` résolvent une release stable, vérifient le digest du ZIP et exécutent le script épinglé à cette version. La simulation offline couvre le bootstrap Linux et le bundle contient les scripts Windows versionnés.
- Aligne l’IHM et la maquette Penpot sur les choix Linux/Windows/Docker, commandes copiables et état de release indisponible. Ajoute les skills de synchronisation UI/Penpot, avec ouverture et authentification Penpot obligatoires dans Orca.

## Validation locale

- La CI restaure toujours la solution en mode verrouillé pour l’audit NuGet, puis ne compile que les projets de tests concernés et les projets source affectés non couverts par ces tests. Les changements globaux gardent le build complet. Le plan Agent/Web est couvert par les contrats CI.

- `python3 scripts/ci/test_ci.py` : 27 tests OK (publication offline, sélection conditionnelle des images, parseur PowerShell si disponible).
- `dotnet test tests/Heimdall.Web.Tests/Heimdall.Web.Tests.csproj --filter FullyQualifiedName~SiteDetailTests --no-restore` : 12 tests OK.
- `bash -n` sur les scripts shell modifiés, parseur PowerShell sur `install/install-server.ps1`, et `git diff --check` : OK.
- Recette Compose construite depuis la source : healthz 200, racine non authentifiée 302, endpoint release sans configuration 502. Projet et tag d’image uniques supprimés puis absence vérifiée.
- Simulation release offline : bundle versionné, digest, signature ECDSA, set exact de 7 assets Gitea et absence de rebuild d’images dans le job de publication.

## CI distante

- CI Gitea du commit `da89cdff2d8c2a7a9339bfc8640502ede9c6d739` : run #880 entièrement vert; tests .NET/E2E, build et scan serveur OK; builds Agent CPU/GPU et publication release ignorés sur cette PR.

## Limites

Pas de vrai run de tag, de publication Docker Hub/Gitea, de runner distant ni d’installation Windows sur hôte réel. Les secrets de publication restent requis seulement pour les événements de publication. L’issue #314 reste ouverte pour ces preuves externes et ne doit pas être fermée par cette PR.

## Maquette

Maquette Heimdall Penpot mise à jour : https://penpot.tordais.cc/#/workspace?team-id=073c6639-4451-8006-8008-e66329727382&file-id=aadb42b1-1e8d-8014-8008-7dc15de6e3ff&page-id=127dfd1c-12b5-80f7-8008-79c6fda854a1

Reviewed-on: #315
Co-authored-by: Arnaud Dartois <admin@tordais.cc>
2026-11-09 17:06:36 +01:00

312 lines
12 KiB
Bash
Executable File
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
#!/usr/bin/env bash
set -euo pipefail
SCRIPT_PATH="${BASH_SOURCE[0]:-}"
SCRIPT_DIR=""
if [[ -n "$SCRIPT_PATH" ]]; then
SCRIPT_DIR="$(cd -- "$(dirname -- "$SCRIPT_PATH")" && pwd)"
fi
readonly SOURCE_BASE_URL="${HEIMDALL_SOURCE_BASE_URL:-https://sources.tordais.cc/arnaud.dartois/Heimdall/raw/branch/main}"
readonly PACKAGE_RELEASE_VERSION="unversioned"
readonly RELEASE_API_URL="${HEIMDALL_RELEASE_API_URL:-https://sources.tordais.cc/api/v1/repos/arnaud.dartois/Heimdall/releases}"
REPO_ROOT=""
if [[ -n "$SCRIPT_DIR" && -f "${SCRIPT_DIR}/../docker/docker-compose.ollama.yml" ]]; then
REPO_ROOT="$(cd -- "${SCRIPT_DIR}/.." && pwd)"
fi
say() { printf '%s\n' "$*"; }
ask() {
local prompt="$1" default="$2" answer
if [[ -r /dev/tty && -w /dev/tty ]]; then
read -r -p "${prompt} [${default}] " answer </dev/tty
else
read -r -p "${prompt} [${default}] " answer
fi
printf '%s' "${answer:-$default}"
}
if [[ ! -t 0 && (! -r /dev/tty || ! -w /dev/tty) ]]; then
echo "Ce script nécessite un terminal interactif." >&2
exit 2
fi
for command in docker openssl curl jq unzip; do
command -v "$command" >/dev/null || { echo "Commande requise absente : $command" >&2; exit 1; }
done
docker compose version >/dev/null
# A raw-branch bootstrap resolves the latest stable installer bundle, then
# re-enters the version-pinned script contained in that bundle. Packaged copies
# already carry their version and never resolve a moving release again.
installer_version="$PACKAGE_RELEASE_VERSION"
if [[ "$PACKAGE_RELEASE_VERSION" == unversioned ]]; then
release_api="$RELEASE_API_URL/latest"
if [[ -n "${HEIMDALL_INSTALLER_VERSION:-}" ]]; then
installer_version="$HEIMDALL_INSTALLER_VERSION"
[[ "$installer_version" =~ ^[0-9]+\.[0-9]+\.[0-9]+([.-][0-9A-Za-z.-]+)?$ ]] || {
echo 'Version Heimdall invalide.' >&2; exit 1;
}
release_api="$RELEASE_API_URL/tags/$installer_version"
fi
bootstrap_dir="$(mktemp -d "${TMPDIR:-/tmp}/heimdall-installer.XXXXXX")"
cleanup_bootstrap() { rm -rf -- "$bootstrap_dir"; }
trap cleanup_bootstrap EXIT
if ! curl --fail --silent --show-error --location "$release_api" --output "$bootstrap_dir/release.json"; then
echo 'Impossible de récupérer la dernière release Heimdall.' >&2; exit 1
fi
resolved_version="$(jq -er '.tag_name | select(type == "string" and test("^[0-9]+\\.[0-9]+\\.[0-9]+([.-][0-9A-Za-z.-]+)?$"))' "$bootstrap_dir/release.json")" || {
echo 'La release Heimdall retournée a une version invalide.' >&2; exit 1;
}
installer_asset="heimdall-installers-$resolved_version.zip"
asset_json="$(jq -ce --arg name "$installer_asset" '.assets[] | select(.name == $name)' "$bootstrap_dir/release.json")" || {
echo 'La release ne contient pas son bundle d’installation versionné.' >&2; exit 1;
}
installer_url="$(jq -er '.browser_download_url | select(startswith("https://"))' <<<"$asset_json")" || {
echo 'URL HTTPS du bundle d’installation invalide.' >&2; exit 1;
}
expected_sha256="$(jq -er '.digest | select(test("^sha256:[A-Fa-f0-9]{64}$")) | sub("^sha256:"; "")' <<<"$asset_json")" || {
echo 'La release ne fournit pas le SHA-256 du bundle.' >&2; exit 1;
}
curl --fail --silent --show-error --location "$installer_url" --output "$bootstrap_dir/installers.zip"
actual_sha256="$(sha256sum "$bootstrap_dir/installers.zip" | cut -d ' ' -f 1)"
[[ "${actual_sha256,,}" == "${expected_sha256,,}" ]] || { echo 'Le SHA-256 du bundle téléchargé ne correspond pas à la release.' >&2; exit 1; }
unzip -q "$bootstrap_dir/installers.zip" -d "$bootstrap_dir/bundle"
packaged_script="$bootstrap_dir/bundle/install/install-server.sh"
[[ -f "$packaged_script" ]] || { echo 'Le bundle ne contient pas install/install-server.sh.' >&2; exit 1; }
HEIMDALL_INSTALLER_VERSION="$resolved_version" bash "$packaged_script" "$@"
exit $?
fi
copy_source_asset() {
local relative_path="$1" destination_path="$2" asset_tmp="${2}.tmp.$$"
if [[ -n "$REPO_ROOT" && -f "$REPO_ROOT/$relative_path" ]]; then
cp "$REPO_ROOT/$relative_path" "$asset_tmp"
else
if ! curl --fail --silent --show-error --location \
"$SOURCE_BASE_URL/$relative_path" --output "$asset_tmp"; then
rm -f "$asset_tmp"
return 1
fi
fi
if [[ -e "$destination_path" ]]; then
cp -p "$destination_path" "$destination_path.bak.$(date -u +%Y%m%dT%H%M%SZ)"
fi
mv -f "$asset_tmp" "$destination_path"
}
say "Installation de Heimdall Central (serveur + PostgreSQL)."
destination="$(ask 'Dossier d’installation' "$HOME/heimdall")"
compose_path="$destination/docker-compose.yml"
env_path="$destination/.env"
is_existing=no
if [[ -e "$compose_path" || -e "$env_path" ]]; then
if [[ ! -f "$compose_path" || ! -f "$env_path" || ! -f "$destination/secrets/db_password" ]]; then
echo "Installation existante incomplète; aucun fichier n’a été modifié." >&2
exit 1
fi
if [[ "$(ask 'Installation existante : mettre à jour le Compose (sauvegarde du précédent), en conservant .env, secrets et volumes ?' 'o')" =~ ^([nN]|[nN][oO][nN]?)$ ]]; then
say "Installation laissée inchangée."
exit 0
fi
is_existing=yes
else
web_port="$(ask 'Port HTTP du serveur' '5000')"
cors_origin="$(ask 'Origine(s) autorisée(s) par CORS' '*')"
[[ "$web_port" =~ ^[0-9]{1,5}$ ]] && (( web_port >= 1 && web_port <= 65535 )) || { echo "Port invalide." >&2; exit 1; }
[[ "$cors_origin" =~ ^[A-Za-z0-9*.,:/_-]+$ ]] || { echo "Origine CORS invalide." >&2; exit 1; }
fi
mkdir -p "$destination/secrets" "$destination/optional" "$destination/optional/secrets"
chmod 700 "$destination" "$destination/secrets" "$destination/optional"
if [[ "$is_existing" == no ]]; then
db_password="$(openssl rand -hex 32)"
jwt_key="$(openssl rand -hex 32)"
jwt_refresh_key="$(openssl rand -hex 32)"
printf '%s' "$db_password" > "$destination/secrets/db_password"
chmod 600 "$destination/secrets/db_password"
cat > "$env_path" <<EOF
POSTGRES_DB=heimdall
POSTGRES_USER=heimdall
DATABASE_URL=Host=postgresql;Port=5432;Database=heimdall;Username=heimdall;Password=${db_password}
JWT__KEY=${jwt_key}
JWT__REFRESHKEY=${jwt_refresh_key}
JWT__ISSUER=heimdall
JWT__AUDIENCE=heimdall-api
ASPNETCORE_ENVIRONMENT=Production
WEB_PORT=${web_port}
Cors__AllowedOrigins=${cors_origin}
TZ=Europe/Paris
REDIS_PASSWORD=$(openssl rand -hex 32)
HEIMDALL_DATA_VOLUME=heimdall_heimdall_data
PLATE_OCR_ENABLED=false
EOF
chmod 600 "$env_path"
else
ensure_env_value() {
local key="$1" value="$2"
if ! grep -q "^${key}=" "$env_path"; then
printf '\n%s=%s\n' "$key" "$value" >> "$env_path"
fi
}
if ! grep -q '^DATABASE_URL=' "$env_path"; then
echo "DATABASE_URL est absent du .env existant; complète-le sans changer le mot de passe PostgreSQL avant de relancer." >&2
exit 1
fi
ensure_env_value JWT__KEY "$(openssl rand -hex 32)"
ensure_env_value JWT__REFRESHKEY "$(openssl rand -hex 32)"
ensure_env_value POSTGRES_DB heimdall
ensure_env_value POSTGRES_USER heimdall
ensure_env_value JWT__ISSUER heimdall
ensure_env_value JWT__AUDIENCE heimdall-api
ensure_env_value ASPNETCORE_ENVIRONMENT Production
ensure_env_value WEB_PORT 5000
ensure_env_value Cors__AllowedOrigins '*'
ensure_env_value TZ Europe/Paris
ensure_env_value REDIS_PASSWORD "$(openssl rand -hex 32)"
ensure_env_value HEIMDALL_DATA_VOLUME heimdall_heimdall_data
ensure_env_value PLATE_OCR_ENABLED false
chmod 600 "$env_path"
fi
compose_tmp="$(mktemp "$destination/.docker-compose.yml.XXXXXX")"
trap 'rm -f "${compose_tmp:-}"' EXIT
cat > "$compose_tmp" <<'COMPOSE'
name: heimdall
services:
postgresql:
image: postgres:17-alpine
pull_policy: always
environment:
POSTGRES_DB: ${POSTGRES_DB}
POSTGRES_USER: ${POSTGRES_USER}
POSTGRES_PASSWORD_FILE: /run/secrets/db_password
secrets: [db_password]
volumes: [pgdata:/var/lib/postgresql/data]
healthcheck:
test: ["CMD-SHELL", "pg_isready -U $${POSTGRES_USER} -d $${POSTGRES_DB}"]
interval: 10s
timeout: 5s
retries: 5
start_period: 30s
restart: unless-stopped
networks: [heimdall-net]
heimdall:
image: eltruncho/heimdall:latest
pull_policy: always
labels:
com.centurylinklabs.watchtower.enable: "true"
environment:
DATABASE_URL: ${DATABASE_URL:?missing DATABASE_URL}
JWT__Issuer: ${JWT__ISSUER}
JWT__Audience: ${JWT__AUDIENCE}
JWT__KEY: ${JWT__KEY:?missing JWT__KEY}
JWT__REFRESHKEY: ${JWT__REFRESHKEY:?missing JWT__REFRESHKEY}
ASPNETCORE_ENVIRONMENT: ${ASPNETCORE_ENVIRONMENT}
ASPNETCORE_URLS: http://+:8080
Cors__AllowedOrigins: ${Cors__AllowedOrigins}
PlateOcr__Enabled: ${PLATE_OCR_ENABLED:-false}
ports: ["${WEB_PORT}:8080"]
volumes:
- heimdall_data:/var/lib/heimdall
- heimdall_data:/app/data
depends_on:
postgresql:
condition: service_healthy
healthcheck:
test: ["CMD", "wget", "--no-verbose", "--tries=1", "--output-document=/dev/null", "http://127.0.0.1:8080/healthz"]
interval: 30s
timeout: 10s
retries: 3
start_period: 60s
restart: unless-stopped
networks: [heimdall-net]
watchtower:
image: nickfedor/watchtower:1.23.2
pull_policy: always
command: ["--cleanup", "--label-enable", "--interval", "86400"]
volumes:
- /var/run/docker.sock:/var/run/docker.sock
restart: unless-stopped
networks: [heimdall-net]
volumes:
pgdata:
heimdall_data:
secrets:
db_password:
file: ./secrets/db_password
networks:
heimdall-net:
name: heimdall-net
driver: bridge
COMPOSE
chmod 600 "$compose_tmp"
docker compose --env-file "$env_path" -f "$compose_tmp" config --quiet
if [[ "$is_existing" == yes ]]; then
backup_path="$compose_path.bak.$(date -u +%Y%m%dT%H%M%SZ)"
cp -p "$compose_path" "$backup_path"
say "Ancien Compose sauvegardé dans $backup_path"
fi
mv -f "$compose_tmp" "$compose_path"
compose_tmp=""
trap - EXIT
declare -a selected=()
for service in ollama ntfy rustfs coturn redis backup; do
if [[ "$service" == backup ]]; then
prompt="Activer les sauvegardes planifiées (nécessite une configuration dédiée) ?"
else
prompt="Installer le service optionnel ${service} ?"
fi
if [[ "$(ask "$prompt" 'n')" =~ ^([oO]|[oO][uU][iI]|[yY]|[yY][eE][sS])$ ]]; then
selected+=("$service")
copy_source_asset "docker/docker-compose.${service}.yml" \
"$destination/optional/docker-compose.${service}.yml"
chmod 600 "$destination/optional/docker-compose.${service}.yml"
fi
done
say "Compose généré dans $destination/docker-compose.yml"
say "Variables protégées dans $destination/.env (mode 600), secret PostgreSQL dans secrets/ (mode 600)."
say "Validation du Compose avant démarrage…"
start_core=no
if [[ "$(ask 'Démarrer PostgreSQL et Heimdall maintenant ?' 'o')" =~ ^([oO]|[oO][uU][iI]|[yY]|[yY][eE][sS])$ ]]; then
docker compose --env-file "$env_path" -f "$compose_path" up -d
start_core=yes
fi
for service in "${selected[@]}"; do
case "$service" in
rustfs)
printf '%s' "heimdall$(openssl rand -hex 8)" > "$destination/optional/secrets/rustfs_access_key"
openssl rand -hex 32 > "$destination/optional/secrets/rustfs_secret_key"
chmod 600 "$destination/optional/secrets/rustfs_access_key" "$destination/optional/secrets/rustfs_secret_key"
;;
coturn)
openssl rand -hex 32 > "$destination/optional/secrets/coturn_secret"
chmod 600 "$destination/optional/secrets/coturn_secret"
;;
backup)
mkdir -p "$destination/optional/scripts"
for script_name in backup.sh backup-protected-data.sh backup-rustfs.sh restore.sh restore-protected-data.sh; do
copy_source_asset "docker/scripts/$script_name" \
"$destination/optional/scripts/$script_name"
done
chmod 700 "$destination/optional/scripts" "$destination/optional/scripts"/*.sh
cp "$destination/secrets/db_password" "$destination/optional/secrets/db_password"
chmod 600 "$destination/optional/secrets/db_password"
;;
esac
if [[ "$start_core" == yes ]] && [[ "$(ask "Démarrer le service optionnel ${service} ?" 'o')" =~ ^([oO]|[oO][uU][iI]|[yY]|[yY][eE][sS])$ ]]; then
docker compose --project-name "heimdall-${service}" --env-file "$destination/.env" \
-f "$destination/optional/docker-compose.${service}.yml" up -d
else
say "Service ${service} préparé dans $destination/optional/."
fi
done
say "Configurez ensuite les intégrations activées depuis les paramètres de Central; leurs valeurs restent gérées par l’IHM."