Container env vars editing using commit and recreate

pull/2/head
Roman Usachev 2016-02-22 09:10:16 +03:00
parent 786b94b285
commit ad0d23d686
3 changed files with 129 additions and 8 deletions

View File

@ -76,9 +76,37 @@
<tr> <tr>
<td>Environment:</td> <td>Environment:</td>
<td> <td>
<ul> <div class="form-group">
<li ng-repeat="k in container.Config.Env">{{ k }}</li> <label>Env:</label>
</ul>
<div ng-repeat="envar in newCfg.Env">
<div class="form-group form-inline">
<div class="form-group">
<label class="sr-only">Variable Name:</label>
<input type="text" ng-model="envar.name" class="form-control"
placeholder="NAME"/>
</div>
<div class="form-group">
<label class="sr-only">Variable Value:</label>
<input type="text" ng-model="envar.value" class="form-control"
placeholder="value"/>
</div>
<div class="form-group">
<button class="btn btn-danger btn-xs form-control"
ng-click="rmEntry(newCfg.Env, envar)">Remove
</button>
</div>
</div>
</div>
<button type="button" class="btn btn-success btn-sm"
ng-click="addEntry(newCfg.Env, {name: '', value: ''})">Add environment
variable
</button>
</div>
<button class="btn btn-success"
ng-click="restartEnv()"
ng-show="!container.State.Restarting">Restart with new env</button>
</td> </td>
</tr> </tr>
<tr> <tr>

View File

@ -1,8 +1,11 @@
angular.module('container', []) angular.module('container', [])
.controller('ContainerController', ['$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, Messages, ViewSpinner, $timeout) { function ($scope, $routeParams, $location, Container, ContainerCommit, Image, Messages, ViewSpinner, $timeout) {
$scope.changes = []; $scope.changes = [];
$scope.edit = false; $scope.edit = false;
$scope.newCfg = {
Env: []
};
var update = function () { var update = function () {
ViewSpinner.spin(); ViewSpinner.spin();
@ -10,6 +13,10 @@ angular.module('container', [])
$scope.container = d; $scope.container = d;
$scope.container.edit = false; $scope.container.edit = false;
$scope.container.newContainerName = d.Name; $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(); ViewSpinner.stop();
}, function (e) { }, function (e) {
if (e.status === 404) { if (e.status === 404) {
@ -20,6 +27,7 @@ angular.module('container', [])
} }
ViewSpinner.stop(); ViewSpinner.stop();
}); });
}; };
$scope.start = function () { $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 () { $scope.commit = function () {
ViewSpinner.spin(); ViewSpinner.spin();
ContainerCommit.commit({id: $routeParams.id, repo: $scope.container.Config.Image}, function (d) { ContainerCommit.commit({id: $routeParams.id, repo: $scope.container.Config.Image}, function (d) {
@ -139,6 +221,15 @@ angular.module('container', [])
$scope.container.edit = false; $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(); update();
$scope.getChanges(); $scope.getChanges();
}]); }]);

View File

@ -31,8 +31,9 @@ angular.module('dockerui.services', ['ngResource'])
url: Settings.url + '/commit', url: Settings.url + '/commit',
params: { params: {
'container': params.id, 'container': params.id,
'repo': params.repo 'tag': params.tag
} },
data: params.config
}).success(callback).error(function (data, status, headers, config) { }).success(callback).error(function (data, status, headers, config) {
console.log(error, data); console.log(error, data);
}); });
@ -92,7 +93,8 @@ angular.module('dockerui.services', ['ngResource'])
insert: {method: 'POST', params: {id: '@id', action: 'insert'}}, insert: {method: 'POST', params: {id: '@id', action: 'insert'}},
push: {method: 'POST', params: {id: '@id', action: 'push'}}, push: {method: 'POST', params: {id: '@id', action: 'push'}},
tag: {method: 'POST', params: {id: '@id', action: 'tag', force: 0, repo: '@repo', tag: '@tag'}}, 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) { .factory('Version', ['$resource', 'Settings', function VersionFactory($resource, Settings) {