feat: add commands for managing deployments and resources
- Implemented `down` command to delete managed resources, with an option to delete ingress and PVCs. - Added `exec` command to execute commands inside deployment pods. - Created `logs` command to show deployment logs with an option to follow the output. - Introduced `start` command to start deployments without rebuilding images. - Developed `stop` command to scale managed deployments to zero. refactor: enhance resource management and Kubernetes interactions - Refactored resource handling in `lib/apply.ts` to support sorting and applying resources. - Improved logging functionality with a new logger in `lib/logger.ts`. - Enhanced build process in `lib/build.ts` to support remote builds and syncing with Git repositories. - Added functions to manage deployments and pods in `lib/shared.ts`. chore: update dependencies and TypeScript configuration - Updated package.json to include `listr2` for task management. - Modified tsconfig.json to exclude build artifacts and fixtures.
This commit is contained in:
@@ -0,0 +1,59 @@
|
||||
import { defineCommand } from "citty";
|
||||
import { Listr } from "listr2";
|
||||
import { ctx } from "../lib/context";
|
||||
import {
|
||||
deleteResource,
|
||||
listManagedResources,
|
||||
sortResources,
|
||||
} from "../lib/apply";
|
||||
|
||||
export const down = defineCommand({
|
||||
meta: {
|
||||
name: "down",
|
||||
description: "Delete managed resources except ingress and PVCs",
|
||||
},
|
||||
args: {
|
||||
full: {
|
||||
type: "boolean",
|
||||
alias: "f",
|
||||
description: "Also delete ingress, PVCs, and the namespace",
|
||||
},
|
||||
},
|
||||
async run({ args }) {
|
||||
const { project } = ctx();
|
||||
const resources = sortResources(await listManagedResources(project)).filter(
|
||||
(resource) =>
|
||||
args.full ||
|
||||
(resource.kind !== "Ingress" &&
|
||||
resource.kind !== "PersistentVolumeClaim"),
|
||||
);
|
||||
|
||||
if (args.full) {
|
||||
resources.push({
|
||||
apiVersion: "v1",
|
||||
kind: "Namespace",
|
||||
metadata: { name: project },
|
||||
});
|
||||
}
|
||||
|
||||
await new Listr([
|
||||
{
|
||||
title: "Delete resources",
|
||||
skip: () =>
|
||||
resources.length > 0 ? false : "No managed resources to delete",
|
||||
task: (_ctx, task) => {
|
||||
const ordered = sortResources(resources).reverse();
|
||||
|
||||
task.output = `${ordered.length} resources queued`;
|
||||
return task.newListr(
|
||||
ordered.map((resource) => ({
|
||||
title: `${resource.kind} ${resource.metadata?.name}`,
|
||||
task: () => deleteResource(resource),
|
||||
})),
|
||||
{ concurrent: false, exitOnError: true },
|
||||
);
|
||||
},
|
||||
},
|
||||
]).run();
|
||||
},
|
||||
});
|
||||
Reference in New Issue
Block a user