feat(server): web server, interface shell, demo mode and Docker image (refs #11 #12 #13 #14 #15 #16 #17)
Phase 1 completed on top of the library foundations: - Server: startup state machine (config, first run, database down, schema, identity, ready) with an error page that retries by itself; the configured database is the only one ever opened, and a vanished SQLite file is never recreated. REST API and status WebSocket; session cookie auth, CSRF on every form and write call; desktop and demo answer only the computer itself. - Interface: static Blazor rendering with plain forms (no interactive runtime), menu, top bar and phone bottom bar as in the mockups, light and dark themes with appendix C tokens and a contrast test, Panoramica, Diario, Rischio, Impostazioni; service pages for sign-in, first access, desktop first run and the database error page with its choices. - Demo mode (tasks seed-demo): appendix F in a database of its own under the temp folder, frozen clock, never touches the configured installation. - Docker: entrypoint gives /data to PUID:PGID and drops root with setpriv, HEALTHCHECK through bash /dev/tcp; proven with SQLite, PostgreSQL, a wrong configuration and a database that goes away and comes back. - tasks screenshots drives the installed Edge/Chrome through DevTools for exact 1440 and 390 pixel shots; anubis db export|import on the command line. Fixes from the independent review: return paths without control characters, Host check against DNS rebinding, attempt limit counted before the check and also on the error-page password, one-use TOTP codes and a code to switch the second factor off, error-page choices serialized with the startup loop, identity checked before migrating, restore restarts with "Ferma tutto" on, damaged archives reported instead of crashing. Running the server tests on PostgreSQL exposed pages rendered before their data arrived; data-loading components now load first (LoadedComponent). Decisions in ADR 0007. Tests: 100 on SQLite and on PostgreSQL. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
53ca01b7c3
commit
f9d71559e8
71 files changed
+5853
-80
No files matched your search
@@ -16,7 +16,8 @@ return command switch
|
||||
"build" => BuildImage("dev"),
|
||||
"ci" => Ci(),
|
||||
"hooks" => Step("Attivazione dell'hook pre-commit (.githooks)", "git", ["config", "core.hooksPath", ".githooks"]) ?? 0,
|
||||
"seed-demo" => NotYet("seed-demo", 1),
|
||||
"seed-demo" => Run("dotnet", ["run", "--project", "src/Anubis.Server", "-c", "Release", "--", "--demo", .. rest]),
|
||||
"screenshots" => Screenshots(rest),
|
||||
"desktop-win" => NotYet("desktop-win", 10),
|
||||
_ => Help(),
|
||||
};
|
||||
@@ -76,6 +77,106 @@ int BuildImage(string tag) =>
|
||||
Step("Costruzione dell'immagine Docker", "docker",
|
||||
["build", "-f", "deploy/docker/Dockerfile", "-t", $"gitea.encke-hake.ts.net/balbosoft/anubis:{tag}", "."]) ?? 0;
|
||||
|
||||
// Demo data photographed at 1440 and 390 pixels, light and dark, to compare with docs/design (SPEC 13.1). Uses the
|
||||
// Edge or Chrome already on the computer, driven through its DevTools protocol: nothing to install (ADR 0007).
|
||||
int Screenshots(string[] pages)
|
||||
{
|
||||
var browser = FindBrowser();
|
||||
if (browser is null)
|
||||
{
|
||||
Console.Error.WriteLine("Serve Microsoft Edge o Google Chrome installato per le fotografie.");
|
||||
return 2;
|
||||
}
|
||||
|
||||
var failed = Step("Compilazione del server", "dotnet", ["build", "src/Anubis.Server", "-c", "Release"]);
|
||||
if (failed is not null)
|
||||
{
|
||||
return failed.Value;
|
||||
}
|
||||
|
||||
var port = FreePort();
|
||||
var url = "http://127.0.0.1:" + port.ToString(CultureInfo.InvariantCulture);
|
||||
var server = new ProcessStartInfo("dotnet") { WorkingDirectory = root, UseShellExecute = false, RedirectStandardOutput = true, RedirectStandardError = true };
|
||||
foreach (var argument in new[] { Path.Combine("src", "Anubis.Server", "bin", "Release", "net10.0", "Anubis.Server.dll"), "--demo", "--urls", url })
|
||||
{
|
||||
server.ArgumentList.Add(argument);
|
||||
}
|
||||
|
||||
using var process = Process.Start(server)!;
|
||||
process.OutputDataReceived += (_, _) => { };
|
||||
process.ErrorDataReceived += (_, _) => { };
|
||||
process.BeginOutputReadLine();
|
||||
process.BeginErrorReadLine();
|
||||
try
|
||||
{
|
||||
using var http = new System.Net.Http.HttpClient();
|
||||
var ready = false;
|
||||
for (var i = 0; i < 60 && !ready; i++)
|
||||
{
|
||||
try
|
||||
{
|
||||
ready = http.GetAsync(new Uri(url + "/health")).GetAwaiter().GetResult().IsSuccessStatusCode;
|
||||
}
|
||||
catch (System.Net.Http.HttpRequestException)
|
||||
{
|
||||
}
|
||||
|
||||
if (!ready)
|
||||
{
|
||||
Thread.Sleep(500);
|
||||
}
|
||||
}
|
||||
|
||||
if (!ready)
|
||||
{
|
||||
Console.Error.WriteLine("Il server dimostrativo non risponde.");
|
||||
return 1;
|
||||
}
|
||||
|
||||
var folder = Path.Combine(root, "artifacts", "screenshots");
|
||||
Directory.CreateDirectory(folder);
|
||||
var targets = pages.Length > 0 ? pages : ["/", "/diario", "/impostazioni"];
|
||||
using var shots = Shots.Start(browser);
|
||||
foreach (var page in targets)
|
||||
{
|
||||
var name = page == "/" ? "panoramica" : page.Trim('/').Replace('/', '-');
|
||||
foreach (var (width, height, dark) in new[] { (1440, 1400, false), (390, 2200, false), (1440, 1400, true) })
|
||||
{
|
||||
var file = Path.Combine(folder, $"{name}-{width.ToString(CultureInfo.InvariantCulture)}{(dark ? "-scuro" : "")}.png");
|
||||
shots.Take(url + page, width, height, dark, file);
|
||||
Console.WriteLine($" {file}");
|
||||
}
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
finally
|
||||
{
|
||||
process.Kill(entireProcessTree: true);
|
||||
}
|
||||
}
|
||||
|
||||
static string? FindBrowser()
|
||||
{
|
||||
string[] candidates =
|
||||
[
|
||||
Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.ProgramFilesX86), "Microsoft", "Edge", "Application", "msedge.exe"),
|
||||
Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.ProgramFiles), "Microsoft", "Edge", "Application", "msedge.exe"),
|
||||
Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.ProgramFiles), "Google", "Chrome", "Application", "chrome.exe"),
|
||||
"/usr/bin/chromium", "/usr/bin/chromium-browser", "/usr/bin/google-chrome", "/usr/bin/microsoft-edge",
|
||||
];
|
||||
return candidates.FirstOrDefault(File.Exists);
|
||||
}
|
||||
|
||||
static int FreePort()
|
||||
{
|
||||
var listener = new System.Net.Sockets.TcpListener(System.Net.IPAddress.Loopback, 0);
|
||||
listener.Start();
|
||||
var port = ((System.Net.IPEndPoint)listener.LocalEndpoint).Port;
|
||||
listener.Stop();
|
||||
return port;
|
||||
}
|
||||
|
||||
int NotYet(string name, int phase)
|
||||
{
|
||||
Console.Error.WriteLine($"'tasks {name}' arriva nella Fase {phase.ToString(CultureInfo.InvariantCulture)}.");
|
||||
@@ -92,7 +193,8 @@ int Help()
|
||||
tasks build costruisce l'immagine Docker
|
||||
tasks ci come la CI: check, test su PostgreSQL, immagine
|
||||
tasks hooks attiva l'hook che esegue check prima di ogni commit
|
||||
tasks seed-demo dati dimostrativi (Fase 1)
|
||||
tasks seed-demo avvia la modalità dimostrativa (dati dell'appendice F, database a parte)
|
||||
tasks screenshots fotografa le schermate dimostrative a 1440 e 390 pixel
|
||||
tasks desktop-win installatore Windows (Fase 10)
|
||||
""");
|
||||
return command == "help" ? 0 : 1;
|
||||
|
||||
Reference in new issue
Block a user