fix: launch v02 bridge containers with env reuse
This commit is contained in:
@@ -477,6 +477,48 @@ function bootMetadataForService({ args, catalog, deployService, serviceId, sourc
|
||||
};
|
||||
}
|
||||
|
||||
function envReuseBootShForContainer({ serviceId, container, defaultBootSh }) {
|
||||
if (serviceId === "hwlab-cloud-api" && container?.name === "hwlab-codex-api-forwarder") {
|
||||
return "deploy/runtime/boot/hwlab-codex-api-responses-forwarder.sh";
|
||||
}
|
||||
return defaultBootSh;
|
||||
}
|
||||
|
||||
function applyEnvReuseBootEnv(container, bootMetadata, { sourceBranch, bootSh = bootMetadata?.bootSh } = {}) {
|
||||
if (!container || !bootMetadata) return;
|
||||
delete container.command;
|
||||
delete container.args;
|
||||
container.env ??= [];
|
||||
upsertEnv(container.env, "HWLAB_RUNTIME_MODE", bootMetadata.runtimeMode);
|
||||
upsertEnv(container.env, "HWLAB_BOOT_REPO", bootMetadata.bootRepo);
|
||||
upsertEnv(container.env, "HWLAB_BOOT_COMMIT", bootMetadata.bootCommit);
|
||||
upsertEnv(container.env, "HWLAB_BOOT_REF", sourceBranch);
|
||||
upsertEnv(container.env, "HWLAB_BOOT_SH", bootSh);
|
||||
upsertEnv(container.env, "HWLAB_BOOT_READ_URL", defaultV02GitReadUrl);
|
||||
upsertEnv(container.env, "HWLAB_ENVIRONMENT_IMAGE", bootMetadata.environmentImage ?? "");
|
||||
upsertEnv(container.env, "HWLAB_ENVIRONMENT_DIGEST", bootMetadata.environmentDigest ?? "");
|
||||
upsertEnv(container.env, "HWLAB_ENVIRONMENT_INPUT_HASH", bootMetadata.environmentInputHash ?? "");
|
||||
upsertEnv(container.env, "HWLAB_CODE_INPUT_HASH", bootMetadata.codeInputHash ?? "");
|
||||
upsertEnv(container.env, "HWLAB_IMAGE_DIGEST", bootMetadata.environmentDigest ?? "unknown");
|
||||
}
|
||||
|
||||
function annotateEnvReusePodTemplate(podMetadata, bootMetadata) {
|
||||
if (!podMetadata || !bootMetadata) return;
|
||||
annotate(podMetadata, {
|
||||
"hwlab.pikastech.local/runtime-mode": bootMetadata.runtimeMode,
|
||||
"hwlab.pikastech.local/boot-repo": bootMetadata.bootRepo,
|
||||
"hwlab.pikastech.local/boot-commit": bootMetadata.bootCommit,
|
||||
"hwlab.pikastech.local/boot-sh": bootMetadata.bootSh,
|
||||
"hwlab.pikastech.local/environment-digest": bootMetadata.environmentDigest ?? "not_published",
|
||||
"hwlab.pikastech.local/environment-input-hash": bootMetadata.environmentInputHash ?? "unknown",
|
||||
"hwlab.pikastech.local/code-input-hash": bootMetadata.codeInputHash ?? "unknown"
|
||||
});
|
||||
label(podMetadata, {
|
||||
"hwlab.pikastech.local/runtime-mode": bootMetadata.runtimeMode,
|
||||
"hwlab.pikastech.local/boot-commit": bootMetadata.bootCommit
|
||||
});
|
||||
}
|
||||
|
||||
function runtimeArtifactForService({ catalog, deploy, serviceId, source, registryPrefix, useDeployImages = false, digestPin = false, envReuseServiceIds = null }) {
|
||||
const catalogService = catalogServiceById(catalog, serviceId);
|
||||
if (v02EnvReuseEnabled(catalog, serviceId, envReuseServiceIds)) {
|
||||
@@ -943,30 +985,11 @@ function transformWorkloads({ workloads, deploy, catalog, source, sourceBranch =
|
||||
upsertEnv(container.env, "HWLAB_CODE_AGENT_AGENTRUN_SOURCE_COMMIT", runtimeCommit);
|
||||
}
|
||||
if (bootMetadata) {
|
||||
upsertEnv(container.env, "HWLAB_RUNTIME_MODE", bootMetadata.runtimeMode);
|
||||
upsertEnv(container.env, "HWLAB_BOOT_REPO", bootMetadata.bootRepo);
|
||||
upsertEnv(container.env, "HWLAB_BOOT_COMMIT", bootMetadata.bootCommit);
|
||||
upsertEnv(container.env, "HWLAB_BOOT_REF", sourceBranch);
|
||||
upsertEnv(container.env, "HWLAB_BOOT_SH", bootMetadata.bootSh);
|
||||
upsertEnv(container.env, "HWLAB_BOOT_READ_URL", defaultV02GitReadUrl);
|
||||
upsertEnv(container.env, "HWLAB_ENVIRONMENT_IMAGE", bootMetadata.environmentImage ?? "");
|
||||
upsertEnv(container.env, "HWLAB_ENVIRONMENT_DIGEST", bootMetadata.environmentDigest ?? "");
|
||||
upsertEnv(container.env, "HWLAB_ENVIRONMENT_INPUT_HASH", bootMetadata.environmentInputHash ?? "");
|
||||
upsertEnv(container.env, "HWLAB_CODE_INPUT_HASH", bootMetadata.codeInputHash ?? "");
|
||||
upsertEnv(container.env, "HWLAB_IMAGE_DIGEST", bootMetadata.environmentDigest ?? "unknown");
|
||||
annotate(podTemplate.metadata, {
|
||||
"hwlab.pikastech.local/runtime-mode": bootMetadata.runtimeMode,
|
||||
"hwlab.pikastech.local/boot-repo": bootMetadata.bootRepo,
|
||||
"hwlab.pikastech.local/boot-commit": bootMetadata.bootCommit,
|
||||
"hwlab.pikastech.local/boot-sh": bootMetadata.bootSh,
|
||||
"hwlab.pikastech.local/environment-digest": bootMetadata.environmentDigest ?? "not_published",
|
||||
"hwlab.pikastech.local/environment-input-hash": bootMetadata.environmentInputHash ?? "unknown",
|
||||
"hwlab.pikastech.local/code-input-hash": bootMetadata.codeInputHash ?? "unknown"
|
||||
});
|
||||
label(podTemplate.metadata, {
|
||||
"hwlab.pikastech.local/runtime-mode": bootMetadata.runtimeMode,
|
||||
"hwlab.pikastech.local/boot-commit": bootMetadata.bootCommit
|
||||
applyEnvReuseBootEnv(container, bootMetadata, {
|
||||
sourceBranch,
|
||||
bootSh: envReuseBootShForContainer({ serviceId, container, defaultBootSh: bootMetadata.bootSh })
|
||||
});
|
||||
if (container.name === serviceId) annotateEnvReusePodTemplate(podTemplate.metadata, bootMetadata);
|
||||
}
|
||||
if (serviceId === "hwlab-cloud-api" || serviceId === "hwlab-edge-proxy") {
|
||||
upsertEnv(container.env, "HWLAB_PUBLIC_ENDPOINT", runtimeEndpoint);
|
||||
@@ -4057,13 +4080,17 @@ remotePort = ${edgeRemotePort}
|
||||
};
|
||||
}
|
||||
|
||||
function deepSeekProxyManifest({ profile = "dev", source, registryPrefix = defaultRegistryPrefix, catalog = null, useDeployImages = false, metricsSidecarSha256 = null } = {}) {
|
||||
function deepSeekProxyManifest({ profile = "dev", source, sourceBranch = "G14", sourceRepo = defaultSourceRepo, deploy = null, registryPrefix = defaultRegistryPrefix, catalog = null, useDeployImages = false, metricsSidecarSha256 = null } = {}) {
|
||||
const namespace = namespaceNameForProfile(profile);
|
||||
const bridgeServiceId = "hwlab-cloud-api";
|
||||
const digestPin = profile === "v02";
|
||||
const bridgeImage = runtimeImageForService({ catalog, serviceId: bridgeServiceId, source, registryPrefix, useDeployImages, digestPin });
|
||||
const bridgeCommit = runtimeCommitForService({ catalog, serviceId: bridgeServiceId, source, registryPrefix, useDeployImages, digestPin });
|
||||
const bridgeImageTag = runtimeImageTagForService({ catalog, serviceId: bridgeServiceId, source, registryPrefix, useDeployImages, digestPin });
|
||||
const envReuseServiceIds = profile === "v02" ? new Set([bridgeServiceId]) : null;
|
||||
const bridgeImage = runtimeImageForService({ catalog, deploy, serviceId: bridgeServiceId, source, registryPrefix, useDeployImages, digestPin, envReuseServiceIds });
|
||||
const bridgeCommit = runtimeCommitForService({ catalog, deploy, serviceId: bridgeServiceId, source, registryPrefix, useDeployImages, digestPin, envReuseServiceIds });
|
||||
const bridgeImageTag = runtimeImageTagForService({ catalog, deploy, serviceId: bridgeServiceId, source, registryPrefix, useDeployImages, digestPin, envReuseServiceIds });
|
||||
const bridgeBootMetadata = profile === "v02" && v02EnvReuseEnabled(catalog, bridgeServiceId, envReuseServiceIds)
|
||||
? bootMetadataForService({ args: { sourceRepo, registryPrefix }, catalog, deployService: deployServiceForBoot(deploy, bridgeServiceId), serviceId: bridgeServiceId, source })
|
||||
: null;
|
||||
const labels = {
|
||||
"app.kubernetes.io/name": "hwlab-deepseek-proxy",
|
||||
"app.kubernetes.io/part-of": "hwlab",
|
||||
@@ -4086,6 +4113,37 @@ function deepSeekProxyManifest({ profile = "dev", source, registryPrefix = defau
|
||||
"hwlab.pikastech.local/bridge-image": bridgeImage,
|
||||
...v02MetricsSidecarAnnotations(profile === "v02" ? metricsSidecarSha256 : null)
|
||||
};
|
||||
const responsesBridgeContainer = {
|
||||
name: "responses-bridge",
|
||||
image: bridgeImage,
|
||||
imagePullPolicy: "IfNotPresent",
|
||||
command: ["/usr/local/bin/bun", "run", "/app/cmd/hwlab-deepseek-responses-bridge/main.ts"],
|
||||
env: [
|
||||
{ name: "PORT", value: "4000" },
|
||||
{ name: "HWLAB_COMMIT_ID", value: bridgeCommit },
|
||||
{ name: "HWLAB_IMAGE", value: bridgeImage },
|
||||
{ name: "HWLAB_IMAGE_TAG", value: bridgeImageTag },
|
||||
{ name: "HWLAB_DEEPSEEK_BRIDGE_UPSTREAM", value: "http://127.0.0.1:4001" },
|
||||
{ name: "HWLAB_DEEPSEEK_BRIDGE_MODEL", value: deepSeekProfileModel }
|
||||
],
|
||||
ports: [{ name: "http", containerPort: 4000 }],
|
||||
readinessProbe: { httpGet: { path: "/health/readiness", port: "http" }, initialDelaySeconds: 10, periodSeconds: 10 },
|
||||
livenessProbe: { httpGet: { path: "/health/liveliness", port: "http" }, initialDelaySeconds: 20, periodSeconds: 20 }
|
||||
};
|
||||
if (bridgeBootMetadata) {
|
||||
applyEnvReuseBootEnv(responsesBridgeContainer, bridgeBootMetadata, { sourceBranch, bootSh: "deploy/runtime/boot/hwlab-deepseek-responses-bridge.sh" });
|
||||
Object.assign(templateAnnotations, {
|
||||
"hwlab.pikastech.local/bridge-runtime-mode": bridgeBootMetadata.runtimeMode,
|
||||
"hwlab.pikastech.local/bridge-boot-repo": bridgeBootMetadata.bootRepo,
|
||||
"hwlab.pikastech.local/bridge-boot-commit": bridgeBootMetadata.bootCommit,
|
||||
"hwlab.pikastech.local/bridge-boot-sh": "deploy/runtime/boot/hwlab-deepseek-responses-bridge.sh",
|
||||
"hwlab.pikastech.local/bridge-environment-digest": bridgeBootMetadata.environmentDigest ?? "not_published"
|
||||
});
|
||||
Object.assign(templateLabels, {
|
||||
"hwlab.pikastech.local/bridge-runtime-mode": bridgeBootMetadata.runtimeMode,
|
||||
"hwlab.pikastech.local/bridge-boot-commit": bridgeBootMetadata.bootCommit
|
||||
});
|
||||
}
|
||||
return {
|
||||
apiVersion: "v1",
|
||||
kind: "List",
|
||||
@@ -4122,23 +4180,7 @@ function deepSeekProxyManifest({ profile = "dev", source, registryPrefix = defau
|
||||
{ name: "moonbridge-config", mountPath: "/config" }
|
||||
]
|
||||
}],
|
||||
containers: [{
|
||||
name: "responses-bridge",
|
||||
image: bridgeImage,
|
||||
imagePullPolicy: "IfNotPresent",
|
||||
command: ["/usr/local/bin/bun", "run", "/app/cmd/hwlab-deepseek-responses-bridge/main.ts"],
|
||||
env: [
|
||||
{ name: "PORT", value: "4000" },
|
||||
{ name: "HWLAB_COMMIT_ID", value: bridgeCommit },
|
||||
{ name: "HWLAB_IMAGE", value: bridgeImage },
|
||||
{ name: "HWLAB_IMAGE_TAG", value: bridgeImageTag },
|
||||
{ name: "HWLAB_DEEPSEEK_BRIDGE_UPSTREAM", value: "http://127.0.0.1:4001" },
|
||||
{ name: "HWLAB_DEEPSEEK_BRIDGE_MODEL", value: deepSeekProfileModel }
|
||||
],
|
||||
ports: [{ name: "http", containerPort: 4000 }],
|
||||
readinessProbe: { httpGet: { path: "/health/readiness", port: "http" }, initialDelaySeconds: 10, periodSeconds: 10 },
|
||||
livenessProbe: { httpGet: { path: "/health/liveliness", port: "http" }, initialDelaySeconds: 20, periodSeconds: 20 }
|
||||
}, {
|
||||
containers: [responsesBridgeContainer, {
|
||||
name: "moonbridge",
|
||||
image: moonBridgeImage,
|
||||
imagePullPolicy: "IfNotPresent",
|
||||
@@ -4785,7 +4827,7 @@ async function plannedFiles(args) {
|
||||
putJson(`${runtimePath}/services.yaml`, transformServices({ services, namespace, labels: profileLabels, annotations, profile }));
|
||||
putJson(`${runtimePath}/health-contract.yaml`, transformHealthContract(health, namespace, profileLabels, annotations, endpoints.runtimeEndpoint, endpoints.webEndpoint, profile));
|
||||
putJson(`${runtimePath}/workloads.yaml`, transformWorkloads({ workloads, deploy, catalog: artifactCatalog, source, sourceBranch: args.sourceBranch, registryPrefix: args.registryPrefix, runtimeEndpoint: endpoints.runtimeEndpoint, webEndpoint: endpoints.webEndpoint, profile, useDeployImages: args.useDeployImages, metricsSidecarSha256 }));
|
||||
putJson(`${runtimePath}/deepseek-proxy.yaml`, deepSeekProxyManifest({ profile, source, registryPrefix: args.registryPrefix, catalog: artifactCatalog, useDeployImages: args.useDeployImages, metricsSidecarSha256 }));
|
||||
putJson(`${runtimePath}/deepseek-proxy.yaml`, deepSeekProxyManifest({ profile, source, sourceBranch: args.sourceBranch, sourceRepo: args.sourceRepo, deploy, registryPrefix: args.registryPrefix, catalog: artifactCatalog, useDeployImages: args.useDeployImages, metricsSidecarSha256 }));
|
||||
if (profile === "v02") putJson(`${runtimePath}/postgres.yaml`, v02PostgresManifest({ migrationSql, source }));
|
||||
if (profile === "v02") putJson(`${runtimePath}/openfga.yaml`, v02OpenFgaManifest({ source }));
|
||||
if (profile === "v02") putJson(`${runtimePath}/observability.yaml`, observabilityManifest({ namespace, labels: profileLabels, annotations, metricsSidecarScript }));
|
||||
|
||||
Reference in New Issue
Block a user