Fase 10 — Nuova rotta: solo Docker (#184)
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:
1 parent
3c57b3e84c
commit
1bc7e067fd
96 files changed
+1433
-1606
No files matched your search
@@ -165,6 +165,13 @@ public sealed class ServerTests
|
||||
}
|
||||
|
||||
TempFolder.Delete(demoRoot);
|
||||
|
||||
// A development run outside a container: the same refusal, even when bound to every address (ADR 0022).
|
||||
await using var dev = await ServerHarness.StartAsync("docker", ServerHarness.DockerSqlite());
|
||||
using var rebinding = new HttpRequestMessage(HttpMethod.Get, new Uri("/health", UriKind.Relative));
|
||||
rebinding.Headers.Host = "evil.example:" + dev.BaseAddress.Port.ToString(System.Globalization.CultureInfo.InvariantCulture);
|
||||
using var refused = await dev.Http.SendAsync(rebinding);
|
||||
Assert.AreEqual(HttpStatusCode.Forbidden, refused.StatusCode);
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
@@ -332,36 +339,93 @@ public sealed class ServerTests
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
public async Task DesktopStartsFromAnEmptyFolderAndKeepsTheKeyOutOfConfig()
|
||||
public void TheDesktopIsGoneAndOutsideAContainerTheFolderIsGivenByHand()
|
||||
{
|
||||
await using var server = await ServerHarness.StartAsync("desktop", new Dictionary<string, string?>(), waitReady: false);
|
||||
await server.WaitForAsync(HostMode.FirstRun);
|
||||
var env = ServerHarness.DockerSqlite();
|
||||
var desktop = Assert.Throws<StartupRefusedException>(() => ServerOptions.Parse(["--platform", "desktop"], env));
|
||||
Assert.Contains("solo in un container Docker", desktop.Message);
|
||||
|
||||
using (var redirect = await server.GetAsync("/"))
|
||||
// "--platform docker" still works, for the commands already written in the manuals.
|
||||
var outside = ServerOptions.Parse(["--platform", "docker"], env);
|
||||
Assert.IsFalse(outside.InContainer);
|
||||
Assert.IsTrue(outside.LocalOnly);
|
||||
var refused = Assert.Throws<StartupRefusedException>(() => outside.LoadConfig(env));
|
||||
Assert.Contains("--data-dir", refused.Message);
|
||||
|
||||
var inside = new Dictionary<string, string?>(env, StringComparer.Ordinal) { ["DOTNET_RUNNING_IN_CONTAINER"] = "true" };
|
||||
var container = ServerOptions.Parse([], inside);
|
||||
Assert.IsTrue(container.InContainer);
|
||||
Assert.IsFalse(container.LocalOnly);
|
||||
Assert.AreEqual("/data", container.LoadConfig(inside).Data.Root);
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
[DataRow(false, "http://127.0.0.1:")]
|
||||
[DataRow(true, "http://0.0.0.0:")]
|
||||
public async Task OutsideAContainerTheServerListensOnlyOnThisComputer(bool inContainer, string address)
|
||||
{
|
||||
var folder = TempFolder.Create("listen");
|
||||
try
|
||||
{
|
||||
Assert.AreEqual("/primo-avvio", ServerHarness.Location(redirect));
|
||||
var env = ServerHarness.DockerSqlite();
|
||||
env["PORT"] = "18787";
|
||||
if (inContainer)
|
||||
{
|
||||
env["DOTNET_RUNNING_IN_CONTAINER"] = "true";
|
||||
}
|
||||
|
||||
await using (var app = ServerApp.Build(["--data-dir", folder], new ServerOverrides { Environment = env, PasswordIterations = 1000 }))
|
||||
{
|
||||
Assert.AreEqual(address + "18787", app.Configuration["urls"]);
|
||||
}
|
||||
}
|
||||
finally
|
||||
{
|
||||
TempFolder.Delete(folder);
|
||||
}
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
[DataRow("Anubis.Server.dll", "--platform desktop", "solo in un container Docker")]
|
||||
[DataRow("Anubis.Server.dll", "", "--data-dir")]
|
||||
[DataRow("Anubis.Guard.dll", "--platform desktop", "solo in un container Docker")]
|
||||
[DataRow("Anubis.Guard.dll", "--platform desktop --data-dir .", "solo in un container Docker")]
|
||||
[DataRow("Anubis.Guard.dll", "", "--data-dir")]
|
||||
public async Task TheServerSaysInItalianWhyItDoesNotStart(string program, string arguments, string message)
|
||||
{
|
||||
var info = new System.Diagnostics.ProcessStartInfo(Anubis.Supervision.GuardLaunch.Dotnet())
|
||||
{
|
||||
RedirectStandardError = true,
|
||||
RedirectStandardOutput = true,
|
||||
UseShellExecute = false,
|
||||
};
|
||||
// The guard too: a refused start ends with the message, not with an engine restarted again and again.
|
||||
info.ArgumentList.Add(Path.Combine(AppContext.BaseDirectory, program));
|
||||
foreach (var argument in arguments.Split(' ', StringSplitOptions.RemoveEmptyEntries))
|
||||
{
|
||||
info.ArgumentList.Add(argument);
|
||||
}
|
||||
|
||||
const string password = "fake-desktop-pass-3";
|
||||
using (var done = await server.PostFormAsync("/primo-avvio", "/azioni/primo-avvio", ("motore", "sqlite"), ("password", password), ("conferma", password)))
|
||||
// Outside a container, even when the suite runs in one (the CI).
|
||||
info.Environment.Remove("DOTNET_RUNNING_IN_CONTAINER");
|
||||
using var process = System.Diagnostics.Process.Start(info)!;
|
||||
var errors = process.StandardError.ReadToEndAsync();
|
||||
_ = process.StandardOutput.ReadToEndAsync();
|
||||
using var timeout = new CancellationTokenSource(TimeSpan.FromSeconds(60));
|
||||
try
|
||||
{
|
||||
Assert.AreEqual("/", ServerHarness.Location(done));
|
||||
await process.WaitForExitAsync(timeout.Token);
|
||||
}
|
||||
catch (OperationCanceledException)
|
||||
{
|
||||
// A guard that does not refuse would restart the engine for ever: it goes, with what it started.
|
||||
process.Kill(entireProcessTree: true);
|
||||
Assert.Fail(program + " did not end within a minute.");
|
||||
}
|
||||
|
||||
Assert.AreEqual(HostMode.Ready, server.Host.Status.Mode);
|
||||
using (var home = await server.GetAsync("/"))
|
||||
{
|
||||
Assert.AreEqual(HttpStatusCode.OK, home.StatusCode, "Signed in by the wizard.");
|
||||
}
|
||||
|
||||
var data = new DataDirectory(server.DataDir);
|
||||
Assert.IsTrue(File.Exists(data.SqliteFile));
|
||||
var config = await File.ReadAllTextAsync(data.ConfigFile);
|
||||
StringAssert.Contains(config, "engine = \"sqlite\"");
|
||||
StringAssert.Contains(config, "allow_live = false");
|
||||
Assert.IsFalse(System.Text.RegularExpressions.Regex.IsMatch(config, @"^\s*\w*(secret|key|password)\w*\s*=", System.Text.RegularExpressions.RegexOptions.Multiline),
|
||||
"Neither the secret key nor a password goes into config.toml.");
|
||||
Assert.IsNotEmpty(Directory.EnumerateFiles(Path.Combine(data.Root, "keys")).ToList());
|
||||
Assert.AreEqual(2, process.ExitCode);
|
||||
Assert.Contains(message, await errors);
|
||||
Assert.DoesNotContain(" at ", await errors, "A message, not a stack trace.");
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
@@ -403,6 +467,13 @@ public sealed class ServerTests
|
||||
StringAssert.Contains(message, "\"bot\":\"active\"");
|
||||
await socket.CloseAsync(WebSocketCloseStatus.NormalClosure, null, CancellationToken.None);
|
||||
|
||||
// The demo has no startup password and answers only this computer: the error-page choices go through without one.
|
||||
using (var choice = await server.PostFormAsync("/", "/azioni/servizio/riprova"))
|
||||
{
|
||||
Assert.AreEqual(HttpStatusCode.Redirect, choice.StatusCode);
|
||||
Assert.DoesNotContain("errore", ServerHarness.Location(choice));
|
||||
}
|
||||
|
||||
var after = Snapshot(configured);
|
||||
CollectionAssert.AreEquivalent(before.Keys.ToList(), after.Keys.ToList(), "No file added or removed in the configured data folder.");
|
||||
foreach (var (name, hash) in before)
|
||||
|
||||
Reference in new issue
Block a user