diff --git a/static/js/services/dockerfile-service.js b/static/js/services/dockerfile-service.js index 42e6c5a6c..8763b8a13 100644 --- a/static/js/services/dockerfile-service.js +++ b/static/js/services/dockerfile-service.js @@ -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);