mirror of https://github.com/portainer/portainer
feat(images): allow tags when importing docker image EE-1737 (#5883)
parent
988069df56
commit
80af93afec
|
@ -1,35 +1,72 @@
|
||||||
|
import { PorImageRegistryModel } from 'Docker/models/porImageRegistry';
|
||||||
|
|
||||||
angular.module('portainer.docker').controller('ImportImageController', [
|
angular.module('portainer.docker').controller('ImportImageController', [
|
||||||
'$scope',
|
'$scope',
|
||||||
'$state',
|
'$state',
|
||||||
'ImageService',
|
'ImageService',
|
||||||
'Notifications',
|
'Notifications',
|
||||||
'HttpRequestHelper',
|
'HttpRequestHelper',
|
||||||
function ($scope, $state, ImageService, Notifications, HttpRequestHelper) {
|
'Authentication',
|
||||||
|
'ImageHelper',
|
||||||
|
'endpoint',
|
||||||
|
function ($scope, $state, ImageService, Notifications, HttpRequestHelper, Authentication, ImageHelper, endpoint) {
|
||||||
$scope.state = {
|
$scope.state = {
|
||||||
actionInProgress: false,
|
actionInProgress: false,
|
||||||
};
|
};
|
||||||
|
|
||||||
|
$scope.endpoint = endpoint;
|
||||||
|
|
||||||
|
$scope.isAdmin = Authentication.isAdmin();
|
||||||
|
|
||||||
$scope.formValues = {
|
$scope.formValues = {
|
||||||
UploadFile: null,
|
UploadFile: null,
|
||||||
NodeName: null,
|
NodeName: null,
|
||||||
|
RegistryModel: new PorImageRegistryModel(),
|
||||||
};
|
};
|
||||||
|
|
||||||
$scope.uploadImage = function () {
|
$scope.setPullImageValidity = setPullImageValidity;
|
||||||
|
function setPullImageValidity(validity) {
|
||||||
|
$scope.state.pullImageValidity = validity;
|
||||||
|
}
|
||||||
|
|
||||||
|
async function tagImage(id) {
|
||||||
|
const registryModel = $scope.formValues.RegistryModel;
|
||||||
|
if (registryModel.Image) {
|
||||||
|
const image = ImageHelper.createImageConfigForContainer(registryModel);
|
||||||
|
try {
|
||||||
|
await ImageService.tagImage(id, image.fromImage);
|
||||||
|
} catch (err) {
|
||||||
|
Notifications.error('Failure', err, 'Unable to tag image');
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
$scope.uploadImage = async function () {
|
||||||
$scope.state.actionInProgress = true;
|
$scope.state.actionInProgress = true;
|
||||||
|
|
||||||
var nodeName = $scope.formValues.NodeName;
|
var nodeName = $scope.formValues.NodeName;
|
||||||
HttpRequestHelper.setPortainerAgentTargetHeader(nodeName);
|
HttpRequestHelper.setPortainerAgentTargetHeader(nodeName);
|
||||||
var file = $scope.formValues.UploadFile;
|
var file = $scope.formValues.UploadFile;
|
||||||
ImageService.uploadImage(file)
|
try {
|
||||||
.then(function success() {
|
const { data } = await ImageService.uploadImage(file);
|
||||||
|
if (data.error) {
|
||||||
|
Notifications.error('Failure', data.error, 'Unable to upload image');
|
||||||
|
} else if (data.stream) {
|
||||||
|
var regex = /Loaded.*?: (.*?)\n$/g;
|
||||||
|
var imageIds = regex.exec(data.stream);
|
||||||
|
if (imageIds && imageIds.length == 2) {
|
||||||
|
await tagImage(imageIds[1]);
|
||||||
|
$state.go('docker.images.image', { id: imageIds[1] }, { reload: true });
|
||||||
|
}
|
||||||
Notifications.success('Images successfully uploaded');
|
Notifications.success('Images successfully uploaded');
|
||||||
})
|
} else {
|
||||||
.catch(function error(err) {
|
Notifications.success('The uploaded tar file contained multiple images. The provided tag therefore has been ignored.');
|
||||||
Notifications.error('Failure', err, 'Unable to upload image');
|
}
|
||||||
})
|
} catch (err) {
|
||||||
.finally(function final() {
|
Notifications.error('Failure', err, 'Unable to upload image');
|
||||||
$scope.state.actionInProgress = false;
|
} finally {
|
||||||
});
|
$scope.state.actionInProgress = false;
|
||||||
|
}
|
||||||
};
|
};
|
||||||
},
|
},
|
||||||
]);
|
]);
|
||||||
|
|
|
@ -37,6 +37,25 @@
|
||||||
<node-selector model="formValues.NodeName"> </node-selector>
|
<node-selector model="formValues.NodeName"> </node-selector>
|
||||||
<!-- !node-selection -->
|
<!-- !node-selection -->
|
||||||
</div>
|
</div>
|
||||||
|
<div class="row" authorization="DockerImageCreate">
|
||||||
|
<div class="col-lg-12 col-md-12 col-xs-12">
|
||||||
|
<rd-widget>
|
||||||
|
<rd-widget-header icon="fa-tag" title-text="Tag the image"></rd-widget-header>
|
||||||
|
<rd-widget-body>
|
||||||
|
<!-- image-and-registry -->
|
||||||
|
<por-image-registry
|
||||||
|
model="formValues.RegistryModel"
|
||||||
|
label-class="col-sm-1"
|
||||||
|
input-class="col-sm-11"
|
||||||
|
endpoint="endpoint"
|
||||||
|
is-admin="isAdmin"
|
||||||
|
set-validity="setPullImageValidity"
|
||||||
|
check-rate-limits="true"
|
||||||
|
></por-image-registry>
|
||||||
|
</rd-widget-body>
|
||||||
|
</rd-widget>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
<!-- actions -->
|
<!-- actions -->
|
||||||
<div class="col-sm-12 form-section-title">
|
<div class="col-sm-12 form-section-title">
|
||||||
Actions
|
Actions
|
||||||
|
|
Loading…
Reference in New Issue