mirror of
https://github.com/portainer/portainer.git
synced 2025-07-22 23:09:41 +02:00
feat(container-details): add the ability to specify if image should be pulled when re-creating a container
This commit is contained in:
parent
c85aa0739d
commit
e96e615761
2 changed files with 104 additions and 54 deletions
|
@ -1,6 +1,6 @@
|
||||||
angular.module('container', [])
|
angular.module('container', [])
|
||||||
.controller('ContainerController', ['$scope', '$state','$stateParams', '$filter', 'Container', 'ContainerCommit', 'ContainerHelper', 'ContainerService', 'ImageHelper', 'Network', 'NetworkService', 'Notifications', 'Pagination', 'ModalService', 'ResourceControlService', 'RegistryService', 'ImageService',
|
.controller('ContainerController', ['$q', '$scope', '$state','$stateParams', '$filter', 'Container', 'ContainerCommit', 'ContainerHelper', 'ContainerService', 'ImageHelper', 'Network', 'NetworkService', 'Notifications', 'Pagination', 'ModalService', 'ResourceControlService', 'RegistryService', 'ImageService',
|
||||||
function ($scope, $state, $stateParams, $filter, Container, ContainerCommit, ContainerHelper, ContainerService, ImageHelper, Network, NetworkService, Notifications, Pagination, ModalService, ResourceControlService, RegistryService, ImageService) {
|
function ($q, $scope, $state, $stateParams, $filter, Container, ContainerCommit, ContainerHelper, ContainerService, ImageHelper, Network, NetworkService, Notifications, Pagination, ModalService, ResourceControlService, RegistryService, ImageService) {
|
||||||
$scope.activityTime = 0;
|
$scope.activityTime = 0;
|
||||||
$scope.portBindings = [];
|
$scope.portBindings = [];
|
||||||
$scope.config = {
|
$scope.config = {
|
||||||
|
@ -203,62 +203,78 @@ function ($scope, $state, $stateParams, $filter, Container, ContainerCommit, Con
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
|
$scope.confirmRemove = function () {
|
||||||
|
var title = 'You are about to remove a container.';
|
||||||
|
if ($scope.container.State.Running) {
|
||||||
|
title = 'You are about to remove a running container.';
|
||||||
|
}
|
||||||
|
ModalService.confirmContainerDeletion(
|
||||||
|
title,
|
||||||
|
function (result) {
|
||||||
|
if(!result) { return; }
|
||||||
|
var cleanAssociatedVolumes = false;
|
||||||
|
if (result[0]) {
|
||||||
|
cleanAssociatedVolumes = true;
|
||||||
|
}
|
||||||
|
$scope.remove(cleanAssociatedVolumes);
|
||||||
|
}
|
||||||
|
);
|
||||||
|
};
|
||||||
|
|
||||||
|
function recreateContainer(pullImage) {
|
||||||
|
$('#loadingViewSpinner').show();
|
||||||
|
var container = $scope.container;
|
||||||
|
var config = ContainerHelper.configFromContainer(container.Model);
|
||||||
|
ContainerService.remove(container, true)
|
||||||
|
.then(function success() {
|
||||||
|
return RegistryService.retrieveRegistryFromRepository(container.Config.Image);
|
||||||
|
})
|
||||||
|
.then(function success(data) {
|
||||||
|
return $q.when(!pullImage || ImageService.pullImage(container.Config.Image, data, true));
|
||||||
|
})
|
||||||
|
.then(function success() {
|
||||||
|
return ContainerService.createAndStartContainer(config);
|
||||||
|
})
|
||||||
|
.then(function success(data) {
|
||||||
|
if (!container.ResourceControl) {
|
||||||
|
return true;
|
||||||
|
} else {
|
||||||
|
var containerIdentifier = data.Id;
|
||||||
|
var resourceControl = container.ResourceControl;
|
||||||
|
var users = resourceControl.UserAccesses.map(function(u) {
|
||||||
|
return u.UserId;
|
||||||
|
});
|
||||||
|
var teams = resourceControl.TeamAccesses.map(function(t) {
|
||||||
|
return t.TeamId;
|
||||||
|
});
|
||||||
|
return ResourceControlService.createResourceControl(resourceControl.AdministratorsOnly,
|
||||||
|
users, teams, containerIdentifier, 'container', []);
|
||||||
|
}
|
||||||
|
})
|
||||||
|
.then(function success(data) {
|
||||||
|
Notifications.success('Container successfully re-created');
|
||||||
|
$state.go('containers', {}, {reload: true});
|
||||||
|
})
|
||||||
|
.catch(function error(err) {
|
||||||
|
Notifications.error('Failure', err, 'Unable to re-create container');
|
||||||
|
})
|
||||||
|
.finally(function final() {
|
||||||
|
$('#loadingViewSpinner').hide();
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
$scope.recreate = function() {
|
$scope.recreate = function() {
|
||||||
ModalService.confirmExperimentalFeature(function (experimental) {
|
ModalService.confirmExperimentalFeature(function (experimental) {
|
||||||
if(!experimental) { return; }
|
if(!experimental) { return; }
|
||||||
ModalService.confirm({
|
|
||||||
title: 'Are you sure ?',
|
ModalService.confirmContainerRecreation(function (result) {
|
||||||
message: 'You\'re about to re-create this container, any non-persisted data will be lost. This container will be removed and another one will be created using the same configuration.',
|
if(!result) { return; }
|
||||||
buttons: {
|
console.log(JSON.stringify(result, null, 4));
|
||||||
confirm: {
|
var pullImage = false;
|
||||||
label: 'Recreate',
|
if (result[0]) {
|
||||||
className: 'btn-danger'
|
pullImage = true;
|
||||||
}
|
|
||||||
},
|
|
||||||
callback: function onConfirm(confirmed) {
|
|
||||||
if(!confirmed) { return; }
|
|
||||||
else {
|
|
||||||
$('#loadingViewSpinner').show();
|
|
||||||
var container = $scope.container;
|
|
||||||
var config = ContainerHelper.configFromContainer(container.Model);
|
|
||||||
ContainerService.remove(container, true)
|
|
||||||
.then(function success() {
|
|
||||||
return RegistryService.retrieveRegistryFromRepository(container.Config.Image);
|
|
||||||
})
|
|
||||||
.then(function success(data) {
|
|
||||||
return ImageService.pullImage(container.Config.Image, data, true);
|
|
||||||
})
|
|
||||||
.then(function success() {
|
|
||||||
return ContainerService.createAndStartContainer(config);
|
|
||||||
})
|
|
||||||
.then(function success(data) {
|
|
||||||
if (!container.ResourceControl) {
|
|
||||||
return true;
|
|
||||||
} else {
|
|
||||||
var containerIdentifier = data.Id;
|
|
||||||
var resourceControl = container.ResourceControl;
|
|
||||||
var users = resourceControl.UserAccesses.map(function(u) {
|
|
||||||
return u.UserId;
|
|
||||||
});
|
|
||||||
var teams = resourceControl.TeamAccesses.map(function(t) {
|
|
||||||
return t.TeamId;
|
|
||||||
});
|
|
||||||
return ResourceControlService.createResourceControl(resourceControl.AdministratorsOnly,
|
|
||||||
users, teams, containerIdentifier, 'container', []);
|
|
||||||
}
|
|
||||||
})
|
|
||||||
.then(function success(data) {
|
|
||||||
Notifications.success('Container successfully re-created');
|
|
||||||
$state.go('containers', {}, {reload: true});
|
|
||||||
})
|
|
||||||
.catch(function error(err) {
|
|
||||||
Notifications.error('Failure', err, 'Unable to re-create container');
|
|
||||||
})
|
|
||||||
.finally(function final() {
|
|
||||||
$('#loadingViewSpinner').hide();
|
|
||||||
});
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
recreateContainer(pullImage);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
|
@ -46,6 +46,19 @@ angular.module('portainer.services')
|
||||||
applyBoxCSS(box);
|
applyBoxCSS(box);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
service.customPrompt = function(options) {
|
||||||
|
var box = bootbox.prompt({
|
||||||
|
title: options.title,
|
||||||
|
inputType: options.inputType,
|
||||||
|
inputOptions: options.inputOptions,
|
||||||
|
buttons: confirmButtons(options),
|
||||||
|
callback: options.callback
|
||||||
|
});
|
||||||
|
applyBoxCSS(box);
|
||||||
|
box.find('.bootbox-body').prepend('<p>' + options.message + '</p>');
|
||||||
|
box.find('.bootbox-input-checkbox').prop('checked', true);
|
||||||
|
};
|
||||||
|
|
||||||
service.confirmAccessControlUpdate = function(callback, msg) {
|
service.confirmAccessControlUpdate = function(callback, msg) {
|
||||||
service.confirm({
|
service.confirm({
|
||||||
title: 'Are you sure ?',
|
title: 'Are you sure ?',
|
||||||
|
@ -108,6 +121,27 @@ angular.module('portainer.services')
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
|
service.confirmContainerRecreation = function(callback) {
|
||||||
|
service.customPrompt({
|
||||||
|
title: 'Are you sure?',
|
||||||
|
message: 'You\'re about to re-create this container, any non-persisted data will be lost. This container will be removed and another one will be created using the same configuration.',
|
||||||
|
inputType: 'checkbox',
|
||||||
|
inputOptions: [
|
||||||
|
{
|
||||||
|
text: 'Pull latest image<i></i>',
|
||||||
|
value: '1'
|
||||||
|
}
|
||||||
|
],
|
||||||
|
buttons: {
|
||||||
|
confirm: {
|
||||||
|
label: 'Recreate',
|
||||||
|
className: 'btn-danger'
|
||||||
|
}
|
||||||
|
},
|
||||||
|
callback: callback
|
||||||
|
});
|
||||||
|
};
|
||||||
|
|
||||||
service.confirmExperimentalFeature = function(callback) {
|
service.confirmExperimentalFeature = function(callback) {
|
||||||
service.confirm({
|
service.confirm({
|
||||||
title: 'Experimental feature',
|
title: 'Experimental feature',
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue