feat: implement rollback command for deployments
- Added a new `rollback` command to roll back deployments to their previous release. - Introduced `findRollbackCandidates` and `rollbackDeployment` functions to handle rollback logic. - Updated CLI command definitions to include the new `rollback` command with an alias. - Enhanced deployment conversion to use resolved images for buildable services. - Introduced a new `graph` module to visualize Kubernetes resources and their relationships. - Added tests for the new rollback functionality and graph rendering. - Updated package version to 1.3.0.
This commit is contained in:
+12
-8
@@ -21,7 +21,6 @@ import type { ComposeSpecification } from "../schema/docker.d";
|
||||
import type { Service } from "../schema/docker.d";
|
||||
import { LABELS } from "../const";
|
||||
import { getComposeArchPlacement } from "./arch";
|
||||
import { DEFAULT_REGISTRY } from "./config";
|
||||
import { isPostgresVolumeEntry } from "./database";
|
||||
import { toEnvVars } from "./format";
|
||||
import { deepMerge } from "./shared";
|
||||
@@ -78,12 +77,17 @@ function toReplicaCount(service: Service): number {
|
||||
}
|
||||
|
||||
function toDeploymentImage(
|
||||
project: string,
|
||||
name: string,
|
||||
service: Service,
|
||||
registry: string,
|
||||
buildImages: Record<string, string>,
|
||||
): string | undefined {
|
||||
if (service.build) return `${registry}/kuber/${project}-${name}:latest`;
|
||||
if (service.build) {
|
||||
const image = buildImages[name];
|
||||
if (!image) {
|
||||
throw new Error(`Missing resolved build image for service ${name}`);
|
||||
}
|
||||
return image;
|
||||
}
|
||||
return service.image;
|
||||
}
|
||||
|
||||
@@ -845,7 +849,7 @@ export function serviceToDeployment(
|
||||
cwd = process.cwd(),
|
||||
extraEnv: Record<string, string> = {},
|
||||
volumes: ComposeVolumes = {},
|
||||
registry = DEFAULT_REGISTRY,
|
||||
buildImages: Record<string, string> = {},
|
||||
): V1Deployment {
|
||||
const mounts = toMounts(service, cwd, volumes);
|
||||
const ports = toPorts(service);
|
||||
@@ -888,7 +892,7 @@ export function serviceToDeployment(
|
||||
name,
|
||||
imagePullPolicy: "Always",
|
||||
env: toEnvVars(service.environment),
|
||||
image: toDeploymentImage(project, name, service, registry),
|
||||
image: toDeploymentImage(name, service, buildImages),
|
||||
command:
|
||||
service.command instanceof Array
|
||||
? service.command
|
||||
@@ -1098,7 +1102,7 @@ export async function composeToKubernetes(
|
||||
compose: ComposeSpecification,
|
||||
cwd = process.cwd(),
|
||||
serviceEnv: Record<string, Record<string, string>> = {},
|
||||
registry = DEFAULT_REGISTRY,
|
||||
buildImages: Record<string, string> = {},
|
||||
): Promise<KubernetesResource[]> {
|
||||
const resources = new Map<string, KubernetesResource>();
|
||||
|
||||
@@ -1141,7 +1145,7 @@ export async function composeToKubernetes(
|
||||
cwd,
|
||||
serviceEnv[name] ?? {},
|
||||
compose.volumes,
|
||||
registry,
|
||||
buildImages,
|
||||
);
|
||||
const envSecret = envSecrets[0];
|
||||
if (envSecret) {
|
||||
|
||||
Reference in New Issue
Block a user