From d9624053d2224e4a7fc11e8d94d30edc59671489 Mon Sep 17 00:00:00 2001 From: Anthony Lapenna Date: Fri, 10 Feb 2017 18:11:00 +1300 Subject: [PATCH] feat(templates): add support for the command field (#585) --- app/helpers/containerHelper.js | 32 +++++++++++++++++++------------- app/models/template.js | 1 + app/services/templateService.js | 7 +++---- bower.json | 3 ++- gruntfile.js | 1 + 5 files changed, 26 insertions(+), 18 deletions(-) diff --git a/app/helpers/containerHelper.js b/app/helpers/containerHelper.js index 101d9a108..3e806e24c 100644 --- a/app/helpers/containerHelper.js +++ b/app/helpers/containerHelper.js @@ -1,20 +1,26 @@ angular.module('portainer.helpers') .factory('ContainerHelper', [function ContainerHelperFactory() { 'use strict'; - return { - hideContainers: function(containers, containersToHideLabels) { - return containers.filter(function (container) { - var filterContainer = false; - containersToHideLabels.forEach(function(label, index) { - if (_.has(container.Labels, label.name) && - container.Labels[label.name] === label.value) { - filterContainer = true; - } - }); - if (!filterContainer) { - return container; + var helper = {}; + + helper.commandStringToArray = function(command) { + return splitargs(command); + }; + + helper.hideContainers = function(containers, containersToHideLabels) { + return containers.filter(function (container) { + var filterContainer = false; + containersToHideLabels.forEach(function(label, index) { + if (_.has(container.Labels, label.name) && + container.Labels[label.name] === label.value) { + filterContainer = true; } }); - } + if (!filterContainer) { + return container; + } + }); }; + + return helper; }]); diff --git a/app/models/template.js b/app/models/template.js index fb0bc70b1..d65eae553 100644 --- a/app/models/template.js +++ b/app/models/template.js @@ -4,6 +4,7 @@ function TemplateViewModel(data) { this.Logo = data.logo; this.Image = data.image; this.Registry = data.registry ? data.registry : ''; + this.Command = data.command ? data.command : ''; this.Env = data.env ? data.env : []; this.Volumes = data.volumes ? data.volumes : []; this.Ports = []; diff --git a/app/services/templateService.js b/app/services/templateService.js index 99cb2a8da..c63ee8731 100644 --- a/app/services/templateService.js +++ b/app/services/templateService.js @@ -1,5 +1,5 @@ angular.module('portainer.services') -.factory('TemplateService', ['$q', 'Template', 'TemplateHelper', 'ImageHelper', function TemplateServiceFactory($q, Template, TemplateHelper, ImageHelper) { +.factory('TemplateService', ['$q', 'Template', 'TemplateHelper', 'ImageHelper', 'ContainerHelper', function TemplateServiceFactory($q, Template, TemplateHelper, ImageHelper, ContainerHelper) { 'use strict'; var service = {}; @@ -39,9 +39,8 @@ angular.module('portainer.services') configuration.HostConfig.NetworkMode = network.Name; configuration.name = containerName; configuration.Image = template.Image; - if (template.Env) { - configuration.Env = TemplateHelper.EnvToStringArray(template.Env, containerMapping); - } + configuration.Env = TemplateHelper.EnvToStringArray(template.Env, containerMapping); + configuration.Cmd = ContainerHelper.commandStringToArray(template.Command); var portConfiguration = TemplateHelper.portArrayToPortConfiguration(template.Ports); configuration.HostConfig.PortBindings = portConfiguration.bindings; configuration.ExposedPorts = portConfiguration.exposedPorts; diff --git a/bower.json b/bower.json index d69e8403e..a75b42cef 100644 --- a/bower.json +++ b/bower.json @@ -44,7 +44,8 @@ "moment": "~2.14.1", "xterm.js": "~2.0.1", "font-awesome": "~4.7.0", - "ng-file-upload": "~12.2.13" + "ng-file-upload": "~12.2.13", + "splitargs": "~0.2.0" }, "resolutions": { "angular": "1.5.5" diff --git a/gruntfile.js b/gruntfile.js index cbd083dfc..61680ff5d 100644 --- a/gruntfile.js +++ b/gruntfile.js @@ -129,6 +129,7 @@ module.exports = function (grunt) { 'bower_components/bootstrap/dist/js/bootstrap.min.js', 'bower_components/Chart.js/Chart.min.js', 'bower_components/lodash/dist/lodash.min.js', + 'bower_components/splitargs/src/splitargs.js', 'bower_components/filesize/lib/filesize.min.js', 'bower_components/moment/min/moment.min.js', 'bower_components/xterm.js/dist/xterm.js',