OPC # 0002: Improvements to Client provisioning workflows
This commit is contained in:
@@ -16,6 +16,7 @@ public static class InfraEndpoints
|
||||
g.MapPost("/{container}/restart",(string container) => ServiceAction(container, "restart"));
|
||||
g.MapGet ("/compose/up/stream", ComposeUpStream);
|
||||
g.MapGet ("/compose/up-force/stream", ComposeUpForceStream);
|
||||
g.MapGet ("/compose/nuke/stream", ComposeNukeStream);
|
||||
g.MapGet ("/compose/down/stream", ComposeDownStream);
|
||||
|
||||
return app;
|
||||
@@ -131,17 +132,49 @@ public static class InfraEndpoints
|
||||
private static Task ComposeUpForceStream(HttpContext ctx, IConfiguration config, CancellationToken ct) =>
|
||||
StreamComposeOutput(ctx, config, "up -d --force-recreate --remove-orphans", ct);
|
||||
|
||||
// Nuke: force-removes every known platform container by name first (kills orphans that
|
||||
// --remove-orphans won't touch because they belong to a different compose project),
|
||||
// then runs a fresh compose up.
|
||||
private static async Task ComposeNukeStream(HttpContext ctx, IConfiguration config, CancellationToken ct)
|
||||
{
|
||||
ctx.Response.Headers.ContentType = "text/event-stream";
|
||||
ctx.Response.Headers.CacheControl = "no-cache";
|
||||
ctx.Response.Headers.Connection = "keep-alive";
|
||||
|
||||
async Task Send(string line)
|
||||
{
|
||||
await ctx.Response.WriteAsync($"data: {line}\n\n", ct);
|
||||
await ctx.Response.Body.FlushAsync(ct);
|
||||
}
|
||||
|
||||
await Send("▶ Removing all known platform containers…");
|
||||
foreach (var container in PlatformContainers)
|
||||
{
|
||||
var (code, _) = await DockerAsync($"rm -f {container}");
|
||||
await Send(code == 0
|
||||
? $" ✔ removed {container}"
|
||||
: $" · {container} not found (skipped)");
|
||||
}
|
||||
|
||||
await Send("▶ Running compose up…");
|
||||
await StreamComposeOutput(ctx, config, "up -d", ct, skipHeaders: true);
|
||||
}
|
||||
|
||||
private static Task ComposeDownStream(HttpContext ctx, IConfiguration config, CancellationToken ct) =>
|
||||
StreamComposeOutput(ctx, config, "down", ct);
|
||||
|
||||
private static async Task StreamComposeOutput(
|
||||
HttpContext ctx, IConfiguration config, string composeArgs, CancellationToken ct)
|
||||
HttpContext ctx, IConfiguration config, string composeArgs, CancellationToken ct,
|
||||
bool skipHeaders = false)
|
||||
{
|
||||
var infraDir = ResolveInfraPath(config);
|
||||
|
||||
ctx.Response.Headers.ContentType = "text/event-stream";
|
||||
ctx.Response.Headers.CacheControl = "no-cache";
|
||||
ctx.Response.Headers.Connection = "keep-alive";
|
||||
if (!skipHeaders)
|
||||
{
|
||||
ctx.Response.Headers.ContentType = "text/event-stream";
|
||||
ctx.Response.Headers.CacheControl = "no-cache";
|
||||
ctx.Response.Headers.Connection = "keep-alive";
|
||||
}
|
||||
|
||||
var channel = System.Threading.Channels.Channel.CreateUnbounded<string?>(
|
||||
new System.Threading.Channels.UnboundedChannelOptions { SingleWriter = false, SingleReader = true });
|
||||
|
||||
Reference in New Issue
Block a user