Files
piik/scripts/publish-container.mjs
T
TNTcraft 2e74d19dc3 fix(ci): inspect raw OCI indexes when publishing containers (#527)
`docker manifest inspect` reconstructs an image index and drops descriptor annotations. The v2.6.0 registry index correctly marks its BuildKit attestation, but the transformed CLI output loses that marker and the publisher counts `unknown/unknown` as another runnable platform.

Read the original index with `docker buildx imagetools inspect --raw`. Keep the explicit attestation filter, exact runnable-platform set and image/source/archive checks. Treat only an exact missing-reference error as absence; permission, network and missing-blob errors still stop publication.

The regression now distinguishes the old CLI's annotation loss from the raw index response. Container/package publisher and mirror-source checks pass (65 tests), including new/retained attestation indexes, unmarked unknown platforms and lookup failures.

The actual v2.6.0 index and both image configs were read anonymously. Their version, source SHA and Server archive digests match the published release. The original index bytes were used to finish the `latest` alias; the version tag, images and release attachments were not rebuilt or replaced. This is a publishing-tool correction and does not create another product version.

Primary references: [Docker CLI descriptor reconstruction](https://github.com/docker/cli/blob/master/cli/command/manifest/push.go#L132), [Buildx raw inspection](https://docs.docker.com/reference/cli/docker/buildx/imagetools/inspect/).
2026-11-06 15:22:56 -04:00

93 lines
4.4 KiB
JavaScript

#!/usr/bin/env node
import assert from "node:assert/strict";
import { execFileSync } from "node:child_process";
import { readReleaseArtifacts } from "./release-artifacts.mjs";
const [image, directory, version, revision] = process.argv.slice(2);
if (process.argv.length !== 6 || !image) {
throw new Error("Usage: node scripts/publish-container.mjs <local-image-prefix> <artifacts> <version> <full-SHA>");
}
const { servers } = readReleaseArtifacts(directory, version, revision);
// Only the Linux Server packages have a container image; a Windows Server
// package shares the `amd64` arch but is a ZIP with no image of its own.
const linuxServers = servers.filter(server => server.goos === "linux");
const repository = process.env.GITHUB_REPOSITORY || "TNTcraftHIM/Piik";
const destination = `ghcr.io/${repository.toLowerCase()}`;
const run = (command, ...args) => execFileSync(command, args, {
encoding: "utf8", stdio: ["ignore", "pipe", "pipe"], timeout: 300_000,
}).trim();
const gh = (path) => JSON.parse(run("gh", "api", `repos/${repository}/${path}`));
const release = gh(`releases/tags/${version}`);
assert.equal(release.draft, false, "Container publication requires a published GitHub release");
assert.equal(release.prerelease, false);
assert.equal(release.target_commitish, revision);
assert.equal(run("gh", "api", `repos/${repository}/commits/${version}`,
"--header", "Accept: application/vnd.github.sha"), revision, "Published source tag changed");
for (const server of servers) {
assert.equal(release.assets.find((asset) => asset.name === server.name)?.digest,
`sha256:${server.sha256}`, "Container must wrap the published Server archive");
}
function verifyImage(reference, server) {
const metadata = JSON.parse(run("docker", "image", "inspect", reference))[0];
assert.equal(metadata.Os, "linux");
assert.equal(metadata.Architecture, server.arch);
const labels = metadata.Config.Labels;
assert.equal(labels["org.opencontainers.image.version"], version);
assert.equal(labels["org.opencontainers.image.revision"], revision);
assert.equal(labels["tv.piik.server.sha256"], server.sha256);
}
const tag = `${destination}:${version}`;
function manifest(reference) {
// manifest inspect reconstructs the list and drops descriptor annotations.
try { return JSON.parse(run("docker", "buildx", "imagetools", "inspect", "--raw", reference)); }
catch (error) {
// Authentication/network failures are not evidence that a tag is absent.
if (String(error.stderr ?? "").trim().replace(/^ERROR: /, "") !== `${reference}: not found`) throw error;
return null;
}
}
function verifyIndex(reference, index) {
const platforms = index.manifests
.filter(item => item.annotations?.["vnd.docker.reference.type"] !== "attestation-manifest")
.map(item => `${item.platform.os}/${item.platform.architecture}`).sort();
assert.deepEqual(platforms,
linuxServers.map(server => `linux/${server.arch}`).sort(), "Container platforms differ from the release");
for (const server of linuxServers) {
run("docker", "pull", "--platform", `linux/${server.arch}`, reference);
verifyImage(reference, server);
}
}
for (const server of linuxServers) verifyImage(`${image}-${server.arch}`, server);
const existing = manifest(tag);
if (existing) {
verifyIndex(tag, existing);
process.stdout.write(`${tag} already exists; retained without replacement.\n`);
} else {
const parts = linuxServers.map(server => ({ server, tag: `${tag}-${server.arch}` }));
// Validate every existing platform before publishing any missing sibling.
for (const part of parts) {
part.exists = manifest(part.tag) !== null;
if (part.exists) {
run("docker", "pull", "--platform", `linux/${part.server.arch}`, part.tag);
verifyImage(part.tag, part.server);
}
}
for (const part of parts) {
if (part.exists) continue;
run("docker", "tag", `${image}-${part.server.arch}`, part.tag);
run("docker", "push", part.tag);
}
run("docker", "buildx", "imagetools", "create", "--tag", tag, ...parts.map(part => part.tag));
verifyIndex(tag, manifest(tag));
}
// Retrying an older release must never move latest backwards.
if (gh("releases/latest").tag_name === version) {
run("docker", "buildx", "imagetools", "create", "--tag", `${destination}:latest`, tag);
verifyIndex(`${destination}:latest`, manifest(`${destination}:latest`));
}
process.stdout.write(`Container publication complete: ${tag}\n`);