refactor(docker/images): remove EndpointProvider from build [EE-5551] (#9020)

pull/9120/head
Chaim Lev-Ari 2023-06-25 08:02:54 +07:00 committed by GitHub
parent 7cb6e3f66a
commit dfc1a7b1d7
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 19 additions and 22 deletions

View File

@ -1,16 +1,13 @@
import { API_ENDPOINT_ENDPOINTS } from '@/constants';
import { jsonObjectsToArrayHandler } from './response/handlers';
angular.module('portainer.docker').factory('Build', [
'$resource',
'API_ENDPOINT_ENDPOINTS',
'EndpointProvider',
function BuildFactory($resource, API_ENDPOINT_ENDPOINTS, EndpointProvider) {
function BuildFactory($resource) {
'use strict';
return $resource(
API_ENDPOINT_ENDPOINTS + '/:endpointId/docker/build',
{
endpointId: EndpointProvider.endpointID,
},
{},
{
buildImage: {
method: 'POST',

View File

@ -8,10 +8,10 @@ angular.module('portainer.docker').factory('BuildService', [
'use strict';
var service = {};
service.buildImageFromUpload = function (names, file, path) {
service.buildImageFromUpload = function (endpointID, names, file, path) {
var deferred = $q.defer();
FileUploadService.buildImage(names, file, path)
FileUploadService.buildImage(endpointID, names, file, path)
.then(function success(response) {
var model = new ImageBuildModel(response.data);
deferred.resolve(model);
@ -23,8 +23,9 @@ angular.module('portainer.docker').factory('BuildService', [
return deferred.promise;
};
service.buildImageFromURL = function (names, url, path) {
service.buildImageFromURL = function (endpointId, names, url, path) {
var params = {
endpointId,
t: names,
remote: url,
dockerfile: path,
@ -44,8 +45,9 @@ angular.module('portainer.docker').factory('BuildService', [
return deferred.promise;
};
service.buildImageFromDockerfileContent = function (names, content) {
service.buildImageFromDockerfileContent = function (endpointId, names, content) {
var params = {
endpointId,
t: names,
};
var payload = {
@ -66,13 +68,13 @@ angular.module('portainer.docker').factory('BuildService', [
return deferred.promise;
};
service.buildImageFromDockerfileContentAndFiles = function (names, content, files) {
service.buildImageFromDockerfileContentAndFiles = function (endpointID, names, content, files) {
var dockerfile = new Blob([content], { type: 'text/plain' });
var uploadFiles = [dockerfile].concat(files);
var deferred = $q.defer();
FileUploadService.buildImageFromFiles(names, uploadFiles)
FileUploadService.buildImageFromFiles(endpointID, names, uploadFiles)
.then(function success(response) {
var model = new ImageBuildModel(response.data);
deferred.resolve(model);

View File

@ -81,17 +81,17 @@ function BuildImageController($scope, $async, $window, BuildService, Notificatio
if (buildType === 'upload') {
var file = $scope.formValues.UploadFile;
return BuildService.buildImageFromUpload(names, file, dockerfilePath);
return BuildService.buildImageFromUpload(endpoint.Id, names, file, dockerfilePath);
} else if (buildType === 'url') {
var URL = $scope.formValues.URL;
return BuildService.buildImageFromURL(names, URL, dockerfilePath);
return BuildService.buildImageFromURL(endpoint.Id, names, URL, dockerfilePath);
} else {
var dockerfileContent = $scope.formValues.DockerFileContent;
if ($scope.formValues.AdditionalFiles.length === 0) {
return BuildService.buildImageFromDockerfileContent(names, dockerfileContent);
return BuildService.buildImageFromDockerfileContent(endpoint.Id, names, dockerfileContent);
} else {
var additionalFiles = $scope.formValues.AdditionalFiles;
return BuildService.buildImageFromDockerfileContentAndFiles(names, dockerfileContent, additionalFiles);
return BuildService.buildImageFromDockerfileContentAndFiles(endpoint.Id, names, dockerfileContent, additionalFiles);
}
}
}

View File

@ -14,10 +14,9 @@ angular.module('portainer.app').factory('FileUploadService', [
return Upload.upload({ url: url, data: { file: file } });
}
service.buildImage = function (names, file, path) {
var endpointID = EndpointProvider.endpointID();
service.buildImage = function (endpointID, names, file, path) {
return Upload.http({
url: 'api/endpoints/' + endpointID + '/docker/build',
url: `api/endpoints/${endpointID}/docker/build`,
headers: {
'Content-Type': file.type,
},
@ -33,10 +32,9 @@ angular.module('portainer.app').factory('FileUploadService', [
});
};
service.buildImageFromFiles = function (names, files) {
var endpointID = EndpointProvider.endpointID();
service.buildImageFromFiles = function (endpointID, names, files) {
return Upload.upload({
url: 'api/endpoints/' + endpointID + '/docker/build',
url: `api/endpoints/${endpointID}/docker/build`,
headers: {
'Content-Type': 'multipart/form-data',
},