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

feat(images): add the ability to export/import Docker images (#935) (#2073)

This commit is contained in:
baron_l 2018-07-26 15:09:48 +02:00 committed by Anthony Lapenna
parent d2702d6d7b
commit 5bca9560c9
16 changed files with 278 additions and 10 deletions

View file

@ -1,11 +1,15 @@
angular.module('portainer.docker')
.controller('ImageController', ['$q', '$scope', '$transition$', '$state', '$timeout', 'ImageService', 'RegistryService', 'Notifications', 'HttpRequestHelper',
function ($q, $scope, $transition$, $state, $timeout, ImageService, RegistryService, Notifications, HttpRequestHelper) {
.controller('ImageController', ['$q', '$scope', '$transition$', '$state', '$timeout', 'ImageService', 'RegistryService', 'Notifications', 'HttpRequestHelper', 'ModalService', 'FileSaver', 'Blob',
function ($q, $scope, $transition$, $state, $timeout, ImageService, RegistryService, Notifications, HttpRequestHelper, ModalService, FileSaver, Blob) {
$scope.formValues = {
Image: '',
Registry: ''
};
$scope.state = {
exportInProgress: false
};
$scope.sortType = 'Order';
$scope.sortReverse = false;
@ -97,6 +101,35 @@ function ($q, $scope, $transition$, $state, $timeout, ImageService, RegistryServ
});
};
function exportImage(image) {
HttpRequestHelper.setPortainerAgentTargetHeader(image.NodeName);
$scope.state.exportInProgress = true;
ImageService.downloadImages([image])
.then(function success(data) {
var downloadData = new Blob([data.file], { type: 'application/x-tar' });
FileSaver.saveAs(downloadData, 'images.tar');
Notifications.success('Image successfully downloaded');
})
.catch(function error(err) {
Notifications.error('Failure', err, 'Unable to download image');
})
.finally(function final() {
$scope.state.exportInProgress = false;
});
}
$scope.exportImage = function (image) {
if (image.RepoTags.length === 0 || _.includes(image.RepoTags, '<none>')) {
Notifications.warning('', 'Cannot download a untagged image');
return;
}
ModalService.confirmImageExport(function (confirmed) {
if(!confirmed) { return; }
exportImage(image);
});
};
function initView() {
HttpRequestHelper.setPortainerAgentTargetHeader($transition$.params().nodeName);
var endpointProvider = $scope.applicationState.endpoint.mode.provider;