46b4ea8e3e
Fixes #1297
66 lines
No EOL
1.7 KiB
JavaScript
66 lines
No EOL
1.7 KiB
JavaScript
/**
|
|
* 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));
|
|
};
|
|
|
|
metadataService.getImageCommand = function(image, imageId) {
|
|
if (!image) {
|
|
return null;
|
|
}
|
|
|
|
if (!image.__imageMap) {
|
|
image.__imageMap = {};
|
|
image.__imageMap[image.id] = image;
|
|
|
|
for (var i = 0; i < image.history.length; ++i) {
|
|
var cimage = image.history[i];
|
|
image.__imageMap[cimage.id] = cimage;
|
|
}
|
|
}
|
|
|
|
var found = image.__imageMap[imageId];
|
|
if (!found) {
|
|
return null;
|
|
}
|
|
|
|
return metadataService.getDockerfileCommand(found.command);
|
|
};
|
|
|
|
metadataService.getDockerfileCommand = function(command) {
|
|
if (!command) { return ''; }
|
|
command = command.join(' ').split(' ');
|
|
|
|
// ["/bin/sh", "-c", "#(nop)", "RUN", "foo"]
|
|
if (command[0] != '/bin/sh' || command[1] != '-c') { return ''; }
|
|
|
|
var commandPrefix = '#(nop)';
|
|
if (command[2] != commandPrefix) {
|
|
return 'RUN ' + command.slice(2).join(' ');
|
|
}
|
|
|
|
return command.slice(3).join(' ');
|
|
};
|
|
|
|
return metadataService;
|
|
}]); |