From ca27e7f27a3d2debff73ec9d4f0867b0ba3f3aa8 Mon Sep 17 00:00:00 2001 From: Anthony Lapenna Date: Fri, 8 Jul 2016 15:40:13 +1200 Subject: [PATCH] fix(containerCreation): fix an issue when creating an image from a custom registry without automatic pulling (#50) --- .../createContainerController.js | 41 +++++++++++-------- 1 file changed, 23 insertions(+), 18 deletions(-) diff --git a/app/components/createContainer/createContainerController.js b/app/components/createContainer/createContainerController.js index d70676c89..7a761c04d 100644 --- a/app/components/createContainer/createContainerController.js +++ b/app/components/createContainer/createContainerController.js @@ -12,6 +12,8 @@ function ($scope, $state, Config, Container, Image, Volume, Network, Messages, e Registry: '' }; + $scope.imageConfig = {}; + $scope.config = { Env: [], HostConfig: { @@ -104,6 +106,23 @@ function ($scope, $state, Config, Container, Image, Volume, Network, Messages, e }); } + function pullImageAndCreateContainer(config) { + $('#createContainerSpinner').show(); + Image.create($scope.imageConfig, function (data) { + var err = data.length > 0 && data[data.length - 1].hasOwnProperty('error'); + if (err) { + var detail = data[data.length - 1]; + $('#createContainerSpinner').hide(); + Messages.error('Error', detail.error); + } else { + createContainer(config); + } + }, function (e) { + $('#createContainerSpinner').hide(); + Messages.error('Error', 'Unable to pull image ' + image); + }); + } + function createImageConfig(imageName, registry) { var imageNameAndTag = imageName.split(':'); var image = imageNameAndTag[0]; @@ -117,27 +136,12 @@ function ($scope, $state, Config, Container, Image, Volume, Network, Messages, e return imageConfig; } - function pullImageAndCreateContainer(config) { - $('#createContainerSpinner').show(); - + function prepareImageConfig(config) { var image = _.toLower(config.Image); - var registry = _.toLower($scope.formValues.Registry); + var registry = $scope.formValues.Registry; var imageConfig = createImageConfig(image, registry); config.Image = imageConfig.fromImage + ':' + imageConfig.tag; - - Image.create(imageConfig, function (data) { - var err = data.length > 0 && data[data.length - 1].hasOwnProperty('error'); - if (err) { - var detail = data[data.length - 1]; - $('#createContainerSpinner').hide(); - Messages.error('Error', detail.error); - } else { - createContainer(config); - } - }, function (e) { - $('#createContainerSpinner').hide(); - Messages.error('Error', 'Unable to pull image ' + image); - }); + $scope.imageConfig = imageConfig; } function preparePortBindings(config) { @@ -199,6 +203,7 @@ function ($scope, $state, Config, Container, Image, Volume, Network, Messages, e function prepareConfiguration() { var config = angular.copy($scope.config); + prepareImageConfig(config); preparePortBindings(config); prepareConsole(config); prepareEnvironmentVariables(config);