From dfc1a7b1d7b06b01d181dbfa5123f9a679a2a617 Mon Sep 17 00:00:00 2001 From: Chaim Lev-Ari Date: Sun, 25 Jun 2023 08:02:54 +0700 Subject: [PATCH] refactor(docker/images): remove EndpointProvider from build [EE-5551] (#9020) --- app/docker/rest/build.js | 9 +++------ app/docker/services/buildService.js | 14 ++++++++------ .../views/images/build/buildImageController.js | 8 ++++---- app/portainer/services/fileUpload.js | 10 ++++------ 4 files changed, 19 insertions(+), 22 deletions(-) diff --git a/app/docker/rest/build.js b/app/docker/rest/build.js index b0ba607ad..1d5b1606e 100644 --- a/app/docker/rest/build.js +++ b/app/docker/rest/build.js @@ -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', diff --git a/app/docker/services/buildService.js b/app/docker/services/buildService.js index 99d7ef746..852a5f2ae 100644 --- a/app/docker/services/buildService.js +++ b/app/docker/services/buildService.js @@ -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); diff --git a/app/docker/views/images/build/buildImageController.js b/app/docker/views/images/build/buildImageController.js index 54e3b8ddd..553b15049 100644 --- a/app/docker/views/images/build/buildImageController.js +++ b/app/docker/views/images/build/buildImageController.js @@ -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); } } } diff --git a/app/portainer/services/fileUpload.js b/app/portainer/services/fileUpload.js index 0dbfec0c6..37653f41c 100644 --- a/app/portainer/services/fileUpload.js +++ b/app/portainer/services/fileUpload.js @@ -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', },