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:
2026-08-09 00:18:14 +07:00 Unverified
parent c08fb36d2e
commit 8f331d4cc7
17 changed files with 1299 additions and 50 deletions
+43
View File
@@ -0,0 +1,43 @@
import { defineCommand } from "citty";
import { getPodContainerName, getPodForDeployment } from "../lib/shared";
import { execClient } from "../lib/k8s";
export const exec = defineCommand({
meta: {
name: "exec",
description: "Execute a command inside a deployment pod",
},
async run({ args }) {
const [deployment, ...command] = args._;
if (!deployment) throw new Error("Deployment name is required");
if (command.length === 0) throw new Error("Command is required");
const pod = await getPodForDeployment(deployment);
if (pod.status?.phase !== "Running") {
throw new Error(
`Deployment ${deployment} has no running pod to exec into (${pod.metadata?.name ?? "unknown pod"} is ${pod.status?.phase ?? "not ready"})`,
);
}
const namespace = pod.metadata?.namespace ?? "default";
const podName = pod.metadata?.name;
if (!podName) throw new Error(`No pod name found for deployment ${deployment}`);
const socket = await execClient.exec(
namespace,
podName,
getPodContainerName(pod),
command,
process.stdout,
process.stderr,
process.stdin,
Boolean(process.stdin.isTTY),
);
await new Promise<void>((resolve, reject) => {
socket.onclose = () => resolve();
socket.onerror = (event: { error?: unknown }) =>
reject(event.error ?? new Error("Exec failed"));
});
},
});