Skip to content

Commit

Permalink
chore: allow to use index manifest without recommended mediaType field
Browse files Browse the repository at this point in the history
fixes redhat-developer/podman-desktop-demo#33
Signed-off-by: Florent Benoit <[email protected]>
  • Loading branch information
benoitf committed Dec 12, 2023
1 parent 8c21b28 commit 5adcc41
Show file tree
Hide file tree
Showing 2 changed files with 82 additions and 3 deletions.
75 changes: 75 additions & 0 deletions packages/main/src/plugin/image-registry.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -585,3 +585,78 @@ test('getBestManifest returns the expected manifest', () => {
imageRegistry.getBestManifest([manifests['windows-amd64'], manifests['darwin-amd64']], 'amd64', 'linux'),
).toBeUndefined();
});

test('getManifestFromUrl returns the expected manifest with mediaType', async () => {
const fakeManifest = {
schemaVersion: 2,
mediaType: 'application/vnd.oci.image.index.v1+json',
manifests: [],
};

// image index
nock('https://my-podman-desktop-fake-registry.io').get('/v2/foo/bar/manifests/latest').reply(200, fakeManifest);

// digest
nock('https://my-podman-desktop-fake-registry.io')
.get('/v2/foo/bar/manifests/1234')
.reply(200, JSON.stringify({ endManifest: true }));

// mock getBestManifest
const spyGetBestManifest = vi.spyOn(imageRegistry, 'getBestManifest');
spyGetBestManifest.mockReturnValue({
digest: 1234,
});

const manifest = await imageRegistry.getManifest(
{
name: 'foo/bar',
tag: 'latest',
registry: 'my-podman-desktop-fake-registry.io',
registryURL: 'https://my-podman-desktop-fake-registry.io/v2',
},
'dummyToken',
);

expect(manifest).toBeDefined();
expect(manifest).toHaveProperty('endManifest', true);
expect(spyGetBestManifest).toHaveBeenCalled();
});

test('getManifestFromUrl returns the expected manifest without mediaType but with manifests', async () => {
const fakeManifest = {
schemaVersion: 2,
manifests: [
{
dummyManifest: true,
},
],
};

// image index
nock('https://my-podman-desktop-fake-registry.io').get('/v2/foo/bar/manifests/latest').reply(200, fakeManifest);

// digest
nock('https://my-podman-desktop-fake-registry.io')
.get('/v2/foo/bar/manifests/1234')
.reply(200, JSON.stringify({ endManifest: true }));

// mock getBestManifest
const spyGetBestManifest = vi.spyOn(imageRegistry, 'getBestManifest');
spyGetBestManifest.mockReturnValue({
digest: 1234,
});

const manifest = await imageRegistry.getManifest(
{
name: 'foo/bar',
tag: 'latest',
registry: 'my-podman-desktop-fake-registry.io',
registryURL: 'https://my-podman-desktop-fake-registry.io/v2',
},
'dummyToken',
);

expect(manifest).toBeDefined();
expect(manifest).toHaveProperty('endManifest', true);
expect(spyGetBestManifest).toHaveBeenCalled();
});
10 changes: 7 additions & 3 deletions packages/main/src/plugin/image-registry.ts
Original file line number Diff line number Diff line change
Expand Up @@ -614,9 +614,13 @@ export class ImageRegistry {
}
}

// check mediaType of the manifest
// if it is application/vnd.oci.image.index.v1+json it is an index
if (parsedManifest.mediaType === 'application/vnd.oci.image.index.v1+json') {
// https://github.com/opencontainers/image-spec/blob/main/image-index.md
// check schemaVersion and (mediaType of the manifest or if it contains manifests field being an array)
if (
parsedManifest.schemaVersion === 2 &&
(parsedManifest.mediaType === 'application/vnd.oci.image.index.v1+json' ||
Array.isArray(parsedManifest.manifests))
) {
// need to grab correct manifest from the index corresponding to our platform
let platformArch: 'amd64' | 'arm64' = 'amd64';
const arch = os.arch();
Expand Down

0 comments on commit 5adcc41

Please sign in to comment.