2018-02-01 12:27:52 +00:00
|
|
|
angular.module('portainer.docker')
|
2017-01-31 23:26:29 +00:00
|
|
|
.factory('ContainerHelper', [function ContainerHelperFactory() {
|
|
|
|
'use strict';
|
2017-02-10 05:11:00 +00:00
|
|
|
var helper = {};
|
|
|
|
|
|
|
|
helper.commandStringToArray = function(command) {
|
2018-11-07 20:53:19 +00:00
|
|
|
return splitargs(command, undefined, true);
|
2017-02-10 05:11:00 +00:00
|
|
|
};
|
|
|
|
|
2017-08-13 10:17:41 +00:00
|
|
|
helper.commandArrayToString = function(array) {
|
|
|
|
return array.map(function(elem) {
|
|
|
|
return '\'' + elem + '\'';
|
|
|
|
}).join(' ');
|
|
|
|
};
|
|
|
|
|
|
|
|
helper.configFromContainer = function(container) {
|
|
|
|
var config = container.Config;
|
|
|
|
// HostConfig
|
|
|
|
config.HostConfig = container.HostConfig;
|
|
|
|
// Name
|
|
|
|
config.name = container.Name.replace(/^\//g, '');
|
|
|
|
// Network
|
|
|
|
var mode = config.HostConfig.NetworkMode;
|
|
|
|
config.NetworkingConfig = {
|
|
|
|
'EndpointsConfig': {}
|
|
|
|
};
|
|
|
|
config.NetworkingConfig.EndpointsConfig = container.NetworkSettings.Networks;
|
|
|
|
if (mode.indexOf('container:') !== -1) {
|
|
|
|
delete config.Hostname;
|
|
|
|
delete config.ExposedPorts;
|
|
|
|
}
|
|
|
|
// Set volumes
|
|
|
|
var binds = [];
|
|
|
|
var volumes = {};
|
|
|
|
for (var v in container.Mounts) {
|
|
|
|
if ({}.hasOwnProperty.call(container.Mounts, v)) {
|
|
|
|
var mount = container.Mounts[v];
|
|
|
|
var name = mount.Name || mount.Source;
|
|
|
|
var containerPath = mount.Destination;
|
|
|
|
if (name && containerPath) {
|
|
|
|
var bind = name + ':' + containerPath;
|
|
|
|
volumes[containerPath] = {};
|
|
|
|
if (mount.RW === false) {
|
|
|
|
bind += ':ro';
|
|
|
|
}
|
|
|
|
binds.push(bind);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
config.HostConfig.Binds = binds;
|
|
|
|
config.Volumes = volumes;
|
|
|
|
return config;
|
|
|
|
};
|
|
|
|
|
2017-02-10 05:11:00 +00:00
|
|
|
return helper;
|
2017-01-31 23:26:29 +00:00
|
|
|
}]);
|