mirror of
https://github.com/portainer/portainer.git
synced 2025-08-09 07:45:22 +02:00
refactor(stacks): extract auto update logic [EE-4945] (#8545)
This commit is contained in:
parent
085381e6fc
commit
6918da2414
42 changed files with 410 additions and 166 deletions
|
@ -10,6 +10,8 @@ export const gitFormAutoUpdate: IComponentOptions = {
|
|||
environment-type="$ctrl.environmentType"
|
||||
is-force-pull-visible="$ctrl.isForcePullVisible"
|
||||
base-webhook-url="$ctrl.baseWebhookUrl"
|
||||
webhook-id="$ctrl.webhookId"
|
||||
webhooks-docs="$ctrl.webhooksDocs"
|
||||
errors="$ctrl.errors">
|
||||
</react-git-form-auto-update-fieldset>
|
||||
</ng-form>`,
|
||||
|
@ -19,6 +21,8 @@ export const gitFormAutoUpdate: IComponentOptions = {
|
|||
environmentType: '@',
|
||||
isForcePullVisible: '<',
|
||||
baseWebhookUrl: '@',
|
||||
webhookId: '@',
|
||||
webhooksDocs: '@',
|
||||
},
|
||||
controller,
|
||||
};
|
||||
|
|
|
@ -11,10 +11,11 @@ export const gitForm: IComponentOptions = {
|
|||
is-docker-standalone="$ctrl.isDockerStandalone"
|
||||
deploy-method="$ctrl.deployMethod"
|
||||
is-additional-files-field-visible="$ctrl.isAdditionalFilesFieldVisible"
|
||||
is-auto-update-visible="$ctrl.isAutoUpdateVisible"
|
||||
is-force-pull-visible="$ctrl.isForcePullVisible"
|
||||
is-auth-explanation-visible="$ctrl.isAuthExplanationVisible"
|
||||
base-webhook-url="$ctrl.baseWebhookUrl"
|
||||
webhook-id="$ctrl.webhookId"
|
||||
webhooks-docs="$ctrl.webhooksDocs"
|
||||
errors="$ctrl.errors">
|
||||
</react-git-form>
|
||||
</ng-form>`,
|
||||
|
@ -25,9 +26,10 @@ export const gitForm: IComponentOptions = {
|
|||
deployMethod: '@',
|
||||
baseWebhookUrl: '@',
|
||||
isAdditionalFilesFieldVisible: '<',
|
||||
isAutoUpdateVisible: '<',
|
||||
isForcePullVisible: '<',
|
||||
isAuthExplanationVisible: '<',
|
||||
webhookId: '@',
|
||||
webhooksDocs: '@',
|
||||
},
|
||||
controller,
|
||||
};
|
||||
|
|
|
@ -3,7 +3,7 @@ import { confirm } from '@@/modals/confirm';
|
|||
import { buildConfirmButton } from '@@/modals/utils';
|
||||
import { ModalType } from '@@/modals';
|
||||
import { parseAutoUpdateResponse } from '@/react/portainer/gitops/AutoUpdateFieldset/utils';
|
||||
import { baseStackWebhookUrl } from '@/portainer/helpers/webhookHelper';
|
||||
import { baseStackWebhookUrl, createWebhookId } from '@/portainer/helpers/webhookHelper';
|
||||
|
||||
class KubernetesRedeployAppGitFormController {
|
||||
/* @ngInject */
|
||||
|
@ -20,6 +20,7 @@ class KubernetesRedeployAppGitFormController {
|
|||
isEdit: false,
|
||||
hasUnsavedChanges: false,
|
||||
baseWebhookUrl: baseStackWebhookUrl(),
|
||||
webhookId: createWebhookId(),
|
||||
};
|
||||
|
||||
this.formValues = {
|
||||
|
@ -117,7 +118,7 @@ class KubernetesRedeployAppGitFormController {
|
|||
return this.$async(async () => {
|
||||
try {
|
||||
this.state.saveGitSettingsInProgress = true;
|
||||
await this.StackService.updateKubeStack({ EndpointId: this.stack.EndpointId, Id: this.stack.Id }, null, this.formValues);
|
||||
await this.StackService.updateKubeStack({ EndpointId: this.stack.EndpointId, Id: this.stack.Id }, { gitConfig: this.formValues, webhookId: this.state.webhookId });
|
||||
this.savedFormValues = angular.copy(this.formValues);
|
||||
this.state.hasUnsavedChanges = false;
|
||||
this.Notifications.success('Success', 'Save stack settings successfully');
|
||||
|
@ -138,6 +139,10 @@ class KubernetesRedeployAppGitFormController {
|
|||
|
||||
this.formValues.AutoUpdate = parseAutoUpdateResponse(this.stack.AutoUpdate);
|
||||
|
||||
if (this.stack.AutoUpdate.Webhook) {
|
||||
this.state.webhookId = this.stack.AutoUpdate.Webhook;
|
||||
}
|
||||
|
||||
if (this.stack.GitConfig && this.stack.GitConfig.Authentication) {
|
||||
this.formValues.RepositoryUsername = this.stack.GitConfig.Authentication.Username;
|
||||
this.formValues.RepositoryAuthentication = true;
|
||||
|
|
|
@ -10,6 +10,8 @@
|
|||
on-change="($ctrl.onChangeAutoUpdate)"
|
||||
environment-type="KUBERNETES"
|
||||
base-webhook-url="{{ $ctrl.state.baseWebhookUrl }}"
|
||||
webhook-id="{{ $ctrl.state.webhookId }}"
|
||||
webhooks-docs="https://docs.portainer.io/user/kubernetes/applications/webhooks"
|
||||
></git-form-auto-update-fieldset>
|
||||
<time-window-display></time-window-display>
|
||||
|
||||
|
|
|
@ -3,7 +3,7 @@ import { FeatureId } from '@/react/portainer/feature-flags/enums';
|
|||
import { confirmStackUpdate } from '@/react/docker/stacks/common/confirm-stack-update';
|
||||
|
||||
import { parseAutoUpdateResponse } from '@/react/portainer/gitops/AutoUpdateFieldset/utils';
|
||||
import { baseStackWebhookUrl } from '@/portainer/helpers/webhookHelper';
|
||||
import { baseStackWebhookUrl, createWebhookId } from '@/portainer/helpers/webhookHelper';
|
||||
|
||||
class StackRedeployGitFormController {
|
||||
/* @ngInject */
|
||||
|
@ -23,6 +23,7 @@ class StackRedeployGitFormController {
|
|||
isEdit: false,
|
||||
hasUnsavedChanges: false,
|
||||
baseWebhookUrl: baseStackWebhookUrl(),
|
||||
webhookId: createWebhookId(),
|
||||
};
|
||||
|
||||
this.formValues = {
|
||||
|
@ -132,7 +133,8 @@ class StackRedeployGitFormController {
|
|||
this.stack.Id,
|
||||
this.stack.EndpointId,
|
||||
this.FormHelper.removeInvalidEnvVars(this.formValues.Env),
|
||||
this.formValues
|
||||
this.formValues,
|
||||
this.state.webhookId
|
||||
);
|
||||
this.savedFormValues = angular.copy(this.formValues);
|
||||
this.state.hasUnsavedChanges = false;
|
||||
|
@ -180,6 +182,10 @@ class StackRedeployGitFormController {
|
|||
|
||||
this.formValues.AutoUpdate = parseAutoUpdateResponse(this.stack.AutoUpdate);
|
||||
|
||||
if (this.stack.AutoUpdate.Webhook) {
|
||||
this.state.webhookId = this.stack.AutoUpdate.Webhook;
|
||||
}
|
||||
|
||||
if (this.stack.GitConfig && this.stack.GitConfig.Authentication) {
|
||||
this.formValues.RepositoryUsername = this.stack.GitConfig.Authentication.Username;
|
||||
this.formValues.RepositoryAuthentication = true;
|
||||
|
|
|
@ -14,6 +14,8 @@
|
|||
environment-type="DOCKER"
|
||||
is-force-pull-visible="$ctrl.stack.Type !== 3"
|
||||
base-webhook-url="{{ $ctrl.state.baseWebhookUrl }}"
|
||||
webhook-id="{{ $ctrl.state.webhookId }}"
|
||||
webhooks-docs="https://docs.portainer.io/user/docker/stacks/webhooks"
|
||||
></git-form-auto-update-fieldset>
|
||||
<div class="form-group">
|
||||
<div class="col-sm-12">
|
||||
|
|
|
@ -1,3 +1,5 @@
|
|||
import uuid from 'uuid';
|
||||
|
||||
import { API_ENDPOINT_STACKS, API_ENDPOINT_WEBHOOKS } from '@/constants';
|
||||
|
||||
import { baseHref } from './pathHelper';
|
||||
|
@ -16,6 +18,10 @@ export function stackWebhookUrl(token: string) {
|
|||
return `${baseStackWebhookUrl()}/${token}`;
|
||||
}
|
||||
|
||||
export function createWebhookId() {
|
||||
return uuid();
|
||||
}
|
||||
|
||||
/* @ngInject */
|
||||
export function WebhookHelperFactory() {
|
||||
return {
|
||||
|
|
|
@ -25,6 +25,8 @@ export const gitFormModule = angular
|
|||
'isAuthExplanationVisible',
|
||||
'errors',
|
||||
'baseWebhookUrl',
|
||||
'webhookId',
|
||||
'webhooksDocs',
|
||||
])
|
||||
)
|
||||
.component(
|
||||
|
@ -46,6 +48,8 @@ export const gitFormModule = angular
|
|||
'isForcePullVisible',
|
||||
'errors',
|
||||
'baseWebhookUrl',
|
||||
'webhookId',
|
||||
'webhooksDocs',
|
||||
])
|
||||
)
|
||||
.component(
|
||||
|
|
|
@ -270,7 +270,7 @@ angular.module('portainer.app').factory('StackService', [
|
|||
).$promise;
|
||||
};
|
||||
|
||||
service.updateKubeStack = function (stack, stackFile, gitConfig) {
|
||||
service.updateKubeStack = function (stack, { stackFile, gitConfig, webhookId }) {
|
||||
let payload = {};
|
||||
|
||||
if (stackFile) {
|
||||
|
@ -279,7 +279,7 @@ angular.module('portainer.app').factory('StackService', [
|
|||
};
|
||||
} else {
|
||||
payload = {
|
||||
AutoUpdate: transformAutoUpdateViewModel(gitConfig.AutoUpdate),
|
||||
AutoUpdate: transformAutoUpdateViewModel(gitConfig.AutoUpdate, webhookId),
|
||||
RepositoryReferenceName: gitConfig.RefName,
|
||||
RepositoryAuthentication: gitConfig.RepositoryAuthentication,
|
||||
RepositoryUsername: gitConfig.RepositoryUsername,
|
||||
|
@ -455,11 +455,11 @@ angular.module('portainer.app').factory('StackService', [
|
|||
).$promise;
|
||||
}
|
||||
|
||||
service.updateGitStackSettings = function (id, endpointId, env, gitConfig) {
|
||||
service.updateGitStackSettings = function (id, endpointId, env, gitConfig, webhookId) {
|
||||
return Stack.updateGitStackSettings(
|
||||
{ endpointId, id },
|
||||
{
|
||||
AutoUpdate: transformAutoUpdateViewModel(gitConfig.AutoUpdate),
|
||||
AutoUpdate: transformAutoUpdateViewModel(gitConfig.AutoUpdate, webhookId),
|
||||
Env: env,
|
||||
RepositoryReferenceName: gitConfig.RefName,
|
||||
RepositoryAuthentication: gitConfig.RepositoryAuthentication,
|
||||
|
|
|
@ -9,7 +9,7 @@ import { renderTemplate } from '@/react/portainer/custom-templates/components/ut
|
|||
import { editor, upload, git, customTemplate } from '@@/BoxSelector/common-options/build-methods';
|
||||
import { confirmWebEditorDiscard } from '@@/modals/confirm';
|
||||
import { parseAutoUpdateResponse, transformAutoUpdateViewModel } from '@/react/portainer/gitops/AutoUpdateFieldset/utils';
|
||||
import { baseStackWebhookUrl } from '@/portainer/helpers/webhookHelper';
|
||||
import { baseStackWebhookUrl, createWebhookId } from '@/portainer/helpers/webhookHelper';
|
||||
|
||||
angular
|
||||
.module('portainer.app')
|
||||
|
@ -70,6 +70,7 @@ angular
|
|||
selectedTemplate: null,
|
||||
selectedTemplateId: null,
|
||||
baseWebhookUrl: baseStackWebhookUrl(),
|
||||
webhookId: createWebhookId(),
|
||||
};
|
||||
|
||||
$window.onbeforeunload = () => {
|
||||
|
@ -153,6 +154,7 @@ angular
|
|||
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);
|
||||
|
@ -172,7 +174,7 @@ angular
|
|||
RepositoryAuthentication: $scope.formValues.RepositoryAuthentication,
|
||||
RepositoryUsername: $scope.formValues.RepositoryUsername,
|
||||
RepositoryPassword: $scope.formValues.RepositoryPassword,
|
||||
AutoUpdate: transformAutoUpdateViewModel($scope.formValues.AutoUpdate),
|
||||
AutoUpdate: transformAutoUpdateViewModel($scope.formValues.AutoUpdate, $scope.state.webhookId),
|
||||
};
|
||||
|
||||
return StackService.createSwarmStackFromGitRepository(name, repositoryOptions, env, endpointId);
|
||||
|
@ -198,7 +200,7 @@ angular
|
|||
RepositoryAuthentication: $scope.formValues.RepositoryAuthentication,
|
||||
RepositoryUsername: $scope.formValues.RepositoryUsername,
|
||||
RepositoryPassword: $scope.formValues.RepositoryPassword,
|
||||
AutoUpdate: transformAutoUpdateViewModel($scope.formValues.AutoUpdate),
|
||||
AutoUpdate: transformAutoUpdateViewModel($scope.formValues.AutoUpdate, $scope.state.webhookId),
|
||||
};
|
||||
|
||||
return StackService.createComposeStackFromGitRepository(name, repositoryOptions, env, endpointId);
|
||||
|
|
|
@ -83,10 +83,11 @@
|
|||
on-change="(onChangeFormValues)"
|
||||
is-docker-standalone="isDockerStandalone"
|
||||
is-additional-files-field-visible="true"
|
||||
is-auto-update-visible="true"
|
||||
is-auth-explanation-visible="true"
|
||||
is-force-pull-visible="true"
|
||||
base-webhook-url="{{ state.baseWebhookUrl }}"
|
||||
webhook-id="{{ state.webhookId }}"
|
||||
webhooks-docs="https://docs.portainer.io/user/docker/stacks/webhooks"
|
||||
></git-form>
|
||||
|
||||
<div ng-show="state.Method === 'template'">
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue