2015-08-25 05:59:54 +00:00
|
|
|
describe('startContainerController', function () {
|
2015-01-19 05:20:49 +00:00
|
|
|
var scope, $location, createController, mockContainer, $httpBackend;
|
2015-01-21 05:31:57 +00:00
|
|
|
|
2016-09-04 02:50:37 +00:00
|
|
|
beforeEach(angular.mock.module('portainer'));
|
2015-01-19 05:20:49 +00:00
|
|
|
|
2015-08-25 05:59:54 +00:00
|
|
|
beforeEach(inject(function ($rootScope, $controller, _$location_) {
|
2015-01-19 05:20:49 +00:00
|
|
|
$location = _$location_;
|
|
|
|
scope = $rootScope.$new();
|
|
|
|
|
2015-08-25 05:59:54 +00:00
|
|
|
createController = function () {
|
2015-01-19 05:20:49 +00:00
|
|
|
return $controller('StartContainerController', {
|
|
|
|
'$scope': scope
|
|
|
|
});
|
|
|
|
};
|
|
|
|
|
2015-08-25 05:59:54 +00:00
|
|
|
angular.mock.inject(function (_Container_, _$httpBackend_) {
|
2015-01-19 05:20:49 +00:00
|
|
|
mockContainer = _Container_;
|
|
|
|
$httpBackend = _$httpBackend_;
|
|
|
|
});
|
|
|
|
}));
|
2015-01-25 21:52:40 +00:00
|
|
|
function expectGetContainers() {
|
|
|
|
$httpBackend.expectGET('dockerapi/containers/json?all=1').respond([{
|
2016-09-04 02:50:37 +00:00
|
|
|
'Command': './portainer -e /docker.sock',
|
2015-01-25 23:59:08 +00:00
|
|
|
'Created': 1421817232,
|
|
|
|
'Id': 'b17882378cee8ec0136f482681b764cca430befd52a9bfd1bde031f49b8bba9f',
|
2016-09-04 02:50:37 +00:00
|
|
|
'Image': 'portainer:latest',
|
|
|
|
'Names': ['/portainer'],
|
2015-01-25 23:59:08 +00:00
|
|
|
'Ports': [{
|
|
|
|
'IP': '0.0.0.0',
|
|
|
|
'PrivatePort': 9000,
|
|
|
|
'PublicPort': 9000,
|
|
|
|
'Type': 'tcp'
|
2015-01-25 21:52:40 +00:00
|
|
|
}],
|
2015-01-25 23:59:08 +00:00
|
|
|
'Status': 'Up 2 minutes'
|
2015-01-25 21:52:40 +00:00
|
|
|
}]);
|
|
|
|
}
|
2015-08-25 05:59:54 +00:00
|
|
|
|
|
|
|
describe('Create and start a container with port bindings', function () {
|
|
|
|
it('should issue a correct create request to the Docker remote API', function () {
|
2015-01-19 05:20:49 +00:00
|
|
|
var controller = createController();
|
|
|
|
var id = '6abd8bfba81cf8a05a76a4bdefcb36c4b66cd02265f4bfcd0e236468696ebc6c';
|
|
|
|
var expectedBody = {
|
2015-01-25 23:59:08 +00:00
|
|
|
'name': 'container-name',
|
|
|
|
'ExposedPorts': {
|
2015-03-12 21:28:01 +00:00
|
|
|
'9000/tcp': {}
|
2015-01-19 05:20:49 +00:00
|
|
|
},
|
2015-01-25 23:59:08 +00:00
|
|
|
'HostConfig': {
|
|
|
|
'PortBindings': {
|
|
|
|
'9000/tcp': [{
|
|
|
|
'HostPort': '9999',
|
2015-03-12 21:28:01 +00:00
|
|
|
'HostIp': '10.20.10.15'
|
2015-01-19 05:20:49 +00:00
|
|
|
}]
|
2015-03-12 21:28:01 +00:00
|
|
|
}
|
2015-01-21 05:31:57 +00:00
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2015-01-25 21:52:40 +00:00
|
|
|
expectGetContainers();
|
|
|
|
|
|
|
|
$httpBackend.expectPOST('dockerapi/containers/create?name=container-name', expectedBody).respond({
|
2015-01-25 23:59:08 +00:00
|
|
|
'Id': id,
|
|
|
|
'Warnings': null
|
2015-01-19 05:20:49 +00:00
|
|
|
});
|
2015-03-27 20:16:44 +00:00
|
|
|
$httpBackend.expectPOST('dockerapi/containers/' + id + '/start').respond({
|
2015-01-26 01:18:46 +00:00
|
|
|
'id': id,
|
2015-01-25 23:59:08 +00:00
|
|
|
'Warnings': null
|
2015-01-19 05:20:49 +00:00
|
|
|
});
|
|
|
|
|
|
|
|
scope.config.name = 'container-name';
|
2015-01-25 23:59:08 +00:00
|
|
|
scope.config.HostConfig.PortBindings = [{
|
2015-01-21 05:31:57 +00:00
|
|
|
ip: '10.20.10.15',
|
|
|
|
extPort: '9999',
|
|
|
|
intPort: '9000'
|
2015-03-12 21:28:01 +00:00
|
|
|
}];
|
2015-01-19 05:20:49 +00:00
|
|
|
|
|
|
|
scope.create();
|
2015-01-20 07:42:08 +00:00
|
|
|
$httpBackend.flush();
|
|
|
|
});
|
|
|
|
});
|
2015-01-19 05:20:49 +00:00
|
|
|
|
2015-08-25 05:59:54 +00:00
|
|
|
describe('Create and start a container with environment variables', function () {
|
|
|
|
it('should issue a correct create request to the Docker remote API', function () {
|
2015-01-20 07:42:08 +00:00
|
|
|
var controller = createController();
|
|
|
|
var id = '6abd8bfba81cf8a05a76a4bdefcb36c4b66cd02265f4bfcd0e236468696ebc6c';
|
|
|
|
var expectedBody = {
|
2015-01-25 23:59:08 +00:00
|
|
|
'name': 'container-name',
|
|
|
|
'Env': ['SHELL=/bin/bash', 'TERM=xterm-256color']
|
2015-01-20 07:42:08 +00:00
|
|
|
};
|
2015-01-21 05:31:57 +00:00
|
|
|
|
2015-01-25 21:52:40 +00:00
|
|
|
expectGetContainers();
|
|
|
|
|
|
|
|
$httpBackend.expectPOST('dockerapi/containers/create?name=container-name', expectedBody).respond({
|
2015-01-25 23:59:08 +00:00
|
|
|
'Id': id,
|
|
|
|
'Warnings': null
|
2015-01-21 05:31:57 +00:00
|
|
|
});
|
2015-03-27 20:16:44 +00:00
|
|
|
$httpBackend.expectPOST('dockerapi/containers/' + id + '/start').respond({
|
2015-01-26 01:18:46 +00:00
|
|
|
'id': id,
|
2015-01-25 23:59:08 +00:00
|
|
|
'Warnings': null
|
2015-01-21 05:31:57 +00:00
|
|
|
});
|
|
|
|
|
|
|
|
scope.config.name = 'container-name';
|
2015-01-25 21:52:40 +00:00
|
|
|
scope.config.Env = [{
|
2015-01-21 05:31:57 +00:00
|
|
|
name: 'SHELL',
|
|
|
|
value: '/bin/bash'
|
|
|
|
}, {
|
|
|
|
name: 'TERM',
|
|
|
|
value: 'xterm-256color'
|
|
|
|
}];
|
|
|
|
|
|
|
|
scope.create();
|
|
|
|
$httpBackend.flush();
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
2015-11-27 04:28:01 +00:00
|
|
|
describe('Create and start a container with labels', 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',
|
|
|
|
'Labels': {
|
|
|
|
"org.foo.bar": "Baz",
|
|
|
|
"com.biz.baz": "Boo"
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
expectGetContainers();
|
|
|
|
|
|
|
|
$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.Labels = [{
|
|
|
|
key: 'org.foo.bar',
|
|
|
|
value: 'Baz'
|
|
|
|
}, {
|
|
|
|
key: 'com.biz.baz',
|
|
|
|
value: 'Boo'
|
|
|
|
}];
|
|
|
|
|
|
|
|
scope.create();
|
|
|
|
$httpBackend.flush();
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
2015-08-25 05:59:54 +00:00
|
|
|
describe('Create and start a container with volumesFrom', function () {
|
|
|
|
it('should issue a correct create request to the Docker remote API', function () {
|
2015-01-21 05:31:57 +00:00
|
|
|
var controller = createController();
|
|
|
|
var id = '6abd8bfba81cf8a05a76a4bdefcb36c4b66cd02265f4bfcd0e236468696ebc6c';
|
|
|
|
var expectedBody = {
|
2015-01-25 21:52:40 +00:00
|
|
|
HostConfig: {
|
2015-01-25 23:59:08 +00:00
|
|
|
'VolumesFrom': ['parent', 'other:ro']
|
2015-01-25 21:52:40 +00:00
|
|
|
},
|
2015-01-25 23:59:08 +00:00
|
|
|
'name': 'container-name'
|
2015-01-21 05:31:57 +00:00
|
|
|
};
|
|
|
|
|
2015-01-25 21:52:40 +00:00
|
|
|
expectGetContainers();
|
|
|
|
|
2015-01-25 23:59:08 +00:00
|
|
|
$httpBackend.expectPOST('dockerapi/containers/create?name=container-name', expectedBody).respond({
|
|
|
|
'Id': id,
|
|
|
|
'Warnings': null
|
|
|
|
});
|
2015-03-27 20:16:44 +00:00
|
|
|
$httpBackend.expectPOST('dockerapi/containers/' + id + '/start').respond({
|
2015-01-26 01:18:46 +00:00
|
|
|
'id': id,
|
2015-01-25 23:59:08 +00:00
|
|
|
'Warnings': null
|
|
|
|
});
|
|
|
|
|
|
|
|
scope.config.name = 'container-name';
|
2015-08-25 05:59:54 +00:00
|
|
|
scope.config.HostConfig.VolumesFrom = [{name: 'parent'}, {name: 'other:ro'}];
|
2015-01-25 23:59:08 +00:00
|
|
|
|
|
|
|
scope.create();
|
|
|
|
$httpBackend.flush();
|
|
|
|
});
|
|
|
|
});
|
2015-08-25 05:59:54 +00:00
|
|
|
|
|
|
|
describe('Create and start a container with multiple options', function () {
|
|
|
|
it('should issue a correct create request to the Docker remote API', function () {
|
2015-01-25 23:59:08 +00:00
|
|
|
var controller = createController();
|
|
|
|
var id = '6abd8bfba81cf8a05a76a4bdefcb36c4b66cd02265f4bfcd0e236468696ebc6c';
|
|
|
|
var expectedBody = {
|
|
|
|
Volumes: ['/var/www'],
|
|
|
|
SecurityOpts: ['label:type:svirt_apache'],
|
|
|
|
HostConfig: {
|
|
|
|
Binds: ['/app:/app'],
|
|
|
|
Links: ['web:db'],
|
|
|
|
Dns: ['8.8.8.8'],
|
|
|
|
DnsSearch: ['example.com'],
|
|
|
|
CapAdd: ['cap_sys_admin'],
|
2015-01-28 08:28:41 +00:00
|
|
|
CapDrop: ['cap_foo_bar'],
|
2015-08-25 05:59:54 +00:00
|
|
|
Devices: [{
|
|
|
|
'PathOnHost': '/dev/deviceName',
|
|
|
|
'PathInContainer': '/dev/deviceName',
|
|
|
|
'CgroupPermissions': 'mrw'
|
|
|
|
}],
|
|
|
|
LxcConf: {'lxc.utsname': 'docker'},
|
2015-01-29 01:26:48 +00:00
|
|
|
ExtraHosts: ['hostname:127.0.0.1'],
|
2015-01-28 08:28:41 +00:00
|
|
|
RestartPolicy: {name: 'always', MaximumRetryCount: 5}
|
2015-01-25 23:59:08 +00:00
|
|
|
},
|
|
|
|
name: 'container-name'
|
|
|
|
};
|
|
|
|
|
|
|
|
expectGetContainers();
|
2015-01-25 21:52:40 +00:00
|
|
|
|
|
|
|
$httpBackend.expectPOST('dockerapi/containers/create?name=container-name', expectedBody).respond({
|
2015-01-25 23:59:08 +00:00
|
|
|
'Id': id,
|
|
|
|
'Warnings': null
|
2015-01-20 07:42:08 +00:00
|
|
|
});
|
2015-03-27 20:16:44 +00:00
|
|
|
$httpBackend.expectPOST('dockerapi/containers/' + id + '/start').respond({
|
2015-01-26 01:18:46 +00:00
|
|
|
'id': id,
|
2015-01-25 23:59:08 +00:00
|
|
|
'Warnings': null
|
2015-01-20 07:42:08 +00:00
|
|
|
});
|
|
|
|
|
|
|
|
scope.config.name = 'container-name';
|
2015-01-25 23:59:08 +00:00
|
|
|
scope.config.Volumes = [{name: '/var/www'}];
|
|
|
|
scope.config.SecurityOpts = [{name: 'label:type:svirt_apache'}];
|
|
|
|
scope.config.NetworkDisabled = true;
|
|
|
|
scope.config.Tty = true;
|
|
|
|
scope.config.OpenStdin = true;
|
|
|
|
scope.config.StdinOnce = true;
|
|
|
|
|
|
|
|
scope.config.HostConfig.Binds = [{name: '/app:/app'}];
|
|
|
|
scope.config.HostConfig.Links = [{name: 'web:db'}];
|
|
|
|
scope.config.HostConfig.Dns = [{name: '8.8.8.8'}];
|
|
|
|
scope.config.HostConfig.DnsSearch = [{name: 'example.com'}];
|
|
|
|
scope.config.HostConfig.CapAdd = [{name: 'cap_sys_admin'}];
|
|
|
|
scope.config.HostConfig.CapDrop = [{name: 'cap_foo_bar'}];
|
|
|
|
scope.config.HostConfig.PublishAllPorts = true;
|
|
|
|
scope.config.HostConfig.Privileged = true;
|
2015-01-28 08:28:41 +00:00
|
|
|
scope.config.HostConfig.RestartPolicy = {name: 'always', MaximumRetryCount: 5};
|
2015-08-25 05:59:54 +00:00
|
|
|
scope.config.HostConfig.Devices = [{
|
|
|
|
'PathOnHost': '/dev/deviceName',
|
|
|
|
'PathInContainer': '/dev/deviceName',
|
|
|
|
'CgroupPermissions': 'mrw'
|
|
|
|
}];
|
2015-01-28 08:28:41 +00:00
|
|
|
scope.config.HostConfig.LxcConf = [{name: 'lxc.utsname', value: 'docker'}];
|
2015-01-29 01:26:48 +00:00
|
|
|
scope.config.HostConfig.ExtraHosts = [{host: 'hostname', ip: '127.0.0.1'}];
|
2015-01-20 07:42:08 +00:00
|
|
|
|
|
|
|
scope.create();
|
2015-01-19 05:20:49 +00:00
|
|
|
$httpBackend.flush();
|
|
|
|
});
|
|
|
|
});
|
2015-01-21 05:31:57 +00:00
|
|
|
});
|