fix(templates): fix the ability to pull an image within an offline environment (#961)

pull/967/head
Anthony Lapenna 8 years ago committed by GitHub
parent 6609c2e928
commit 6d401dcd59

@ -299,7 +299,7 @@ function ($q, $scope, $state, $stateParams, $filter, Container, ContainerHelper,
}; };
function createContainer(config, accessControlData) { function createContainer(config, accessControlData) {
$q.when(!$scope.formValues.alwaysPull || ImageService.pullImage($scope.config.Image, $scope.formValues.Registry)) $q.when(!$scope.formValues.alwaysPull || ImageService.pullImage($scope.config.Image, $scope.formValues.Registry, true))
.finally(function final() { .finally(function final() {
ContainerService.createAndStartContainer(config) ContainerService.createAndStartContainer(config)
.then(function success(data) { .then(function success(data) {

@ -47,7 +47,7 @@ function ($scope, $stateParams, $state, $timeout, ImageService, RegistryService,
RegistryService.retrieveRegistryFromRepository(repository) RegistryService.retrieveRegistryFromRepository(repository)
.then(function success(data) { .then(function success(data) {
var registry = data; var registry = data;
return ImageService.pullImage(repository, registry); return ImageService.pullImage(repository, registry, false);
}) })
.then(function success(data) { .then(function success(data) {
Notifications.success('Image successfully pulled', repository); Notifications.success('Image successfully pulled', repository);

@ -42,7 +42,7 @@ function ($scope, $state, ImageService, Notifications, Pagination, ModalService)
$('#pullImageSpinner').show(); $('#pullImageSpinner').show();
var image = $scope.formValues.Image; var image = $scope.formValues.Image;
var registry = $scope.formValues.Registry; var registry = $scope.formValues.Registry;
ImageService.pullImage(image, registry) ImageService.pullImage(image, registry, false)
.then(function success(data) { .then(function success(data) {
Notifications.success('Image successfully pulled', image); Notifications.success('Image successfully pulled', image);
$state.reload(); $state.reload();

@ -69,7 +69,7 @@ function ($scope, $q, $state, $stateParams, $anchorScroll, $filter, ContainerSer
generatedVolumeIds.push(volumeId); generatedVolumeIds.push(volumeId);
}); });
TemplateService.updateContainerConfigurationWithVolumes(templateConfiguration, template, data); TemplateService.updateContainerConfigurationWithVolumes(templateConfiguration, template, data);
return ImageService.pullImage(template.Image, template.Registry); return ImageService.pullImage(template.Image, { URL: template.Registry }, true);
}) })
.then(function success(data) { .then(function success(data) {
return ContainerService.createAndStartContainer(templateConfiguration); return ContainerService.createAndStartContainer(templateConfiguration);

@ -54,14 +54,19 @@ angular.module('portainer.services')
return deferred.promise; return deferred.promise;
}; };
function pullImageAndIgnoreErrors(imageConfiguration) {
service.pullImage = function(image, registry) {
var deferred = $q.defer(); var deferred = $q.defer();
var imageDetails = ImageHelper.extractImageAndRegistryFromRepository(image); Image.create({}, imageConfiguration).$promise
var imageConfiguration = ImageHelper.createImageConfigForContainer(imageDetails.image, registry.URL); .finally(function final() {
var authenticationDetails = registry.Authentication ? RegistryService.encodedCredentials(registry) : ''; deferred.resolve();
HttpRequestHelper.setRegistryAuthenticationHeader(authenticationDetails); });
return deferred.promise;
}
function pullImageAndAcknowledgeErrors(imageConfiguration) {
var deferred = $q.defer();
Image.create({}, imageConfiguration).$promise Image.create({}, imageConfiguration).$promise
.then(function success(data) { .then(function success(data) {
@ -78,6 +83,18 @@ angular.module('portainer.services')
}); });
return deferred.promise; return deferred.promise;
}
service.pullImage = function(image, registry, ignoreErrors) {
var imageDetails = ImageHelper.extractImageAndRegistryFromRepository(image);
var imageConfiguration = ImageHelper.createImageConfigForContainer(imageDetails.image, registry.URL);
var authenticationDetails = registry.Authentication ? RegistryService.encodedCredentials(registry) : '';
HttpRequestHelper.setRegistryAuthenticationHeader(authenticationDetails);
if (ignoreErrors) {
return pullImageAndIgnoreErrors(imageConfiguration);
}
return pullImageAndAcknowledgeErrors(imageConfiguration);
}; };
service.tagImage = function(id, image, registry) { service.tagImage = function(id, image, registry) {

Loading…
Cancel
Save