Skip to content

Commit

Permalink
fix: buildx multiarch image date and history not shown (Joxit#309)
Browse files Browse the repository at this point in the history
Support images created with buildx and `--provenance true`

fixes Joxit#309
  • Loading branch information
Joxit committed May 20, 2023
1 parent d2222be commit 9ebbbc3
Show file tree
Hide file tree
Showing 5 changed files with 1,305 additions and 4 deletions.
24 changes: 20 additions & 4 deletions src/scripts/docker-image.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,26 @@
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
import { Http } from './http';
import { isDigit, eventTransfer, ERROR_CAN_NOT_READ_CONTENT_DIGEST } from './utils';
import { Http } from './http.js';
import { eventTransfer, ERROR_CAN_NOT_READ_CONTENT_DIGEST } from './utils.js';
import observable from '@riotjs/observable';

export const supportListManifest = (response) => {
if (response.mediaType === 'application/vnd.docker.distribution.manifest.list.v2+json') {
return true;
}
if (response.mediaType === 'application/vnd.oci.image.index.v1+json' && Array.isArray(response.manifests)) {
return !response.manifests.some(({ mediaType }) => mediaType !== 'application/vnd.oci.image.manifest.v1+json');
}
return false;
};

export const filterWrongManifests = (response) => {
return response.manifests.filter(
({ annotations }) => !annotations || annotations['vnd.docker.reference.type'] !== 'attestation-manifest'
);
};

export class DockerImage {
constructor(name, tag, { list, registryUrl, onNotify, onAuthentication, useControlCacheHeader }) {
this.name = name;
Expand Down Expand Up @@ -73,8 +89,8 @@ export class DockerImage {
oReq.addEventListener('loadend', function () {
if (this.status === 200 || this.status === 202) {
const response = JSON.parse(this.responseText);
if (response.mediaType === 'application/vnd.docker.distribution.manifest.list.v2+json' && self.opts.list) {
self.trigger('list', response);
if (supportListManifest(response) && self.opts.list) {
self.trigger('list', filterWrongManifests(response));
const manifest = response.manifests[0];
const image = new DockerImage(self.name, manifest.digest, { ...self.opts, list: false });
eventTransfer(image, self);
Expand Down
45 changes: 45 additions & 0 deletions test/docker-image.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
import { supportListManifest, filterWrongManifests } from '../src/scripts/docker-image.js';
import { dockerManifestList } from './fixtures/docker-manifest-list.js';
import { ociImageIndexLayer } from './fixtures/oci-image-index-layer.js';
import { ociImageIndexManifest } from './fixtures/oci-image-index-manifest.js';
import assert from 'assert';

describe('docker-image', () => {
describe('supportListManifest', () => {
/**
* Manifest of an image created with:
* docker buildx build --platform amd64,arm -t joxit/docker-registry-ui:buildx --push --provenance false .
*/
it('should support mediaType `application/vnd.docker.distribution.manifest.list.v2+json`', () => {
assert.ok(supportListManifest(dockerManifestList['application/vnd.docker.distribution.manifest.list.v2+json']));
});
/**
* Index of an image created with:
* docker buildx build --platform amd64,arm -t joxit/docker-registry-ui:buildx --push --provenance true .
*/
it('should support mediaType `application/vnd.oci.image.index.v1+json`', () => {
assert.ok(supportListManifest(ociImageIndexManifest['application/vnd.oci.image.index.v1+json']));
});
/**
* Index of an image created with:
* buildctl build --frontend=dockerfile.v0 --local context=. --local dockerfile=. --export-cache type=registry,ref=joxit/docker-registry-ui:buildkit
*/
it('should not support mediaType `application/vnd.oci.image.index.v1+json` with layers (`application/vnd.oci.image.layer.v1.tar+gzip`)', () => {
assert.ok(!supportListManifest(ociImageIndexLayer['application/vnd.oci.image.index.v1+json']));
});
});
describe('supportListManifest', () => {
it('should return all manifests for `application/vnd.docker.distribution.manifest.list.v2+json`', () => {
assert.equal(
filterWrongManifests(dockerManifestList['application/vnd.docker.distribution.manifest.list.v2+json']).length,
2
);
});
it('should return all manifests for `application/vnd.oci.image.index.v1+json`', () => {
assert.equal(
filterWrongManifests(ociImageIndexManifest['application/vnd.oci.image.index.v1+json']).length,
2
);
});
});
});
Loading

0 comments on commit 9ebbbc3

Please sign in to comment.