diff --git a/app/components/container/container.html b/app/components/container/container.html index 083baf33c..95ba886d4 100644 --- a/app/components/container/container.html +++ b/app/components/container/container.html @@ -76,9 +76,37 @@ Environment: - +
+ + +
+
+
+ + +
+
+ + +
+
+ +
+
+
+ +
+ + diff --git a/app/components/container/containerController.js b/app/components/container/containerController.js index b384b6a3f..0c0c516d4 100644 --- a/app/components/container/containerController.js +++ b/app/components/container/containerController.js @@ -1,8 +1,11 @@ angular.module('container', []) - .controller('ContainerController', ['$scope', '$routeParams', '$location', 'Container', 'ContainerCommit', 'Messages', 'ViewSpinner', '$timeout', - function ($scope, $routeParams, $location, Container, ContainerCommit, Messages, ViewSpinner, $timeout) { + .controller('ContainerController', ['$scope', '$routeParams', '$location', 'Container', 'ContainerCommit', 'Image', 'Messages', 'ViewSpinner', '$timeout', + function ($scope, $routeParams, $location, Container, ContainerCommit, Image, Messages, ViewSpinner, $timeout) { $scope.changes = []; $scope.edit = false; + $scope.newCfg = { + Env: [] + }; var update = function () { ViewSpinner.spin(); @@ -10,6 +13,10 @@ angular.module('container', []) $scope.container = d; $scope.container.edit = false; $scope.container.newContainerName = d.Name; + $scope.newCfg.Env = d.Config.Env.map(function(entry) { + return {name: entry.split('=')[0], value: entry.split('=')[1]}; + }); + ViewSpinner.stop(); }, function (e) { if (e.status === 404) { @@ -20,6 +27,7 @@ angular.module('container', []) } ViewSpinner.stop(); }); + }; $scope.start = function () { @@ -58,6 +66,80 @@ angular.module('container', []) }); }; + $scope.restartEnv = function () { + var config = angular.copy($scope.container.Config); + + config.Env = $scope.newCfg.Env.map(function(entry) { + return entry.name+"="+entry.value; + }); + + console.log(config); + + + + ViewSpinner.spin(); + ContainerCommit.commit({id: $routeParams.id, tag: $scope.container.Config.Image, config: config }, function (d) { + console.log(d.Id); + if ('Id' in d) { + var imageId = d.Id; + Image.inspect({id: imageId}, function(imageData) { + console.log(imageData); + Container.create(imageData.Config, function(containerData) { + console.log(containerData); + // Stop current if running + if ($scope.container.State.Running) { + Container.stop({id: $routeParams.id}, function (d) { + Messages.send("Container stopped", $routeParams.id); + // start new + Container.start({ + id: containerData.Id + // HostConfig: $scope.container.HostConfig we really need this? + }, function (d) { + $location.url('/containers/' + containerData.Id + '/'); + Messages.send("Container started", $routeParams.id); + }, function (e) { + update(); + Messages.error("Failure", "Container failed to start." + e.data); + }); + }, function (e) { + update(); + Messages.error("Failure", "Container failed to stop." + e.data); + }); + } else { + // start new + Container.start({ + id: containerData.Id + // HostConfig: $scope.container.HostConfig we really need this? + }, function (d) { + $location.url('/containers/'+containerData.Id+'/'); + Messages.send("Container started", $routeParams.id); + }, function (e) { + update(); + Messages.error("Failure", "Container failed to start." + e.data); + }); + } + + }, function(e) { + update(); + Messages.error("Failure", "Image failed to get." + e.data); + }); + }, function (e) { + update(); + Messages.error("Failure", "Image failed to get." + e.data); + }) + + } else { + update(); + Messages.send("Container commit failed", $routeParams.id); + } + + + }, function (e) { + update(); + Messages.error("Failure", "Container failed to commit." + e.data); + }); + }; + $scope.commit = function () { ViewSpinner.spin(); ContainerCommit.commit({id: $routeParams.id, repo: $scope.container.Config.Image}, function (d) { @@ -139,6 +221,15 @@ angular.module('container', []) $scope.container.edit = false; }; + $scope.addEntry = function (array, entry) { + array.push(entry); + }; + $scope.rmEntry = function (array, entry) { + var idx = array.indexOf(entry); + array.splice(idx, 1); + }; + update(); $scope.getChanges(); }]); + diff --git a/app/shared/services.js b/app/shared/services.js index 2f9530d73..ba38178e2 100644 --- a/app/shared/services.js +++ b/app/shared/services.js @@ -31,8 +31,9 @@ angular.module('dockerui.services', ['ngResource']) url: Settings.url + '/commit', params: { 'container': params.id, - 'repo': params.repo - } + 'tag': params.tag + }, + data: params.config }).success(callback).error(function (data, status, headers, config) { console.log(error, data); }); @@ -92,7 +93,8 @@ angular.module('dockerui.services', ['ngResource']) insert: {method: 'POST', params: {id: '@id', action: 'insert'}}, push: {method: 'POST', params: {id: '@id', action: 'push'}}, tag: {method: 'POST', params: {id: '@id', action: 'tag', force: 0, repo: '@repo', tag: '@tag'}}, - remove: {method: 'DELETE', params: {id: '@id'}, isArray: true} + remove: {method: 'DELETE', params: {id: '@id'}, isArray: true}, + inspect: {method: 'GET', params: {id: '@id', action: 'json'}} }); }]) .factory('Version', ['$resource', 'Settings', function VersionFactory($resource, Settings) {