Skip to content

Commit 65d9fe8

Browse files
author
Brad van der Laan
committed
Update Manifest query to handle both schema versions
The Manifest API will return information about the image or tag. This information is stored in a schema, that schema has two versions. For older Docker clients/ registries the v1 schema is returned by default; however, newer registries can return either v1 or v2. The API requires that you set a header to tell it which schema version you want. PR kwk#101 added the use of the Manifest API so we can show the Dockerfile, and size, and labels, etc. It is setting the header of the request so that we get the v2 version of the schema however it is parsing/expecting the V1 version of the schema. If we are using an older registry (i.e. 2.1.1) then this works because the header is ignored and only the V1 is returned; however, if using a newer version (i.e. 2.6.2) the v2 schema would be returned and not parsed correctly. PR kwk#168 modifies the use of the Manifest API so that it _does_ parse/expect the V2 schema; however, that means that the app will no longer work in older registries (or for images pushed by older clients) as it no longer supportes the V1 schema. This change set merged these two PRs together by checking the content type header in the response to figure out which version the registry returned. It then parses the payload depending on the schema version. With this change the user gets a very similar experance regardless of the manifest schema version being returned. Note: There is likly room for performance improvments here, I plan on a larger refactor and will like to address the ineffeciencies their
1 parent c144a1d commit 65d9fe8

File tree

4 files changed

+223
-104
lines changed

4 files changed

+223
-104
lines changed

app/image/image-controller.js

Lines changed: 25 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -13,24 +13,41 @@ angular.module('image-controller', ['registry-services', 'app-mode-services'])
1313

1414

1515
$scope.appMode = AppMode.query();
16-
$scope.totalImageSize = 0;
17-
$scope.imageDetails = Manifest.query({repository: $scope.repository, tagName: $scope.tagName});
16+
Manifest.query({repository: $scope.repository, tagName: $scope.tagName})
17+
.$promise.then(function(data) {
18+
$scope.imageDetails = angular.copy(data);
19+
20+
return !data.isSchemaV2
21+
? undefined
22+
: Blob.query({repository: $scope.repository, digest: 'sha256:'+data.id})
23+
.$promise.then(function(config) {
24+
$scope.imageDetails.created = config.created;
25+
$scope.imageDetails.docker_version = config.docker_version;
26+
$scope.imageDetails.os = config.os;
27+
$scope.imageDetails.architecture = config.architecture;
28+
$scope.imageDetails.labels = config.container_config && config.container_config.Labels;
29+
$scope.imageDetails.dockerfile = config.dockerfile;
30+
$scope.imageDetails.layers = config.dockerfile.length;
31+
32+
$scope.totalImageSize = $scope.imageDetails.size;
33+
});
34+
});
1835

1936

2037

2138
/**
2239
* Calculates the total download size for the image based on
2340
* it's layers.
2441
*/
25-
$scope.totalImageSize = null;
2642
$scope.calculateTotalImageSize = function() {
2743
$scope.totalImageSize = 0;
2844
angular.forEach($scope.imageDetails.fsLayers, function (id, key) {
29-
Blob.query({repository: $scope.repository, digest: id.blobSum}).$promise.then(function(data){
30-
if(!isNaN(data.contentLength-0)){
31-
$scope.totalImageSize += data.contentLength;
32-
}
33-
});
45+
Blob.querySize({repository: $scope.repository, digest: id.blobSum})
46+
.$promise.then(function(data){
47+
if(!isNaN(data.contentLength-0)){
48+
$scope.totalImageSize += data.contentLength;
49+
}
50+
});
3451
});
3552
};
3653
}]);

app/image/image-details-directive.html

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -14,21 +14,21 @@ <h2>
1414
General information
1515
</tab-heading>
1616
<form class="form-horizontal" role="form">
17-
<div class="form-group">
17+
<div class="form-group" ng-show="imageDetails.labels.maintainer || imageDetails.author">
1818
<label class="col-sm-2 control-label"><span class="glyphicon glyphicon-user"></span> Author</label>
1919
<div class="col-sm-10">
2020
<p class="form-control-static">{{imageDetails.labels.maintainer || imageDetails.author}}</p>
2121
</div>
2222
</div>
23-
<div class="form-group" ng-if="imageDetails.comment">
23+
<div class="form-group" ng-show="imageDetails.comment">
2424
<label class="col-sm-2 control-label"><span class="glyphicon glyphicon-comment"></span> Comment</label>
2525
<div class="col-sm-10">
2626
<p class="form-control-static">
2727
<pre>{{imageDetails.comment}}</pre>
2828
</p>
2929
</div>
3030
</div>
31-
<div class="form-group" >
31+
<div class="form-group" ng-show="imageDetails.created" >
3232
<label class="col-sm-2 control-label"><span class="glyphicon glyphicon-calendar"></span> Created</label>
3333
<div class="col-sm-10">
3434
<p class="form-control-static">
@@ -37,25 +37,25 @@ <h2>
3737
</p>
3838
</div>
3939
</div>
40-
<div class="form-group">
40+
<div class="form-group" ng-show="imageDetails.layers">
4141
<label class="col-sm-2 control-label"><span class="glyphicon glyphicon-align-justify"></span> Layers</label>
4242
<div class="col-sm-10">
4343
<p class="form-control-static">{{imageDetails.layers}}</p>
4444
</div>
4545
</div>
46-
<div class="form-group">
46+
<div class="form-group" ng-show="imageDetails.docker_version">
4747
<label class="col-sm-2 control-label"><span class="glyphicon glyphicon-eye-open"></span> Docker version</label>
4848
<div class="col-sm-10">
4949
<p class="form-control-static">{{imageDetails.docker_version}}</p>
5050
</div>
5151
</div>
52-
<div class="form-group">
52+
<div class="form-group" ng-show="imageDetails.os || imageDetails.architecture">
5353
<label class="col-sm-2 control-label"><span class="glyphicon glyphicon-cog"></span> OS</label>
5454
<div class="col-sm-10">
5555
<p class="form-control-static">{{imageDetails.os}}/{{imageDetails.architecture}}</p>
5656
</div>
5757
</div>
58-
<div class="form-group">
58+
<div class="form-group" ng-show="imageDetails.id">
5959
<label class="col-sm-2 control-label"><span class="glyphicon glyphicon-qrcode"></span> ID</label>
6060
<div class="col-sm-10">
6161
<p class="form-control-static">
@@ -75,10 +75,10 @@ <h2>
7575
<label class="col-sm-2 control-label"><span class="glyphicon glyphicon-compressed"></span> Size <small>(including base image sizes)</small></label>
7676
<div class="col-sm-10">
7777
<p class="form-control-static">
78-
<span ng-show="totalImageSize!==null">
78+
<span ng-show="totalImageSize!==undefined">
7979
{{totalImageSize/1024/1024 | number: 2}} <b>MB</b>
8080
</span>
81-
<button type="submit" class="btn btn-info" ng-click="calculateTotalImageSize()" ng-show="totalImageSize===null">
81+
<button type="submit" class="btn btn-info" ng-click="calculateTotalImageSize()" ng-show="totalImageSize===undefined">
8282
<span class="glyphicon glyphicon-stats"></span> Calculate
8383
</button>
8484
</p>

0 commit comments

Comments
 (0)