2020-04-10 21:54:53 +00:00
|
|
|
import { ImageBuildModel } from '../models/image';
|
2019-03-21 05:46:49 +00:00
|
|
|
|
2020-04-10 21:54:53 +00:00
|
|
|
angular.module('portainer.docker').factory('BuildService', [
|
|
|
|
'$q',
|
|
|
|
'Build',
|
|
|
|
'FileUploadService',
|
|
|
|
function BuildServiceFactory($q, Build, FileUploadService) {
|
|
|
|
'use strict';
|
|
|
|
var service = {};
|
2018-02-28 06:19:06 +00:00
|
|
|
|
2020-04-10 21:54:53 +00:00
|
|
|
service.buildImageFromUpload = function (names, file, path) {
|
|
|
|
var deferred = $q.defer();
|
2018-02-28 06:19:06 +00:00
|
|
|
|
2020-04-10 21:54:53 +00:00
|
|
|
FileUploadService.buildImage(names, file, path)
|
|
|
|
.then(function success(response) {
|
|
|
|
var model = new ImageBuildModel(response.data);
|
|
|
|
deferred.resolve(model);
|
|
|
|
})
|
|
|
|
.catch(function error(err) {
|
|
|
|
deferred.reject(err);
|
|
|
|
});
|
2018-02-28 06:19:06 +00:00
|
|
|
|
2020-04-10 21:54:53 +00:00
|
|
|
return deferred.promise;
|
2018-02-28 06:19:06 +00:00
|
|
|
};
|
|
|
|
|
2020-04-10 21:54:53 +00:00
|
|
|
service.buildImageFromURL = function (names, url, path) {
|
|
|
|
var params = {
|
|
|
|
t: names,
|
|
|
|
remote: url,
|
|
|
|
dockerfile: path,
|
|
|
|
};
|
2018-02-28 06:19:06 +00:00
|
|
|
|
2020-04-10 21:54:53 +00:00
|
|
|
var deferred = $q.defer();
|
2018-02-28 06:19:06 +00:00
|
|
|
|
2020-04-10 21:54:53 +00:00
|
|
|
Build.buildImage(params, {})
|
|
|
|
.$promise.then(function success(data) {
|
|
|
|
var model = new ImageBuildModel(data);
|
|
|
|
deferred.resolve(model);
|
|
|
|
})
|
|
|
|
.catch(function error(err) {
|
|
|
|
deferred.reject(err);
|
|
|
|
});
|
2018-02-28 06:19:06 +00:00
|
|
|
|
2020-04-10 21:54:53 +00:00
|
|
|
return deferred.promise;
|
2018-02-28 06:19:06 +00:00
|
|
|
};
|
|
|
|
|
2020-04-10 21:54:53 +00:00
|
|
|
service.buildImageFromDockerfileContent = function (names, content) {
|
|
|
|
var params = {
|
|
|
|
t: names,
|
|
|
|
};
|
|
|
|
var payload = {
|
|
|
|
content: content,
|
|
|
|
};
|
2018-02-28 06:19:06 +00:00
|
|
|
|
2020-04-10 21:54:53 +00:00
|
|
|
var deferred = $q.defer();
|
2018-02-28 06:19:06 +00:00
|
|
|
|
2020-04-10 21:54:53 +00:00
|
|
|
Build.buildImageOverride(params, payload)
|
|
|
|
.$promise.then(function success(data) {
|
|
|
|
var model = new ImageBuildModel(data);
|
|
|
|
deferred.resolve(model);
|
|
|
|
})
|
|
|
|
.catch(function error(err) {
|
|
|
|
deferred.reject(err);
|
|
|
|
});
|
|
|
|
|
|
|
|
return deferred.promise;
|
|
|
|
};
|
2018-02-28 06:19:06 +00:00
|
|
|
|
2022-09-14 06:47:24 +00:00
|
|
|
service.buildImageFromDockerfileContentAndFiles = function (names, content, files) {
|
|
|
|
var dockerfile = new Blob([content], { type: 'text/plain' });
|
|
|
|
var uploadFiles = [dockerfile].concat(files);
|
|
|
|
|
|
|
|
var deferred = $q.defer();
|
|
|
|
|
|
|
|
FileUploadService.buildImageFromFiles(names, uploadFiles)
|
|
|
|
.then(function success(response) {
|
|
|
|
var model = new ImageBuildModel(response.data);
|
|
|
|
deferred.resolve(model);
|
|
|
|
})
|
|
|
|
.catch(function error(err) {
|
|
|
|
deferred.reject(err);
|
|
|
|
});
|
|
|
|
|
|
|
|
return deferred.promise;
|
|
|
|
};
|
|
|
|
|
2020-04-10 21:54:53 +00:00
|
|
|
return service;
|
|
|
|
},
|
|
|
|
]);
|