Fase 10 — Nuova rotta: solo Docker (#184)
ci / test (postgres) (push) Successful in 4m50s
ci / test (sqlite) (push) Failing after 4m21s
ci / image (push) Skipped

ADR 0021-0026 for the new course of 2 December 2026, roadmap of phases 10-24. The desktop application is gone: Docker is the only form, and outside a container the server runs only for development and tests with --data-dir, on this computer only. Lighter image (829 MB to 410 MB), rotating logs, backtest and learning as one-shot commands.

refs #113 #114 #115 #78 #80 #81

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-authored-by: Alberto Balbo <alberto.balbo.96@gmail.com>
This commit was merged in pull request #184.
This commit is contained in:
Alby96andClaude Opus 5.5 authored and Alby96 committed 2026-12-03 19:59:00 +01:00
1 parent 3c57b3e84c
commit 1bc7e067fd
96 files changed
+1433 -1606

No files matched your search

+12 -132
View File
@@ -15,8 +15,6 @@ internal static partial class Forms
{
var open = app.MapGroup("/azioni").AllowAnonymous();
open.MapPost("/accesso", SignInAsync);
open.MapPost("/primo-avvio/prova", TestDatabaseAsync);
open.MapPost("/primo-avvio", FirstRunAsync);
open.MapPost("/servizio/{choice}", ServiceChoiceAsync);
var signed = app.MapGroup("/azioni").RequireAuthorization();
@@ -1011,144 +1009,29 @@ internal static partial class Forms
}
}
// ---- Desktop first run (SPEC 15.6): only from the computer itself, only while the wizard is due. ----
private static DbSettings ReadDatabase(IFormCollection form, StartupConfig config)
{
if (form["motore"].ToString() != "postgres")
{
return new DbSettings { Engine = DbEngine.Sqlite, SqlitePath = config.Data.SqliteFile };
}
return new DbSettings
{
Engine = DbEngine.Postgres,
Host = form["host"].ToString().Trim(),
Port = int.TryParse(form["porta"].ToString(), out var port) && port is > 0 and < 65536 ? port : 5432,
Database = string.IsNullOrWhiteSpace(form["nome"]) ? "anubis" : form["nome"].ToString().Trim(),
User = string.IsNullOrWhiteSpace(form["utente"]) ? "anubis" : form["utente"].ToString().Trim(),
Password = form["dbpassword"].ToString(),
};
}
/// <summary>Opens the database without creating anything and asks it one question.</summary>
private static async Task<string?> TryConnectAsync(DbSettings settings, CancellationToken ct)
{
if (settings.Engine == DbEngine.Postgres && string.IsNullOrWhiteSpace(settings.Host))
{
return "Manca l'indirizzo del server PostgreSQL.";
}
Redactor.Register(settings.Password);
try
{
await using var db = Database.Open(settings, allowCreate: settings.Engine == DbEngine.Sqlite);
using var timeout = CancellationTokenSource.CreateLinkedTokenSource(ct);
timeout.CancelAfter(TimeSpan.FromSeconds(8));
await db.PingAsync(timeout.Token).ConfigureAwait(false);
return null;
}
catch (Exception ex) when (!ct.IsCancellationRequested)
{
return Redactor.Redact(ex.Message);
}
}
private static bool WizardAllowed(AnubisHost host, HttpContext context) =>
host.Status.Mode == HostMode.FirstRun && host.Config.Platform == PlatformKind.Desktop && CurrentUser.IsLocal(context);
private static async Task<IResult> TestDatabaseAsync(IFormCollection form, AnubisHost host, HttpContext context, CancellationToken ct)
{
if (!WizardAllowed(host, context))
{
return Endpoints.Error(StatusCodes.Status403Forbidden, "non_ammesso", "La procedura guidata si usa solo dal computer su cui gira Anubis, al primo avvio.");
}
var problem = await TryConnectAsync(ReadDatabase(form, host.Config), ct).ConfigureAwait(false);
return Results.Json(new { ok = problem is null, message = problem ?? "Connessione riuscita." });
}
private static async Task<IResult> FirstRunAsync(IFormCollection form, AnubisHost host, HttpContext context, ILogger<AnubisHost> logger, CancellationToken ct)
{
if (!WizardAllowed(host, context))
{
return Results.Redirect("/");
}
var password = form["password"].ToString();
if (password != form["conferma"].ToString())
{
return Results.Redirect("/primo-avvio?errore=diverse");
}
if (Passwords.Problem(password) is not null)
{
return Results.Redirect("/primo-avvio?errore=corta");
}
var config = host.Config;
if (!config.IsComplete)
{
var settings = ReadDatabase(form, config);
if (await TryConnectAsync(settings, ct).ConfigureAwait(false) is not null)
{
return Results.Redirect("/primo-avvio?errore=database");
}
// config.toml without the database password: that goes to the protected store (SPEC 15.6).
DesktopPlatform.WriteConfig(config.Data, ProtectedSecretKey.DefaultStore(config.Data), settings, config.Port, allowNetwork: false);
}
host.PendingPassword = password;
host.Wake();
try
{
await host.WaitForAsync(HostMode.Ready, TimeSpan.FromSeconds(60)).ConfigureAwait(false);
}
catch (OperationCanceledException)
{
LogFirstRunSlow(logger);
return Results.Redirect("/");
}
var (result, token) = await host.Services!.Access.SignInAsync(password, null, context.Request.Headers.UserAgent.ToString(),
context.Connection.RemoteIpAddress?.ToString(), ct).ConfigureAwait(false);
if (result == LoginResult.Ok)
{
SessionAuthentication.WriteCookie(context, token!);
}
return Results.Redirect("/");
}
// ---- Choices of the error page (SPEC 15.1): Docker asks the startup password, desktop only the computer itself. ----
// ---- Choices of the error page (SPEC 15.1): the startup password, with the sign-in attempt limit (ADR 0022). ----
private static async Task<IResult> ServiceChoiceAsync(string choice, IFormCollection form, AnubisHost host, IClock clock, LoginLimiter limiter,
HttpContext context, ILogger<AnubisHost> logger, CancellationToken ct)
{
var config = host.Config;
if (config.Platform == PlatformKind.Docker)
// The startup password, asked by a page anyone on the network can open: same attempt limit as the sign-in. The
// demo has none and answers only this computer (ServerApp.LocalOnly): its choices need no password.
var address = context.Connection.RemoteIpAddress?.ToString() ?? "sconosciuto";
if (limiter.Begin(address) > TimeSpan.Zero)
{
// The startup password, asked by a page anyone on the network can open: same attempt limit as the sign-in.
var address = context.Connection.RemoteIpAddress?.ToString() ?? "sconosciuto";
if (limiter.Begin(address) > TimeSpan.Zero)
{
return Results.Redirect("/?errore=attesa");
}
if (!Endpoints.SameSecret(form["password"].ToString(), config.AdminPassword))
{
LogChoiceRefused(logger, choice);
return Results.Redirect("/?errore=password");
}
limiter.Succeeded(address);
return Results.Redirect("/?errore=attesa");
}
else if (!CurrentUser.IsLocal(context))
if (!host.IsDemo && !Endpoints.SameSecret(form["password"].ToString(), config.AdminPassword))
{
LogChoiceRefused(logger, choice);
return Results.Redirect("/?errore=password");
}
limiter.Succeeded(address);
// The startup loop stays still until the choice is done and the installation renewed.
using var exclusive = await host.ExclusiveAsync(ct).ConfigureAwait(false);
var status = host.Status;
@@ -1252,9 +1135,6 @@ internal static partial class Forms
[LoggerMessage(Level = LogLevel.Error, Message = "Backup on request failed")]
private static partial void LogBackupFailed(ILogger logger, Exception exception);
[LoggerMessage(Level = LogLevel.Warning, Message = "First run: the application is not ready after 60 seconds")]
private static partial void LogFirstRunSlow(ILogger logger);
[LoggerMessage(Level = LogLevel.Warning, Message = "Error page choice {Choice} confirmed")]
private static partial void LogChoice(ILogger logger, string choice);