1
0
Fork 0
mirror of https://github.com/portainer/portainer.git synced 2025-08-08 07:15:23 +02:00

feat(stacks): migrate stack data from previous portainer version

This commit is contained in:
Anthony Lapenna 2018-06-15 18:14:01 +03:00
parent 5e73a49473
commit e1345416b4
7 changed files with 81 additions and 17 deletions

View file

@ -3,6 +3,7 @@ function StackViewModel(data) {
this.Type = data.Type;
this.Name = data.Name;
this.Checked = false;
this.EndpointId = data.EndpointId;
this.Env = data.Env ? data.Env : [];
if (data.ResourceControl && data.ResourceControl.Id !== 0) {
this.ResourceControl = new ResourceControlViewModel(data.ResourceControl);

View file

@ -174,8 +174,8 @@ function StackServiceFactory($q, Stack, ResourceControlService, FileUploadServic
return deferred.promise;
};
service.updateStack = function(id, stackFile, env, prune) {
return Stack.update({ id: id, StackFileContent: stackFile, Env: env, Prune: prune}).$promise;
service.updateStack = function(stack, stackFile, env, prune) {
return Stack.update({ endpointId: stack.EndpointId }, { id: stack.Id, StackFileContent: stackFile, Env: env, Prune: prune }).$promise;
};
service.createComposeStackFromFileUpload = function(name, stackFile, endpointId) {

View file

@ -1,6 +1,6 @@
angular.module('portainer.app')
.controller('StackController', ['$q', '$scope', '$state', '$transition$', 'StackService', 'NodeService', 'ServiceService', 'TaskService', 'ContainerService', 'ServiceHelper', 'TaskHelper', 'Notifications', 'FormHelper',
function ($q, $scope, $state, $transition$, StackService, NodeService, ServiceService, TaskService, ContainerService, ServiceHelper, TaskHelper, Notifications, FormHelper) {
.controller('StackController', ['$q', '$scope', '$state', '$transition$', 'StackService', 'NodeService', 'ServiceService', 'TaskService', 'ContainerService', 'ServiceHelper', 'TaskHelper', 'Notifications', 'FormHelper', 'EndpointProvider',
function ($q, $scope, $state, $transition$, StackService, NodeService, ServiceService, TaskService, ContainerService, ServiceHelper, TaskHelper, Notifications, FormHelper, EndpointProvider) {
$scope.state = {
actionInProgress: false,
@ -15,9 +15,19 @@ function ($q, $scope, $state, $transition$, StackService, NodeService, ServiceSe
var stackFile = $scope.stackFileContent;
var env = FormHelper.removeInvalidEnvVars($scope.stack.Env);
var prune = $scope.formValues.Prune;
var stack = $scope.stack;
// TODO: this is a work-around for stacks created with Portainer version >= 1.17.1
// The EndpointID property is not available for these stacks, we can pass
// the current endpoint identifier as a part of the update request. It will be used if
// the EndpointID property is not defined on the stack.
var endpointId = EndpointProvider.endpointID();
if (stack.EndpointId === 0) {
stack.EndpointId = endpointId;
}
$scope.state.actionInProgress = true;
StackService.updateStack($scope.stack.Id, stackFile, env, prune)
StackService.updateStack(stack, stackFile, env, prune)
.then(function success(data) {
Notifications.success('Stack successfully deployed');
$state.reload();