Record Architecture B approval and verified pinned baseline
This commit is contained in:
1 parent
20ab461c01
commit
cee98e7035
158 files changed
+33575
No files matched your search
@@ -0,0 +1,83 @@
|
||||
using System.Text.Json;
|
||||
|
||||
namespace HealthApp.Provisioning;
|
||||
|
||||
public static class Program
|
||||
{
|
||||
public static async Task<int> Main(string[] args)
|
||||
{
|
||||
var command = args.FirstOrDefault() ?? "";
|
||||
try
|
||||
{
|
||||
var options = new Dictionary<string, string>();
|
||||
for (var index = 1; index < args.Length; index += 2)
|
||||
{
|
||||
if (index + 1 >= args.Length || !args[index].StartsWith("--") || !options.TryAdd(args[index][2..], args[index + 1]))
|
||||
throw new InvalidOperationException("Invalid provisioning arguments.");
|
||||
}
|
||||
string Required(string key) => options.GetValueOrDefault(key) ?? throw new InvalidOperationException("Missing argument: " + key);
|
||||
switch (command)
|
||||
{
|
||||
case "launchd":
|
||||
LaunchdWriter.Write(Required("service"), Required("root"), Required("dotnet"), Required("output"));
|
||||
break;
|
||||
case "secret":
|
||||
File.WriteAllText(Required("output"), Deployment.Secret());
|
||||
if (!OperatingSystem.IsWindows()) File.SetUnixFileMode(Required("output"), UnixFileMode.UserRead | UnixFileMode.UserWrite);
|
||||
break;
|
||||
case "admin-connection":
|
||||
var admin = new Npgsql.NpgsqlConnectionStringBuilder { Host = "localhost", Port = int.Parse(Required("port")),
|
||||
Username = "postgres", Database = "postgres", Password = File.ReadAllText(Required("password-file")).Trim(), Pooling = false };
|
||||
File.WriteAllText(Required("output"), admin.ConnectionString);
|
||||
if (!OperatingSystem.IsWindows()) File.SetUnixFileMode(Required("output"), UnixFileMode.UserRead | UnixFileMode.UserWrite);
|
||||
break;
|
||||
case "execute":
|
||||
var native = options.GetValueOrDefault("platform", "macos");
|
||||
var serviceName = Required("service");
|
||||
if (!Deployment.Names.Contains(serviceName)) throw new InvalidOperationException("Unknown selected service.");
|
||||
var rootPath = Required("root");
|
||||
var config = Path.Combine(rootPath, "config", serviceName, "service.env");
|
||||
var start = new System.Diagnostics.ProcessStartInfo(Required("dotnet")) { UseShellExecute = false,
|
||||
WorkingDirectory = Path.Combine(rootPath, "services", serviceName) };
|
||||
start.ArgumentList.Add(Required("assembly"));
|
||||
start.ArgumentList.Add("--migrate");
|
||||
foreach (var line in File.ReadAllLines(config))
|
||||
start.Environment[line[..line.IndexOf('=')]] = JsonSerializer.Deserialize<string>(line[(line.IndexOf('=') + 1)..])!;
|
||||
using (var process = System.Diagnostics.Process.Start(start)!)
|
||||
{
|
||||
await process.WaitForExitAsync();
|
||||
if (process.ExitCode != 0) throw new InvalidOperationException("Selected service migration failed.");
|
||||
}
|
||||
break;
|
||||
case "prepare":
|
||||
Deployment.Prepare(Required("output"), options.GetValueOrDefault("host", "localhost"), options.GetValueOrDefault("topology"), options.GetValueOrDefault("certificates"));
|
||||
break;
|
||||
case "database":
|
||||
await DatabaseProvisioning.Create(Required("service-dir"), options.GetValueOrDefault("admin-file"));
|
||||
break;
|
||||
case "configure":
|
||||
ConfigurationWriter.Configure(Required("service-dir"), Required("root"), options.GetValueOrDefault("platform", "linux"));
|
||||
break;
|
||||
case "distribute":
|
||||
var names = Required("services").Split(',');
|
||||
if (names.Any(n => !Deployment.Names.Contains(n))) throw new InvalidOperationException("Unknown distribution service.");
|
||||
await Distribution.Deploy(Required("bundle"), Required("deployment"), Required("ssh-user"), names);
|
||||
break;
|
||||
case "verify-startup":
|
||||
case "verify":
|
||||
var selected = Required("services").Split(',');
|
||||
if (selected.Any(n => !Deployment.Names.Contains(n))) throw new InvalidOperationException("Unknown verification service.");
|
||||
await InstallationVerification.Verify(Required("deployment"), selected, options.GetValueOrDefault("complete") == "true", command == "verify-startup");
|
||||
break;
|
||||
default: throw new InvalidOperationException("Unknown provisioning command.");
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
catch (Exception error)
|
||||
{
|
||||
Console.Error.WriteLine($"Provisioning step '{command}' failed: " + (error is InvalidOperationException ? error.Message : error.GetType().Name) +
|
||||
" No credentials are printed; inspect the relevant service logs.");
|
||||
return 1;
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user