* feat(compose): add docker-compose wrapper ce-187 * fix(compose): pick compose implementation upon startup * Add static compose build for linux * Fix wget * Fix platofrm specific docker-compose download * Keep amd64 architecture as download parameter * Add tmp folder for docker-compose * fix: line endings * add proxy server * logs * Proxy * Add lite transport for compose * Fix local deployment * refactor: pass proxyManager by ref * fix: string conversion * refactor: compose wrapper remove unused code * fix: tests * Add edge * Fix merge issue * refactor: remove unused code * Move server to proxy implementation * Cleanup wrapper and manager * feat: pass max supported compose syntax version with each endpoint * fix: pick compose syntax version * fix: store wrapper version in portainer * Get and show composeSyntaxMaxVersion at stack creation screen * Get and show composeSyntaxMaxVersion at stack editor screen * refactor: proxy server * Fix used tmp * Bump docker-compose to 1.28.0 * remove message for docker compose limitation * fix: markup typo * Rollback docker compose to 1.27.4 * * attempt to fix the windows build issue * * attempt to debug grunt issue * * use console log in grunt file * fix: try to fix windows build by removing indirect deps from go.mod * Remove tmp folder * Remove builder stage * feat(build/windows): add git for Docker Compose * feat(build/windows): add git for Docker Compose * feat(build/windows): add git for Docker Compose * feat(build/windows): add git for Docker Compose * feat(build/windows): add git for Docker Compose * feat(build/windows): add git for Docker Compose - fixed verbose output * refactor: renames * fix(stack): get endpoint by EndpointProvider * fix(stack): use margin to add space between line instead of using br tag Co-authored-by: Stéphane Busso <stephane.busso@gmail.com> Co-authored-by: Simon Meng <simon.meng@portainer.io> Co-authored-by: yi-portainer <yi.chen@portainer.io> Co-authored-by: Steven Kang <skan070@gmail.com>
193 lines
6.8 KiB
JavaScript
193 lines
6.8 KiB
JavaScript
import angular from 'angular';
|
|
import _ from 'lodash-es';
|
|
|
|
import { AccessControlFormData } from '../../../components/accessControlForm/porAccessControlFormModel';
|
|
|
|
angular
|
|
.module('portainer.app')
|
|
.controller('CreateStackController', function (
|
|
$scope,
|
|
$state,
|
|
StackService,
|
|
Authentication,
|
|
Notifications,
|
|
FormValidator,
|
|
ResourceControlService,
|
|
FormHelper,
|
|
CustomTemplateService,
|
|
EndpointProvider
|
|
) {
|
|
$scope.formValues = {
|
|
Name: '',
|
|
StackFileContent: '',
|
|
StackFile: null,
|
|
RepositoryURL: '',
|
|
RepositoryReferenceName: '',
|
|
RepositoryAuthentication: false,
|
|
RepositoryUsername: '',
|
|
RepositoryPassword: '',
|
|
Env: [],
|
|
ComposeFilePathInRepository: 'docker-compose.yml',
|
|
AccessControlData: new AccessControlFormData(),
|
|
};
|
|
|
|
$scope.state = {
|
|
Method: 'editor',
|
|
formValidationError: '',
|
|
actionInProgress: false,
|
|
StackType: null,
|
|
};
|
|
|
|
$scope.addEnvironmentVariable = function () {
|
|
$scope.formValues.Env.push({ name: '', value: '' });
|
|
};
|
|
|
|
$scope.removeEnvironmentVariable = function (index) {
|
|
$scope.formValues.Env.splice(index, 1);
|
|
};
|
|
|
|
function validateForm(accessControlData, isAdmin) {
|
|
$scope.state.formValidationError = '';
|
|
var error = '';
|
|
error = FormValidator.validateAccessControl(accessControlData, isAdmin);
|
|
|
|
if (error) {
|
|
$scope.state.formValidationError = error;
|
|
return false;
|
|
}
|
|
return true;
|
|
}
|
|
|
|
function createSwarmStack(name, method) {
|
|
var env = FormHelper.removeInvalidEnvVars($scope.formValues.Env);
|
|
const endpointId = +$state.params.endpointId;
|
|
|
|
if (method === 'template' || method === 'editor') {
|
|
var stackFileContent = $scope.formValues.StackFileContent;
|
|
return StackService.createSwarmStackFromFileContent(name, stackFileContent, env, endpointId);
|
|
}
|
|
|
|
if (method === 'upload') {
|
|
var stackFile = $scope.formValues.StackFile;
|
|
return StackService.createSwarmStackFromFileUpload(name, stackFile, env, endpointId);
|
|
}
|
|
|
|
if (method === 'repository') {
|
|
var repositoryOptions = {
|
|
RepositoryURL: $scope.formValues.RepositoryURL,
|
|
RepositoryReferenceName: $scope.formValues.RepositoryReferenceName,
|
|
ComposeFilePathInRepository: $scope.formValues.ComposeFilePathInRepository,
|
|
RepositoryAuthentication: $scope.formValues.RepositoryAuthentication,
|
|
RepositoryUsername: $scope.formValues.RepositoryUsername,
|
|
RepositoryPassword: $scope.formValues.RepositoryPassword,
|
|
};
|
|
return StackService.createSwarmStackFromGitRepository(name, repositoryOptions, env, endpointId);
|
|
}
|
|
}
|
|
|
|
function createComposeStack(name, method) {
|
|
var env = FormHelper.removeInvalidEnvVars($scope.formValues.Env);
|
|
const endpointId = +$state.params.endpointId;
|
|
|
|
if (method === 'editor' || method === 'template') {
|
|
var stackFileContent = $scope.formValues.StackFileContent;
|
|
return StackService.createComposeStackFromFileContent(name, stackFileContent, env, endpointId);
|
|
} else if (method === 'upload') {
|
|
var stackFile = $scope.formValues.StackFile;
|
|
return StackService.createComposeStackFromFileUpload(name, stackFile, env, endpointId);
|
|
} else if (method === 'repository') {
|
|
var repositoryOptions = {
|
|
RepositoryURL: $scope.formValues.RepositoryURL,
|
|
RepositoryReferenceName: $scope.formValues.RepositoryReferenceName,
|
|
ComposeFilePathInRepository: $scope.formValues.ComposeFilePathInRepository,
|
|
RepositoryAuthentication: $scope.formValues.RepositoryAuthentication,
|
|
RepositoryUsername: $scope.formValues.RepositoryUsername,
|
|
RepositoryPassword: $scope.formValues.RepositoryPassword,
|
|
};
|
|
return StackService.createComposeStackFromGitRepository(name, repositoryOptions, env, endpointId);
|
|
}
|
|
}
|
|
|
|
$scope.deployStack = function () {
|
|
var name = $scope.formValues.Name;
|
|
var method = $scope.state.Method;
|
|
|
|
var accessControlData = $scope.formValues.AccessControlData;
|
|
var userDetails = Authentication.getUserDetails();
|
|
var isAdmin = Authentication.isAdmin();
|
|
|
|
if (method === 'editor' && $scope.formValues.StackFileContent === '') {
|
|
$scope.state.formValidationError = 'Stack file content must not be empty';
|
|
return;
|
|
}
|
|
|
|
if (!validateForm(accessControlData, isAdmin)) {
|
|
return;
|
|
}
|
|
|
|
var type = $scope.state.StackType;
|
|
var action = createSwarmStack;
|
|
if (type === 2) {
|
|
action = createComposeStack;
|
|
}
|
|
$scope.state.actionInProgress = true;
|
|
action(name, method)
|
|
.then(function success(data) {
|
|
if (data.data) {
|
|
data = data.data;
|
|
}
|
|
const userId = userDetails.ID;
|
|
const resourceControl = data.ResourceControl;
|
|
return ResourceControlService.applyResourceControl(userId, accessControlData, resourceControl);
|
|
})
|
|
.then(function success() {
|
|
Notifications.success('Stack successfully deployed');
|
|
$state.go('docker.stacks');
|
|
})
|
|
.catch(function error(err) {
|
|
Notifications.error('Deployment error', err, 'Unable to deploy stack');
|
|
})
|
|
.finally(function final() {
|
|
$scope.state.actionInProgress = false;
|
|
});
|
|
};
|
|
|
|
$scope.editorUpdate = function (cm) {
|
|
$scope.formValues.StackFileContent = cm.getValue();
|
|
};
|
|
|
|
$scope.onChangeTemplate = async function onChangeTemplate(template) {
|
|
try {
|
|
$scope.selectedTemplate = template;
|
|
$scope.formValues.StackFileContent = await CustomTemplateService.customTemplateFile(template.Id);
|
|
} catch (err) {
|
|
Notifications.error('Failure', err, 'Unable to retrieve Custom Template file');
|
|
}
|
|
};
|
|
|
|
async function initView() {
|
|
var endpointMode = $scope.applicationState.endpoint.mode;
|
|
const endpointId = +$state.params.endpointId;
|
|
$scope.state.StackType = 2;
|
|
if (endpointMode.provider === 'DOCKER_SWARM_MODE' && endpointMode.role === 'MANAGER') {
|
|
$scope.state.StackType = 1;
|
|
}
|
|
|
|
try {
|
|
const templates = await CustomTemplateService.customTemplates($scope.state.StackType);
|
|
$scope.templates = _.map(templates, (template) => ({ ...template, label: `${template.Title} - ${template.Description}` }));
|
|
} catch (err) {
|
|
Notifications.error('Failure', err, 'Unable to retrieve Custom Templates');
|
|
}
|
|
|
|
try {
|
|
const endpoint = EndpointProvider.currentEndpoint();
|
|
$scope.composeSyntaxMaxVersion = endpoint.ComposeSyntaxMaxVersion;
|
|
} catch (err) {
|
|
Notifications.error('Failure', err, 'Unable to retrieve the ComposeSyntaxMaxVersion');
|
|
}
|
|
}
|
|
|
|
initView();
|
|
});
|