Bouton "Tout mettre a jour" : mise a jour globale de toutes les stacks

- POST /api/update-all (administrateur) : toutes les stacks de tous les
  serveurs actifs, hors exclues et arretees, en mode autoapply (pull, puis
  down + up -d seulement si une image a change) ; serveurs en parallele,
  stacks d'un meme serveur une par une ; 409 si deja en cours
- etat en memoire expose dans /api/fleet (updateAll : progression, resultats)
- interface : bouton dans la barre du haut (progression n/total), dialogue de
  lancement avec le resultat par stack, echecs en tete
- hostJobsLocked/applyAndWait/tally factorises avec la planification serveur

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01LNfwm2CJxCZs4b8wVW7zkh
This commit is contained in:
claude BotandClaude Opus 5.5 committed 2026-11-27 13:10:17 +01:00
1 parent eac873266c
commit b5aad6dbd3
9 files changed
+365 -29

No files matched your search

+14 -4
View File
@@ -2,11 +2,12 @@ import { useCallback, useEffect, useRef, useState } from "react";
import { api, type Fleet, type Me } from "./api";
import { ActionMenu } from "./ActionMenu";
import { FleetView } from "./FleetView";
import { UpdateAllDialog } from "./AutoUpdate";
import { KeyDialog, ServerDialog } from "./ServerDialog";
import { Login } from "./Login";
import { SettingsDialog } from "./SettingsDialog";
import { initials } from "./format";
import { LogoutIcon, MenuIcon, MoonIcon, PlusIcon, RefreshIcon, ServerIcon, SettingsIcon, ShieldIcon, StackIcon, SunIcon, UserIcon, UsersIcon, KeyIcon } from "./icons";
import { CloudUpIcon, LogoutIcon, MenuIcon, MoonIcon, PlusIcon, RefreshIcon, ServerIcon, SettingsIcon, ShieldIcon, StackIcon, SunIcon, UserIcon, UsersIcon, KeyIcon } from "./icons";
type Theme = "light" | "dark";
@@ -68,6 +69,7 @@ function Shell({ me, reloadMe }: { me: Me; reloadMe: () => Promise<unknown> }) {
const [userMenu, setUserMenu] = useState<HTMLElement | null>(null);
const [serverDialog, setServerDialog] = useState<{ id?: string } | null>(null);
const [keyDialog, setKeyDialog] = useState(false);
const [updateAllDialog, setUpdateAllDialog] = useState(false);
const title = me.title || "Stackwatch";
const user = me.user!;
@@ -97,7 +99,8 @@ function Shell({ me, reloadMe }: { me: Me; reloadMe: () => Promise<unknown> }) {
);
// Rafraîchissement : rapide pendant une analyse, lent sinon.
const busy = !!fleet && fleet.summary.scanning > 0;
const updating = !!fleet?.updateAll?.running;
const busy = !!fleet && (fleet.summary.scanning > 0 || updating);
const loadRef = useRef(load);
loadRef.current = load;
useEffect(() => {
@@ -156,9 +159,15 @@ function Shell({ me, reloadMe }: { me: Me; reloadMe: () => Promise<unknown> }) {
</a>
<div className="topbar-tools">
<button className="ex-btn" onClick={() => run(api.checkAll)} disabled={!servers.length || busy} title="Analyser tous les serveurs">
<RefreshIcon className={busy ? "spin" : ""} />
<span className="hide-sm">{busy ? "Analyse…" : "Tout vérifier"}</span>
<RefreshIcon className={busy && !updating ? "spin" : ""} />
<span className="hide-sm">{busy && !updating ? "Analyse…" : "Tout vérifier"}</span>
</button>
{me.admin && (
<button className="ex-btn" onClick={() => setUpdateAllDialog(true)} disabled={!servers.length} title="Mettre a jour toutes les stacks de tous les serveurs (hors exclues et arretees)">
{updating ? <RefreshIcon className="spin" /> : <CloudUpIcon />}
<span className="hide-sm">{updating ? `Mise à jour ${fleet?.updateAll?.done ?? 0}/${fleet?.updateAll?.total ?? 0}…` : "Tout mettre à jour"}</span>
</button>
)}
<button className="icon-btn" onClick={() => setTheme(theme === "dark" ? "light" : "dark")} aria-label={theme === "dark" ? "Thème clair" : "Thème sombre"} title={theme === "dark" ? "Thème clair" : "Thème sombre"}>
{theme === "dark" ? <SunIcon /> : <MoonIcon />}
</button>
@@ -264,6 +273,7 @@ function Shell({ me, reloadMe }: { me: Me; reloadMe: () => Promise<unknown> }) {
)}
{settings && <SettingsDialog me={me} initialTab={settings} onClose={() => setSettings(null)} onChanged={reloadMe} />}
{updateAllDialog && <UpdateAllDialog status={fleet?.updateAll} onClose={() => setUpdateAllDialog(false)} onStart={() => run(api.updateAll)} />}
{keyDialog && fleet && <KeyDialog publicKey={fleet.publicKey ?? ""} onClose={() => setKeyDialog(false)} />}
{serverDialog && (
<ServerDialog
+69 -2
View File
@@ -1,9 +1,9 @@
// Mises a jour automatiques programmees (crontab) : par stack (detail de la
// stack) et globale par serveur (dialogue du serveur), badges et vue de suivi.
import { useEffect, useState, type ReactNode } from "react";
import { api, type AutoInfo, type HostAutoInfo, type Me, type Scan, type Server, type Stack, type Target } from "./api";
import { api, type AutoInfo, type HostAutoInfo, type UpdateAll, type Me, type Scan, type Server, type Stack, type Target } from "./api";
import { fmtDate, fmtRelative } from "./format";
import { CheckIcon, ClockIcon, RefreshIcon, WarningIcon } from "./icons";
import { CheckIcon, ClockIcon, CloudUpIcon, RefreshIcon, WarningIcon } from "./icons";
export const AUTO_PRESETS: [string, string][] = [
["0 4 * * *", "Chaque nuit a 4 h"],
@@ -192,6 +192,73 @@ export function AutoEditor({ stack, busy, tz, hostSchedule, onSave }: EditorProp
);
}
interface UpdateAllProps {
status?: UpdateAll;
onStart: () => void;
onClose: () => void;
}
/** Mise a jour de toutes les stacks de tous les serveurs : confirmation, progression et dernier resultat. */
export function UpdateAllDialog({ status, onStart, onClose }: UpdateAllProps) {
useEffect(() => {
const onKey = (e: KeyboardEvent) => e.key === "Escape" && onClose();
window.addEventListener("keydown", onKey);
return () => window.removeEventListener("keydown", onKey);
}, [onClose]);
const running = !!status?.running;
const results = [...(status?.results ?? [])].sort((a, b) => Number(a.ok) - Number(b.ok) || Number(!!a.skipped) - Number(!!b.skipped) || a.server.localeCompare(b.server) || a.name.localeCompare(b.name));
return (
<div className="modal-backdrop" onClick={onClose}>
<div className="modal" role="dialog" aria-modal="true" aria-label="Mettre a jour toutes les stacks" onClick={(e) => e.stopPropagation()}>
<h3>Mettre a jour toutes les stacks</h3>
<div className="modal-text">
<p className="muted small-text">
Toutes les stacks de tous les serveurs actifs sont mises a jour : pull, puis down + up -d seulement si une image a change. Les serveurs sont traites en parallele, les stacks d'un meme serveur
une par une. Sont ignorees : les stacks exclues et les stacks arretees.
</p>
{status && (
<div className="small-text">
{running ? (
<span className="status-pill st-applying">
<RefreshIcon size={13} className="spin" /> En cours : {status.done}/{status.total} stack(s)
</span>
) : (
<span className={`auto-last ${status.ok ? "ok" : "ko"}`}>
{status.ok ? <CheckIcon size={13} /> : <WarningIcon size={13} />}
<span>
Derniere execution {fmtRelative(status.finished ?? status.started)}
{status.by ? ` (${status.by})` : ""}
{status.message ? ` : ${status.message}` : ""}
</span>
</span>
)}
</div>
)}
{results.length > 0 && (
<ul className="auto-results small-text">
{results.map((r) => (
<li key={`${r.serverId}:${r.target}:${r.dir}`} className={r.ok ? (r.skipped ? "muted" : "ok") : "ko"}>
{r.ok ? <CheckIcon size={12} /> : <WarningIcon size={12} />} <strong>{r.server}</strong> / <strong>{r.name}</strong> <span className="muted">({r.user})</span> : {r.message}
</li>
))}
</ul>
)}
</div>
<div className="modal-actions">
<span className="spacer" />
<button onClick={onClose}>Fermer</button>
<button className="primary" disabled={running} onClick={onStart}>
<CloudUpIcon />
Lancer
</button>
</div>
</div>
</div>
);
}
interface HostDialogProps {
server: Server;
tz?: string;
+24
View File
@@ -116,6 +116,25 @@ export interface HostAutoInfo {
current?: string;
}
/** Resultat d'une stack lors d'une mise a jour globale (bouton). */
export interface GlobalStackResult extends HostStackResult {
serverId: string;
server: string;
}
/** Mise a jour globale de toutes les stacks (en cours ou derniere executee). */
export interface UpdateAll {
by?: string;
started: string;
finished?: string;
running: boolean;
total: number;
done: number;
ok: boolean;
message?: string;
results?: GlobalStackResult[];
}
export interface Scan {
running: boolean;
task?: "scan" | "apply";
@@ -168,6 +187,8 @@ export interface Fleet {
tz?: string;
/** Administrateur : clé publique SSH à autoriser sur les serveurs. */
publicKey?: string;
/** Mise a jour globale en cours ou derniere executee (absente : aucune depuis le demarrage). */
updateAll?: UpdateAll;
}
export interface PingResult {
@@ -236,6 +257,9 @@ export const api = {
await request("/api/check", { method: "POST" });
},
/** Met a jour toutes les stacks de tous les serveurs actifs (hors exclues et arretees). */
updateAll: async (): Promise<{ stacks: number }> => (await request("/api/update-all", { method: "POST" })).json(),
check: async (serverId: string, targetId?: string): Promise<void> => {
await request(`/api/servers/${q(serverId)}/check${targetId ? `?target=${q(targetId)}` : ""}`, { method: "POST" });
},