2018-02-01 12:27:52 +00:00
|
|
|
angular.module('portainer.docker')
|
2018-07-26 13:09:48 +00:00
|
|
|
.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) {
|
2017-06-20 11:00:32 +00:00
|
|
|
$scope.formValues = {
|
2017-03-20 11:01:35 +00:00
|
|
|
Image: '',
|
|
|
|
Registry: ''
|
2017-03-20 10:45:04 +00:00
|
|
|
};
|
2016-08-17 06:05:17 +00:00
|
|
|
|
2018-07-26 13:09:48 +00:00
|
|
|
$scope.state = {
|
|
|
|
exportInProgress: false
|
|
|
|
};
|
|
|
|
|
2018-03-14 00:27:06 +00:00
|
|
|
$scope.sortType = 'Order';
|
|
|
|
$scope.sortReverse = false;
|
2017-07-08 07:21:30 +00:00
|
|
|
|
|
|
|
$scope.order = function(sortType) {
|
|
|
|
$scope.sortReverse = ($scope.sortType === sortType) ? !$scope.sortReverse : false;
|
|
|
|
$scope.sortType = sortType;
|
|
|
|
};
|
|
|
|
|
2017-07-08 06:59:32 +00:00
|
|
|
$scope.toggleLayerCommand = function(layerId) {
|
|
|
|
$('#layer-command-expander'+layerId+' span').toggleClass('glyphicon-plus-sign glyphicon-minus-sign');
|
|
|
|
$('#layer-command-'+layerId+'-short').toggle();
|
|
|
|
$('#layer-command-'+layerId+'-full').toggle();
|
|
|
|
};
|
|
|
|
|
2017-03-20 11:01:35 +00:00
|
|
|
$scope.tagImage = function() {
|
2017-06-20 11:00:32 +00:00
|
|
|
var image = $scope.formValues.Image;
|
|
|
|
var registry = $scope.formValues.Registry;
|
2016-06-02 05:34:03 +00:00
|
|
|
|
2017-09-21 14:00:53 +00:00
|
|
|
ImageService.tagImage($transition$.params().id, image, registry.URL)
|
2018-08-22 15:33:06 +00:00
|
|
|
.then(function success() {
|
2017-04-12 19:47:22 +00:00
|
|
|
Notifications.success('Image successfully tagged');
|
2018-02-01 12:27:52 +00:00
|
|
|
$state.go('docker.images.image', {id: $transition$.params().id}, {reload: true});
|
2017-03-20 11:01:35 +00:00
|
|
|
})
|
|
|
|
.catch(function error(err) {
|
2017-05-23 18:25:56 +00:00
|
|
|
Notifications.error('Failure', err, 'Unable to tag image');
|
2017-03-20 11:01:35 +00:00
|
|
|
});
|
|
|
|
};
|
|
|
|
|
2017-06-20 11:00:32 +00:00
|
|
|
$scope.pushTag = function(repository) {
|
2017-11-12 19:27:28 +00:00
|
|
|
$('#uploadResourceHint').show();
|
2017-06-20 11:00:32 +00:00
|
|
|
RegistryService.retrieveRegistryFromRepository(repository)
|
|
|
|
.then(function success(data) {
|
|
|
|
var registry = data;
|
|
|
|
return ImageService.pushImage(repository, registry);
|
|
|
|
})
|
2018-08-22 15:33:06 +00:00
|
|
|
.then(function success() {
|
2017-06-20 11:00:32 +00:00
|
|
|
Notifications.success('Image successfully pushed', repository);
|
2017-03-20 11:01:35 +00:00
|
|
|
})
|
|
|
|
.catch(function error(err) {
|
2017-06-20 11:00:32 +00:00
|
|
|
Notifications.error('Failure', err, 'Unable to push image to repository');
|
2017-03-20 11:01:35 +00:00
|
|
|
})
|
|
|
|
.finally(function final() {
|
2017-11-12 19:27:28 +00:00
|
|
|
$('#uploadResourceHint').hide();
|
2017-03-20 11:01:35 +00:00
|
|
|
});
|
|
|
|
};
|
|
|
|
|
2017-06-20 11:00:32 +00:00
|
|
|
$scope.pullTag = function(repository) {
|
2017-11-12 19:27:28 +00:00
|
|
|
$('#downloadResourceHint').show();
|
2017-06-20 11:00:32 +00:00
|
|
|
RegistryService.retrieveRegistryFromRepository(repository)
|
|
|
|
.then(function success(data) {
|
|
|
|
var registry = data;
|
2017-06-29 14:05:39 +00:00
|
|
|
return ImageService.pullImage(repository, registry, false);
|
2017-06-20 11:00:32 +00:00
|
|
|
})
|
2018-08-22 15:33:06 +00:00
|
|
|
.then(function success() {
|
2017-06-20 11:00:32 +00:00
|
|
|
Notifications.success('Image successfully pulled', repository);
|
2017-03-20 11:01:35 +00:00
|
|
|
})
|
2017-06-20 11:00:32 +00:00
|
|
|
.catch(function error(err) {
|
2017-05-23 18:25:56 +00:00
|
|
|
Notifications.error('Failure', err, 'Unable to pull image');
|
2017-03-20 11:01:35 +00:00
|
|
|
})
|
|
|
|
.finally(function final() {
|
2017-11-12 19:27:28 +00:00
|
|
|
$('#downloadResourceHint').hide();
|
2017-03-20 11:01:35 +00:00
|
|
|
});
|
|
|
|
};
|
|
|
|
|
2017-06-20 11:00:32 +00:00
|
|
|
$scope.removeTag = function(repository) {
|
|
|
|
ImageService.deleteImage(repository, false)
|
2017-03-20 11:01:35 +00:00
|
|
|
.then(function success() {
|
|
|
|
if ($scope.image.RepoTags.length === 1) {
|
2017-06-20 11:00:32 +00:00
|
|
|
Notifications.success('Image successfully deleted', repository);
|
2018-02-01 12:27:52 +00:00
|
|
|
$state.go('docker.images', {}, {reload: true});
|
2017-03-20 11:01:35 +00:00
|
|
|
} else {
|
2017-06-20 11:00:32 +00:00
|
|
|
Notifications.success('Tag successfully deleted', repository);
|
2018-02-01 12:27:52 +00:00
|
|
|
$state.go('docker.images.image', {id: $transition$.params().id}, {reload: true});
|
2017-03-20 11:01:35 +00:00
|
|
|
}
|
|
|
|
})
|
|
|
|
.catch(function error(err) {
|
2017-05-23 18:25:56 +00:00
|
|
|
Notifications.error('Failure', err, 'Unable to remove image');
|
2017-03-20 11:01:35 +00:00
|
|
|
});
|
|
|
|
};
|
2016-08-17 00:27:54 +00:00
|
|
|
|
2017-03-20 11:01:35 +00:00
|
|
|
$scope.removeImage = function (id) {
|
|
|
|
ImageService.deleteImage(id, false)
|
|
|
|
.then(function success() {
|
2017-04-12 19:47:22 +00:00
|
|
|
Notifications.success('Image successfully deleted', id);
|
2018-02-01 12:27:52 +00:00
|
|
|
$state.go('docker.images', {}, {reload: true});
|
2017-03-20 11:01:35 +00:00
|
|
|
})
|
|
|
|
.catch(function error(err) {
|
2017-05-23 18:25:56 +00:00
|
|
|
Notifications.error('Failure', err, 'Unable to remove image');
|
2017-03-20 11:01:35 +00:00
|
|
|
});
|
|
|
|
};
|
2017-03-20 10:45:04 +00:00
|
|
|
|
2018-07-26 13:09:48 +00:00
|
|
|
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);
|
|
|
|
});
|
|
|
|
};
|
|
|
|
|
2017-08-13 11:31:50 +00:00
|
|
|
function initView() {
|
2018-05-06 07:15:57 +00:00
|
|
|
HttpRequestHelper.setPortainerAgentTargetHeader($transition$.params().nodeName);
|
2017-08-13 11:31:50 +00:00
|
|
|
var endpointProvider = $scope.applicationState.endpoint.mode.provider;
|
|
|
|
$q.all({
|
2017-09-21 14:00:53 +00:00
|
|
|
image: ImageService.image($transition$.params().id),
|
|
|
|
history: endpointProvider !== 'VMWARE_VIC' ? ImageService.history($transition$.params().id) : []
|
2017-08-13 11:31:50 +00:00
|
|
|
})
|
2017-03-20 11:01:35 +00:00
|
|
|
.then(function success(data) {
|
2017-08-13 11:31:50 +00:00
|
|
|
$scope.image = data.image;
|
|
|
|
$scope.history = data.history;
|
2017-03-20 11:01:35 +00:00
|
|
|
})
|
|
|
|
.catch(function error(err) {
|
2017-05-23 18:25:56 +00:00
|
|
|
Notifications.error('Failure', err, 'Unable to retrieve image details');
|
2018-02-01 12:27:52 +00:00
|
|
|
$state.go('docker.images');
|
2017-03-20 11:01:35 +00:00
|
|
|
});
|
|
|
|
}
|
2016-08-10 03:14:10 +00:00
|
|
|
|
2017-08-13 11:31:50 +00:00
|
|
|
initView();
|
2016-06-02 05:34:03 +00:00
|
|
|
}]);
|