Fix DockerfileService to properly parse repo names and tags

Before this change, the tag name would be included in the image, which breaks the API
This commit is contained in:
Joseph Schorr 2017-02-22 16:26:47 -05:00
parent a726a12096
commit 7f1980bff1

View file

@ -12,20 +12,46 @@ angular.module('quay').factory('DockerfileService', ['DataFileService', 'Config'
DockerfileInfo.prototype.getRegistryBaseImage = function() {
var baseImage = this.getBaseImage();
if (!baseImage) {
return;
return null;
}
if (baseImage.indexOf(Config.getDomain() + '/') != 0) {
return;
return null;
}
return baseImage.substring(Config.getDomain().length + 1);
};
DockerfileInfo.prototype.getBaseImage = function() {
var imageAndTag = this.getBaseImageAndTag();
if (!imageAndTag) {
return null;
}
// Note, we have to handle a few different cases here:
// 1) someimage
// 2) someimage:tag
// 3) host:port/someimage
// 4) host:port/someimage:tag
var lastIndex = imageAndTag.lastIndexOf(':');
if (lastIndex < 0) {
return imageAndTag;
}
// Otherwise, check if there is a / in the portion after the split point. If so,
// then the latter is part of the path (and not a tag).
var afterColon = imageAndTag.substring(lastIndex + 1);
if (afterColon.indexOf('/') >= 0) {
return imageAndTag;
}
return imageAndTag.substring(0, lastIndex);
};
DockerfileInfo.prototype.getBaseImageAndTag = function() {
var fromIndex = this.contents.indexOf('FROM ');
if (fromIndex < 0) {
return;
return null;
}
var newline = this.contents.indexOf('\n', fromIndex);