2015-02-19 21:21:54 +00:00
|
|
|
/**
|
|
|
|
* Helper service for returning information extracted from repository image metadata.
|
|
|
|
*/
|
|
|
|
angular.module('quay').factory('ImageMetadataService', ['UtilService', function(UtilService) {
|
|
|
|
var metadataService = {};
|
|
|
|
metadataService.getFormattedCommand = function(image) {
|
|
|
|
if (!image || !image.command || !image.command.length) {
|
|
|
|
return '';
|
|
|
|
}
|
|
|
|
|
|
|
|
var getCommandStr = function(command) {
|
|
|
|
// Handle /bin/sh commands specially.
|
|
|
|
if (command.length > 2 && command[0] == '/bin/sh' && command[1] == '-c') {
|
|
|
|
return command[2];
|
|
|
|
}
|
|
|
|
|
|
|
|
return command.join(' ');
|
|
|
|
};
|
|
|
|
|
|
|
|
return getCommandStr(image.command);
|
|
|
|
};
|
|
|
|
|
|
|
|
metadataService.getEscapedFormattedCommand = function(image) {
|
|
|
|
return UtilService.textToSafeHtml(metadataService.getFormattedCommand(image));
|
|
|
|
};
|
|
|
|
|
2016-02-22 23:39:04 +00:00
|
|
|
metadataService.getImageCommand = function(image, imageId) {
|
2016-03-04 23:07:44 +00:00
|
|
|
if (!image) {
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
|
2016-02-22 23:39:04 +00:00
|
|
|
if (!image.__imageMap) {
|
|
|
|
image.__imageMap = {};
|
2016-03-17 20:55:41 +00:00
|
|
|
image.__imageMap[image.id] = image;
|
|
|
|
|
2016-02-22 23:39:04 +00:00
|
|
|
for (var i = 0; i < image.history.length; ++i) {
|
|
|
|
var cimage = image.history[i];
|
|
|
|
image.__imageMap[cimage.id] = cimage;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-03-04 23:07:44 +00:00
|
|
|
var found = image.__imageMap[imageId];
|
|
|
|
if (!found) {
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
|
2016-03-09 20:28:21 +00:00
|
|
|
return metadataService.getDockerfileCommand(found.command);
|
2016-02-22 23:39:04 +00:00
|
|
|
};
|
|
|
|
|
2016-03-09 20:28:21 +00:00
|
|
|
metadataService.getDockerfileCommand = function(command) {
|
2016-02-22 23:39:04 +00:00
|
|
|
if (!command) { return ''; }
|
2016-03-10 20:02:38 +00:00
|
|
|
command = command.join(' ').split(' ');
|
2016-02-22 23:39:04 +00:00
|
|
|
|
2016-03-09 20:28:21 +00:00
|
|
|
// ["/bin/sh", "-c", "#(nop)", "RUN", "foo"]
|
2016-02-22 23:39:04 +00:00
|
|
|
if (command[0] != '/bin/sh' || command[1] != '-c') { return ''; }
|
|
|
|
|
2016-03-09 20:28:21 +00:00
|
|
|
var commandPrefix = '#(nop)';
|
|
|
|
if (command[2] != commandPrefix) {
|
|
|
|
return 'RUN ' + command.slice(2).join(' ');
|
2016-02-22 23:39:04 +00:00
|
|
|
}
|
|
|
|
|
2016-03-09 20:28:21 +00:00
|
|
|
return command.slice(3).join(' ');
|
2016-02-22 23:39:04 +00:00
|
|
|
};
|
|
|
|
|
2015-02-19 21:21:54 +00:00
|
|
|
return metadataService;
|
|
|
|
}]);
|