Skip to content

armgit / Piik

Public Imported from GitHub
0

Free, open-source screen sharing for private live streams with friends. Watch together in a browser or self-host Piik. 免费开源的私密屏幕共享,支持游戏直播、一起看电影与自部署。

fix(ci): recognize BuildKit attestation manifests (#522)

TNTcraft4df364872e7d
diff --git a/scripts/publish-container.mjs b/scripts/publish-container.mjs
index 91d51a65..05cefb04 100644
--- a/scripts/publish-container.mjs
+++ b/scripts/publish-container.mjs
@@ -49,7 +49,10 @@ function manifest(reference) {
}
function verifyIndex(reference, index) {
- assert.deepEqual(index.manifests.map(item => `${item.platform.os}/${item.platform.architecture}`).sort(),
+ 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);
diff --git a/tests/publish-container.test.ts b/tests/publish-container.test.ts
index 9368c955..760bc309 100644
--- a/tests/publish-container.test.ts
+++ b/tests/publish-container.test.ts
@@ -17,13 +17,22 @@ const servers = [...linuxServers, {
type Scenario = { existing?: boolean; draft?: boolean; badArchive?: boolean;
wrongSource?: boolean; wrongImage?: boolean; remoteMismatch?: boolean;
registryError?: boolean; newerRelease?: boolean; largeCommit?: boolean;
- partial?: boolean; wrongPlatform?: boolean };
+ partial?: boolean; wrongPlatform?: boolean; attestation?: boolean; unknownPlatform?: boolean };
async function publish(options: Scenario = {}) {
vi.resetModules();
artifacts.mockReturnValue({ servers });
const platforms = ["amd64", "arm64"];
- const index = { manifests: platforms.map(architecture => ({ platform: { os: "linux", architecture } })) };
+ const index = { manifests: [
+ ...platforms.map(architecture => ({ platform: { os: "linux", architecture } })),
+ ...(options.attestation || options.unknownPlatform ? [{
+ platform: { os: "unknown", architecture: "unknown" },
+ ...(options.attestation ? { annotations: {
+ "vnd.docker.reference.type": "attestation-manifest",
+ "vnd.docker.reference.digest": `sha256:${digest}`,
+ } } : {}),
+ }] : []),
+ ] };
const manifests = new Map<string, object>();
if (options.existing) manifests.set(tag, index);
if (options.partial) manifests.set(`${tag}-arm64`, {});
@@ -86,6 +95,16 @@ describe("container publication", () => {
expect(pushes()).toEqual([`${tag}-amd64`, `${tag}-arm64`]);
expect(indexes()).toEqual([[tag, `${tag}-amd64`, `${tag}-arm64`], ["ghcr.io/tntcrafthim/piik:latest", tag]]);
});
+ it.each([false, true])("accepts BuildKit attestations in a new or retained index (existing=%s)", async (existing) => {
+ await publish({ existing, attestation: true });
+ expect(pushes()).toEqual(existing ? [] : [`${tag}-amd64`, `${tag}-arm64`]);
+ expect(indexes().at(-1)).toEqual(["ghcr.io/tntcrafthim/piik:latest", tag]);
+ });
+ it("rejects an unrecognized platform instead of treating it as an attestation", async () => {
+ await expect(publish({ existing: true, unknownPlatform: true })).rejects.toThrow("Container platforms differ");
+ expect(pushes()).toEqual([]);
+ expect(indexes()).toEqual([]);
+ });
it.each([
{ draft: true }, { badArchive: true }, { wrongSource: true }, { wrongImage: true },
{ registryError: true }, { existing: true, remoteMismatch: true },