From 7f1980bff154f0432f350c2d27b79a4be55ff405 Mon Sep 17 00:00:00 2001 From: Joseph Schorr Date: Wed, 22 Feb 2017 16:26:47 -0500 Subject: [PATCH 1/2] 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 --- static/js/services/dockerfile-service.js | 32 +++++++++++++++++++++--- 1 file changed, 29 insertions(+), 3 deletions(-) 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); From baf4b7bed4ad75b01c6703e9909efb4c5050c4d0 Mon Sep 17 00:00:00 2001 From: Joseph Schorr Date: Wed, 22 Feb 2017 16:27:14 -0500 Subject: [PATCH 2/2] Change Dockerfile build form to not require a robot unless sure we need it Fixes #2377 Before this change, we'd err on the side of caution, which is bad UX --- static/js/directives/ui/dockerfile-build-form.js | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/static/js/directives/ui/dockerfile-build-form.js b/static/js/directives/ui/dockerfile-build-form.js index b2c0a4219..fdd705f21 100644 --- a/static/js/directives/ui/dockerfile-build-form.js +++ b/static/js/directives/ui/dockerfile-build-form.js @@ -27,10 +27,10 @@ angular.module('quay').directive('dockerfileBuildForm', function () { $scope.state = 'checking-image'; ApiService.getRepo(null, params).then(function(repository) { $scope.privateBaseRepository = repository.is_public ? null : baseImage; - $scope.state = 'awaiting-bot'; + $scope.state = repository.is_public ? 'ready' : 'awaiting-bot'; }, function() { - $scope.privateBaseRepository = baseImage; - $scope.state = 'awaiting-bot'; + $scope.privateBaseRepository = null; + $scope.state = 'ready'; }); };