fix: reuse env image from registry fallback
This commit is contained in:
@@ -148,14 +148,41 @@ spec:
|
|||||||
AGENTRUN_REGISTRY_PREFIX="$(params.registry-prefix)" \
|
AGENTRUN_REGISTRY_PREFIX="$(params.registry-prefix)" \
|
||||||
node <<'NODE'
|
node <<'NODE'
|
||||||
const { readFileSync, writeFileSync } = require("node:fs");
|
const { readFileSync, writeFileSync } = require("node:fs");
|
||||||
|
const { execFileSync } = require("node:child_process");
|
||||||
const envIdentity = process.env.AGENTRUN_ENV_IDENTITY;
|
const envIdentity = process.env.AGENTRUN_ENV_IDENTITY;
|
||||||
const revision = process.env.AGENTRUN_REVISION;
|
const revision = process.env.AGENTRUN_REVISION;
|
||||||
const gitopsBranch = process.env.AGENTRUN_GITOPS_BRANCH;
|
const gitopsBranch = process.env.AGENTRUN_GITOPS_BRANCH;
|
||||||
|
const registryPrefix = process.env.AGENTRUN_REGISTRY_PREFIX;
|
||||||
let previousService = null;
|
let previousService = null;
|
||||||
try {
|
try {
|
||||||
const catalog = JSON.parse(readFileSync(process.env.AGENTRUN_PREV_CATALOG, "utf8"));
|
const catalog = JSON.parse(readFileSync(process.env.AGENTRUN_PREV_CATALOG, "utf8"));
|
||||||
previousService = (catalog.services || []).find((item) => item.serviceId === "agentrun-mgr" && item.envIdentity === envIdentity && /^sha256:[a-f0-9]{64}$/.test(item.envDigest || item.digest || "")) || null;
|
previousService = (catalog.services || []).find((item) => item.serviceId === "agentrun-mgr" && item.envIdentity === envIdentity && /^sha256:[a-f0-9]{64}$/.test(item.envDigest || item.digest || "")) || null;
|
||||||
} catch {}
|
} catch {}
|
||||||
|
if (previousService === null) {
|
||||||
|
try {
|
||||||
|
const digest = execFileSync("curl", ["-fsSI", "-H", "Accept: application/vnd.docker.distribution.manifest.v2+json", `http://127.0.0.1:5000/v2/agentrun/agentrun-mgr-env/manifests/${envIdentity}`], { encoding: "utf8" })
|
||||||
|
.split(/\r?\n/)
|
||||||
|
.map((line) => line.split(": "))
|
||||||
|
.find(([key]) => String(key).toLowerCase() === "docker-content-digest")?.[1]
|
||||||
|
?.trim();
|
||||||
|
if (/^sha256:[a-f0-9]{64}$/.test(digest || "")) {
|
||||||
|
previousService = {
|
||||||
|
serviceId: "agentrun-mgr",
|
||||||
|
artifactKind: "env-reuse",
|
||||||
|
status: "registry-reuse",
|
||||||
|
image: `${registryPrefix}/agentrun-mgr-env:${envIdentity}`,
|
||||||
|
digest,
|
||||||
|
repositoryDigest: `${registryPrefix}/agentrun-mgr-env@${digest}`,
|
||||||
|
imageTag: envIdentity,
|
||||||
|
envIdentity,
|
||||||
|
envImage: `${registryPrefix}/agentrun-mgr-env:${envIdentity}`,
|
||||||
|
envDigest: digest,
|
||||||
|
envRepositoryDigest: `${registryPrefix}/agentrun-mgr-env@${digest}`,
|
||||||
|
bootCommit: null,
|
||||||
|
};
|
||||||
|
}
|
||||||
|
} catch {}
|
||||||
|
}
|
||||||
const reused = previousService !== null;
|
const reused = previousService !== null;
|
||||||
const plan = {
|
const plan = {
|
||||||
lane: "v0.1",
|
lane: "v0.1",
|
||||||
|
|||||||
Reference in New Issue
Block a user