feat(templates): add support for the template registry field

pull/383/head
Anthony Lapenna 2016-12-14 09:33:24 +13:00 committed by GitHub
parent 8869a2c79c
commit b5bf7cdead
7 changed files with 33 additions and 42 deletions

View File

@ -77,7 +77,7 @@ function ($scope, $state, $stateParams, $filter, Container, ContainerCommit, Ima
$('#createImageSpinner').show(); $('#createImageSpinner').show();
var image = _.toLower($scope.config.Image); var image = _.toLower($scope.config.Image);
var registry = _.toLower($scope.config.Registry); var registry = _.toLower($scope.config.Registry);
var imageConfig = ImageHelper.createImageConfig(image, registry); var imageConfig = ImageHelper.createImageConfigForCommit(image, registry);
ContainerCommit.commit({id: $stateParams.id, tag: imageConfig.tag, repo: imageConfig.repo}, function (d) { ContainerCommit.commit({id: $stateParams.id, tag: imageConfig.tag, repo: imageConfig.repo}, function (d) {
$('#createImageSpinner').hide(); $('#createImageSpinner').hide();
update(); update();

View File

@ -1,6 +1,6 @@
angular.module('createContainer', []) angular.module('createContainer', [])
.controller('CreateContainerController', ['$scope', '$state', '$stateParams', '$filter', 'Config', 'Info', 'Container', 'ContainerHelper', 'Image', 'Volume', 'Network', 'Messages', .controller('CreateContainerController', ['$scope', '$state', '$stateParams', '$filter', 'Config', 'Info', 'Container', 'ContainerHelper', 'Image', 'ImageHelper', 'Volume', 'Network', 'Messages',
function ($scope, $state, $stateParams, $filter, Config, Info, Container, ContainerHelper, Image, Volume, Network, Messages) { function ($scope, $state, $stateParams, $filter, Config, Info, Container, ContainerHelper, Image, ImageHelper, Volume, Network, Messages) {
$scope.formValues = { $scope.formValues = {
alwaysPull: true, alwaysPull: true,
@ -143,23 +143,10 @@ function ($scope, $state, $stateParams, $filter, Config, Info, Container, Contai
}); });
} }
function createImageConfig(imageName, registry) {
var imageNameAndTag = imageName.split(':');
var image = imageNameAndTag[0];
if (registry) {
image = registry + '/' + imageNameAndTag[0];
}
var imageConfig = {
fromImage: image,
tag: imageNameAndTag[1] ? imageNameAndTag[1] : 'latest'
};
return imageConfig;
}
function prepareImageConfig(config) { function prepareImageConfig(config) {
var image = _.toLower(config.Image); var image = _.toLower(config.Image);
var registry = $scope.formValues.Registry; var registry = $scope.formValues.Registry;
var imageConfig = createImageConfig(image, registry); var imageConfig = ImageHelper.createImageConfigForContainer(image, registry);
config.Image = imageConfig.fromImage + ':' + imageConfig.tag; config.Image = imageConfig.fromImage + ':' + imageConfig.tag;
$scope.imageConfig = imageConfig; $scope.imageConfig = imageConfig;
} }

View File

@ -69,8 +69,8 @@ function ($scope, $state, Service, Volume, Network, ImageHelper, Messages) {
}; };
function prepareImageConfig(config, input) { function prepareImageConfig(config, input) {
var imageConfig = ImageHelper.createImageConfig(input.Image, input.Registry); var imageConfig = ImageHelper.createImageConfigForContainer(input.Image, input.Registry);
config.TaskTemplate.ContainerSpec.Image = imageConfig.repo + ':' + imageConfig.tag; config.TaskTemplate.ContainerSpec.Image = imageConfig.fromImage + ':' + imageConfig.tag;
} }
function preparePortsConfig(config, input) { function preparePortsConfig(config, input) {

View File

@ -23,7 +23,7 @@ function ($scope, $stateParams, $state, Image, ImageHelper, Messages) {
$('#loadingViewSpinner').show(); $('#loadingViewSpinner').show();
var image = _.toLower($scope.config.Image); var image = _.toLower($scope.config.Image);
var registry = _.toLower($scope.config.Registry); var registry = _.toLower($scope.config.Registry);
var imageConfig = ImageHelper.createImageConfig(image, registry); var imageConfig = ImageHelper.createImageConfigForCommit(image, registry);
Image.tag({id: $stateParams.id, tag: imageConfig.tag, repo: imageConfig.repo}, function (d) { Image.tag({id: $stateParams.id, tag: imageConfig.tag, repo: imageConfig.repo}, function (d) {
Messages.send('Image successfully tagged'); Messages.send('Image successfully tagged');
$('#loadingViewSpinner').hide(); $('#loadingViewSpinner').hide();

View File

@ -1,6 +1,6 @@
angular.module('images', []) angular.module('images', [])
.controller('ImagesController', ['$scope', '$state', 'Config', 'Image', 'Messages', 'Settings', .controller('ImagesController', ['$scope', '$state', 'Config', 'Image', 'ImageHelper', 'Messages', 'Settings',
function ($scope, $state, Config, Image, Messages, Settings) { function ($scope, $state, Config, Image, ImageHelper, Messages, Settings) {
$scope.state = {}; $scope.state = {};
$scope.sortType = 'RepoTags'; $scope.sortType = 'RepoTags';
$scope.sortReverse = true; $scope.sortReverse = true;
@ -25,24 +25,11 @@ function ($scope, $state, Config, Image, Messages, Settings) {
} }
}; };
function createImageConfig(imageName, registry) {
var imageNameAndTag = imageName.split(':');
var image = imageNameAndTag[0];
if (registry) {
image = registry + '/' + imageNameAndTag[0];
}
var imageConfig = {
fromImage: image,
tag: imageNameAndTag[1] ? imageNameAndTag[1] : 'latest'
};
return imageConfig;
}
$scope.pullImage = function() { $scope.pullImage = function() {
$('#pullImageSpinner').show(); $('#pullImageSpinner').show();
var image = _.toLower($scope.config.Image); var image = _.toLower($scope.config.Image);
var registry = _.toLower($scope.config.Registry); var registry = _.toLower($scope.config.Registry);
var imageConfig = createImageConfig(image, registry); var imageConfig = ImageHelper.createImageConfigForContainer(image, registry);
Image.create(imageConfig, function (data) { Image.create(imageConfig, function (data) {
var err = data.length > 0 && data[data.length - 1].hasOwnProperty('error'); var err = data.length > 0 && data[data.length - 1].hasOwnProperty('error');
if (err) { if (err) {

View File

@ -129,9 +129,18 @@ function ($scope, $q, $state, $filter, $anchorScroll, Config, Info, Container, C
}); });
} }
preparePortBindings(containerConfig, $scope.formValues.ports); preparePortBindings(containerConfig, $scope.formValues.ports);
prepareImageConfig(containerConfig, template);
return containerConfig; return containerConfig;
} }
function prepareImageConfig(config, template) {
var image = _.toLower(template.image);
var registry = template.registry;
var imageConfig = ImageHelper.createImageConfigForContainer(image, registry);
config.Image = imageConfig.fromImage + ':' + imageConfig.tag;
$scope.imageConfig = imageConfig;
}
function prepareVolumeQueries(template, containerConfig) { function prepareVolumeQueries(template, containerConfig) {
var volumeQueries = []; var volumeQueries = [];
if (template.volumes) { if (template.volumes) {
@ -158,13 +167,9 @@ function ($scope, $q, $state, $filter, $anchorScroll, Config, Info, Container, C
$('#createContainerSpinner').show(); $('#createContainerSpinner').show();
var template = $scope.state.selectedTemplate; var template = $scope.state.selectedTemplate;
var containerConfig = createConfigFromTemplate(template); var containerConfig = createConfigFromTemplate(template);
var imageConfig = {
fromImage: template.image.split(':')[0],
tag: template.image.split(':')[1] ? template.image.split(':')[1] : 'latest'
};
var createVolumeQueries = prepareVolumeQueries(template, containerConfig); var createVolumeQueries = prepareVolumeQueries(template, containerConfig);
$q.all(createVolumeQueries).then(function (d) { $q.all(createVolumeQueries).then(function (d) {
pullImageAndCreateContainer(imageConfig, containerConfig); pullImageAndCreateContainer($scope.imageConfig, containerConfig);
}); });
}; };

View File

@ -2,7 +2,7 @@ angular.module('portainer.helpers', [])
.factory('ImageHelper', [function ImageHelperFactory() { .factory('ImageHelper', [function ImageHelperFactory() {
'use strict'; 'use strict';
return { return {
createImageConfig: function(imageName, registry) { createImageConfigForCommit: function(imageName, registry) {
var imageNameAndTag = imageName.split(':'); var imageNameAndTag = imageName.split(':');
var image = imageNameAndTag[0]; var image = imageNameAndTag[0];
if (registry) { if (registry) {
@ -13,6 +13,18 @@ angular.module('portainer.helpers', [])
tag: imageNameAndTag[1] ? imageNameAndTag[1] : 'latest' tag: imageNameAndTag[1] ? imageNameAndTag[1] : 'latest'
}; };
return imageConfig; return imageConfig;
},
createImageConfigForContainer: function (imageName, registry) {
var imageNameAndTag = imageName.split(':');
var image = imageNameAndTag[0];
if (registry) {
image = registry + '/' + imageNameAndTag[0];
}
var imageConfig = {
fromImage: image,
tag: imageNameAndTag[1] ? imageNameAndTag[1] : 'latest'
};
return imageConfig;
} }
}; };
}]) }])