mirror of https://github.com/portainer/portainer
Added VolumesFrom to container start.
parent
4d22a04484
commit
c8213bbf33
|
@ -1,7 +1,14 @@
|
||||||
angular.module('startContainer', [])
|
angular.module('startContainer', [])
|
||||||
.controller('StartContainerController', ['$scope', '$routeParams', '$location', 'Container', 'Messages',
|
.controller('StartContainerController', ['$scope', '$routeParams', '$location', 'Container', 'Messages', 'containernameFilter',
|
||||||
function($scope, $routeParams, $location, Container, Messages) {
|
function($scope, $routeParams, $location, Container, Messages, containernameFilter) {
|
||||||
$scope.template = 'app/components/startContainer/startcontainer.html';
|
$scope.template = 'app/components/startContainer/startcontainer.html';
|
||||||
|
|
||||||
|
Container.query({all: 1}, function(d) {
|
||||||
|
$scope.containerNames = d.map(function(container){
|
||||||
|
return containernameFilter(container);
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
$scope.config = {
|
$scope.config = {
|
||||||
name: '',
|
name: '',
|
||||||
memory: 0,
|
memory: 0,
|
||||||
|
@ -9,7 +16,7 @@ function($scope, $routeParams, $location, Container, Messages) {
|
||||||
cpuShares: 1024,
|
cpuShares: 1024,
|
||||||
env: [],
|
env: [],
|
||||||
commands: '',
|
commands: '',
|
||||||
volumesFrom: '',
|
volumesFrom: [],
|
||||||
portBindings: []
|
portBindings: []
|
||||||
};
|
};
|
||||||
$scope.commandPlaceholder = '["/bin/echo", "Hello world"]';
|
$scope.commandPlaceholder = '["/bin/echo", "Hello world"]';
|
||||||
|
@ -28,6 +35,10 @@ function($scope, $routeParams, $location, Container, Messages) {
|
||||||
var loc = $location;
|
var loc = $location;
|
||||||
var s = $scope;
|
var s = $scope;
|
||||||
|
|
||||||
|
var volumesFrom = $scope.config.volumesFrom.map(function(volume) {
|
||||||
|
return volume.name;
|
||||||
|
});
|
||||||
|
|
||||||
var env = $scope.config.env.map(function(envar) {
|
var env = $scope.config.env.map(function(envar) {
|
||||||
return envar.name + '=' + envar.value;
|
return envar.name + '=' + envar.value;
|
||||||
});
|
});
|
||||||
|
@ -60,7 +71,7 @@ function($scope, $routeParams, $location, Container, Messages) {
|
||||||
MemorySwap: $scope.config.memorySwap,
|
MemorySwap: $scope.config.memorySwap,
|
||||||
CpuShares: $scope.config.cpuShares,
|
CpuShares: $scope.config.cpuShares,
|
||||||
Cmd: cmds,
|
Cmd: cmds,
|
||||||
VolumesFrom: $scope.config.volumesFrom,
|
VolumesFrom: volumesFrom,
|
||||||
Env: env,
|
Env: env,
|
||||||
ExposedPorts: exposedPorts,
|
ExposedPorts: exposedPorts,
|
||||||
HostConfig: {
|
HostConfig: {
|
||||||
|
@ -104,4 +115,13 @@ function($scope, $routeParams, $location, Container, Messages) {
|
||||||
var idx = $scope.config.env.indexOf(envar);
|
var idx = $scope.config.env.indexOf(envar);
|
||||||
$scope.config.env.splice(idx, 1);
|
$scope.config.env.splice(idx, 1);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
$scope.addVolume = function() {
|
||||||
|
$scope.config.volumesFrom.push({name: ''});
|
||||||
|
};
|
||||||
|
|
||||||
|
$scope.removeVolume = function(volume) {
|
||||||
|
var idx = $scope.config.volumesFrom.indexOf(volume);
|
||||||
|
$scope.config.volumesFrom.splice(idx, 1);
|
||||||
|
};
|
||||||
}]);
|
}]);
|
||||||
|
|
|
@ -1,9 +1,9 @@
|
||||||
describe('startContainerController', function () {
|
describe('startContainerController', function() {
|
||||||
var scope, $location, createController, mockContainer, $httpBackend;
|
var scope, $location, createController, mockContainer, $httpBackend;
|
||||||
|
|
||||||
beforeEach(angular.mock.module('dockerui'));
|
beforeEach(angular.mock.module('dockerui'));
|
||||||
|
|
||||||
beforeEach(inject(function ($rootScope, $controller, _$location_) {
|
beforeEach(inject(function($rootScope, $controller, _$location_) {
|
||||||
$location = _$location_;
|
$location = _$location_;
|
||||||
scope = $rootScope.$new();
|
scope = $rootScope.$new();
|
||||||
|
|
||||||
|
@ -13,13 +13,13 @@ describe('startContainerController', function () {
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
angular.mock.inject(function (_Container_, _$httpBackend_) {
|
angular.mock.inject(function(_Container_, _$httpBackend_) {
|
||||||
mockContainer = _Container_;
|
mockContainer = _Container_;
|
||||||
$httpBackend = _$httpBackend_;
|
$httpBackend = _$httpBackend_;
|
||||||
});
|
});
|
||||||
}));
|
}));
|
||||||
|
|
||||||
describe('Create and start a container with port bindings', function () {
|
describe('Create and start a container with port bindings', function() {
|
||||||
it('should issue a correct create request to the Docker remote API', function() {
|
it('should issue a correct create request to the Docker remote API', function() {
|
||||||
var controller = createController();
|
var controller = createController();
|
||||||
var id = '6abd8bfba81cf8a05a76a4bdefcb36c4b66cd02265f4bfcd0e236468696ebc6c';
|
var id = '6abd8bfba81cf8a05a76a4bdefcb36c4b66cd02265f4bfcd0e236468696ebc6c';
|
||||||
|
@ -29,19 +29,36 @@ describe('startContainerController', function () {
|
||||||
"MemorySwap": 0,
|
"MemorySwap": 0,
|
||||||
"CpuShares": 1024,
|
"CpuShares": 1024,
|
||||||
"Cmd": null,
|
"Cmd": null,
|
||||||
"VolumesFrom": "",
|
"VolumesFrom": [],
|
||||||
"Env": [],
|
"Env": [],
|
||||||
"ExposedPorts":{
|
"ExposedPorts": {
|
||||||
"9000/tcp": {},
|
"9000/tcp": {},
|
||||||
},
|
},
|
||||||
"HostConfig": {
|
"HostConfig": {
|
||||||
"PortBindings":{
|
"PortBindings": {
|
||||||
"9000/tcp": [{
|
"9000/tcp": [{
|
||||||
"HostPort": "9999",
|
"HostPort": "9999",
|
||||||
"HostIp": "10.20.10.15",
|
"HostIp": "10.20.10.15",
|
||||||
}]
|
}]
|
||||||
},
|
},
|
||||||
}};
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
$httpBackend.expectGET('/dockerapi/containers/json?all=1').respond([{
|
||||||
|
"Command": "./dockerui -e /docker.sock",
|
||||||
|
"Created": 1421817232,
|
||||||
|
"Id": "b17882378cee8ec0136f482681b764cca430befd52a9bfd1bde031f49b8bba9f",
|
||||||
|
"Image": "dockerui:latest",
|
||||||
|
"Names": ["/dockerui"],
|
||||||
|
"Ports": [{
|
||||||
|
"IP": "0.0.0.0",
|
||||||
|
"PrivatePort": 9000,
|
||||||
|
"PublicPort": 9000,
|
||||||
|
"Type": "tcp"
|
||||||
|
}],
|
||||||
|
"Status": "Up 2 minutes"
|
||||||
|
}]);
|
||||||
|
|
||||||
$httpBackend.expectPOST('/dockerapi/containers/create?name=container-name', expectedBody).respond({
|
$httpBackend.expectPOST('/dockerapi/containers/create?name=container-name', expectedBody).respond({
|
||||||
"Id": id,
|
"Id": id,
|
||||||
"Warnings": null
|
"Warnings": null
|
||||||
|
@ -52,14 +69,18 @@ describe('startContainerController', function () {
|
||||||
});
|
});
|
||||||
|
|
||||||
scope.config.name = 'container-name';
|
scope.config.name = 'container-name';
|
||||||
scope.config.portBindings = [{ip: '10.20.10.15', extPort: '9999', intPort: '9000'}]
|
scope.config.portBindings = [{
|
||||||
|
ip: '10.20.10.15',
|
||||||
|
extPort: '9999',
|
||||||
|
intPort: '9000'
|
||||||
|
}]
|
||||||
|
|
||||||
scope.create();
|
scope.create();
|
||||||
$httpBackend.flush();
|
$httpBackend.flush();
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
describe('Create and start a container with environment variables', function () {
|
describe('Create and start a container with environment variables', function() {
|
||||||
it('should issue a correct create request to the Docker remote API', function() {
|
it('should issue a correct create request to the Docker remote API', function() {
|
||||||
var controller = createController();
|
var controller = createController();
|
||||||
var id = '6abd8bfba81cf8a05a76a4bdefcb36c4b66cd02265f4bfcd0e236468696ebc6c';
|
var id = '6abd8bfba81cf8a05a76a4bdefcb36c4b66cd02265f4bfcd0e236468696ebc6c';
|
||||||
|
@ -69,11 +90,29 @@ describe('startContainerController', function () {
|
||||||
"MemorySwap": 0,
|
"MemorySwap": 0,
|
||||||
"CpuShares": 1024,
|
"CpuShares": 1024,
|
||||||
"Cmd": null,
|
"Cmd": null,
|
||||||
"VolumesFrom": "",
|
"VolumesFrom": [],
|
||||||
"Env":["SHELL=/bin/bash", "TERM=xterm-256color"],
|
"Env": ["SHELL=/bin/bash", "TERM=xterm-256color"],
|
||||||
"ExposedPorts":{},
|
"ExposedPorts": {},
|
||||||
"HostConfig": {"PortBindings":{}}
|
"HostConfig": {
|
||||||
|
"PortBindings": {}
|
||||||
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
$httpBackend.expectGET('/dockerapi/containers/json?all=1').respond([{
|
||||||
|
"Command": "./dockerui -e /docker.sock",
|
||||||
|
"Created": 1421817232,
|
||||||
|
"Id": "b17882378cee8ec0136f482681b764cca430befd52a9bfd1bde031f49b8bba9f",
|
||||||
|
"Image": "dockerui:latest",
|
||||||
|
"Names": ["/dockerui"],
|
||||||
|
"Ports": [{
|
||||||
|
"IP": "0.0.0.0",
|
||||||
|
"PrivatePort": 9000,
|
||||||
|
"PublicPort": 9000,
|
||||||
|
"Type": "tcp"
|
||||||
|
}],
|
||||||
|
"Status": "Up 2 minutes"
|
||||||
|
}]);
|
||||||
|
|
||||||
$httpBackend.expectPOST('/dockerapi/containers/create?name=container-name', expectedBody).respond({
|
$httpBackend.expectPOST('/dockerapi/containers/create?name=container-name', expectedBody).respond({
|
||||||
"Id": id,
|
"Id": id,
|
||||||
"Warnings": null
|
"Warnings": null
|
||||||
|
@ -84,7 +123,63 @@ describe('startContainerController', function () {
|
||||||
});
|
});
|
||||||
|
|
||||||
scope.config.name = 'container-name';
|
scope.config.name = 'container-name';
|
||||||
scope.config.env = [{name: 'SHELL', value: '/bin/bash'}, {name: 'TERM', value: 'xterm-256color'}];
|
scope.config.env = [{
|
||||||
|
name: 'SHELL',
|
||||||
|
value: '/bin/bash'
|
||||||
|
}, {
|
||||||
|
name: 'TERM',
|
||||||
|
value: 'xterm-256color'
|
||||||
|
}];
|
||||||
|
|
||||||
|
scope.create();
|
||||||
|
$httpBackend.flush();
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
describe('Create and start a container with volumesFrom', function() {
|
||||||
|
it('should issue a correct create request to the Docker remote API', function() {
|
||||||
|
var controller = createController();
|
||||||
|
var id = '6abd8bfba81cf8a05a76a4bdefcb36c4b66cd02265f4bfcd0e236468696ebc6c';
|
||||||
|
var expectedBody = {
|
||||||
|
"name": "container-name",
|
||||||
|
"Memory": 0,
|
||||||
|
"MemorySwap": 0,
|
||||||
|
"CpuShares": 1024,
|
||||||
|
"Cmd": null,
|
||||||
|
"VolumesFrom": ["parent", "other:ro"],
|
||||||
|
"Env": [],
|
||||||
|
"ExposedPorts": {},
|
||||||
|
"HostConfig": {
|
||||||
|
"PortBindings": {}
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
$httpBackend.expectGET('/dockerapi/containers/json?all=1').respond([{
|
||||||
|
"Command": "./dockerui -e /docker.sock",
|
||||||
|
"Created": 1421817232,
|
||||||
|
"Id": "b17882378cee8ec0136f482681b764cca430befd52a9bfd1bde031f49b8bba9f",
|
||||||
|
"Image": "dockerui:latest",
|
||||||
|
"Names": ["/dockerui"],
|
||||||
|
"Ports": [{
|
||||||
|
"IP": "0.0.0.0",
|
||||||
|
"PrivatePort": 9000,
|
||||||
|
"PublicPort": 9000,
|
||||||
|
"Type": "tcp"
|
||||||
|
}],
|
||||||
|
"Status": "Up 2 minutes"
|
||||||
|
}]);
|
||||||
|
|
||||||
|
$httpBackend.expectPOST('/dockerapi/containers/create?name=container-name', expectedBody).respond({
|
||||||
|
"Id": id,
|
||||||
|
"Warnings": null
|
||||||
|
});
|
||||||
|
$httpBackend.expectPOST('/dockerapi/containers/' + id + '/start?').respond({
|
||||||
|
"Id": id,
|
||||||
|
"Warnings": null
|
||||||
|
});
|
||||||
|
|
||||||
|
scope.config.name = 'container-name';
|
||||||
|
scope.config.volumesFrom = [{name: "parent"}, {name:"other:ro"}];
|
||||||
|
|
||||||
scope.create();
|
scope.create();
|
||||||
$httpBackend.flush();
|
$httpBackend.flush();
|
||||||
|
|
|
@ -30,8 +30,12 @@
|
||||||
<input type="number" ng-model="config.cpuShares" class="form-control"/>
|
<input type="number" ng-model="config.cpuShares" class="form-control"/>
|
||||||
</div>
|
</div>
|
||||||
<div class="form-group">
|
<div class="form-group">
|
||||||
<label>Volumes From:</label>
|
<label>Mount Volumes From other containers:</label>
|
||||||
<input type="text" ng-model="config.volumesFrom" class="form-control"/>
|
<div ng-repeat="volume in config.volumesFrom" class="form-inline">
|
||||||
|
<select ng-model="volume.name" ng-options="name for name in containerNames track by name"/>
|
||||||
|
<button class="btn btn-danger btn-xs form-control" ng-click="removeVolume($index)">Remove</button>
|
||||||
|
</div>
|
||||||
|
<button type="button" class="btn btn-success" ng-click="addVolume()">Add volume</button>
|
||||||
</div>
|
</div>
|
||||||
<div class="form-group">
|
<div class="form-group">
|
||||||
<label>Environment Variables:</label>
|
<label>Environment Variables:</label>
|
||||||
|
|
Loading…
Reference in New Issue