This commit is contained in:
2026-09-03 11:28:30 +07:00 Unverified
parent 26c2d0f015
commit 82d0fe3e0d
93 changed files with 19237 additions and 1285 deletions
+35 -19
View File
@@ -1,34 +1,50 @@
import { defineCommand } from "citty";
import { Listr } from "listr2";
import { assertManagedNamespace } from "../lib/apply";
import {
getProject,
listManagedDeployments,
restartDeployment,
} from "../lib/shared";
import { apiRequest, type ApiRequestInit } from "../lib/api";
import { ctx } from "../lib/context";
type LifecycleResponse = { deployments: string[] };
export type RestartApiRequest = <T>(
path: string,
init?: ApiRequestInit,
) => Promise<T>;
export function runRestart(
project: string,
name?: string,
request: RestartApiRequest = apiRequest,
): Promise<LifecycleResponse> {
return request<LifecycleResponse>(
`/workspaces/${encodeURIComponent(project)}/lifecycle`,
{
method: "POST",
json: { action: "restart", ...(name && { services: [name] }) },
},
);
}
export const restart = defineCommand({
meta: {
name: "restart",
description: "Roll out a restart for managed deployments",
},
async run() {
await assertManagedNamespace(getProject());
const deployments = await listManagedDeployments();
if (deployments.length === 0) return;
args: {
deployment: {
type: "positional",
description: "Deployment name to restart (defaults to all managed)",
required: false,
},
},
async run({ args }) {
await new Listr([
{
title: "Restart deployments",
task: (_ctx, task) => {
task.output = `${deployments.length} deployments queued`;
return task.newListr(
deployments.map((deployment) => ({
title: `Deployment ${deployment.metadata?.name}`,
task: () => restartDeployment(deployment.metadata!.name!),
})),
{ concurrent: false, exitOnError: true },
task: async (_ctx, task) => {
const { deployments } = await runRestart(
ctx().project,
args.deployment,
);
task.output = `${deployments.length} deployments queued`;
},
},
]).run();