plugin-workflow-portainer 0.0.0-stage → 0.1.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +176 -0
- package/README.md +31 -3
- package/client-v2.js +1 -0
- package/client.js +1 -0
- package/dist/client/127.5012da93825a6e5c.js +10 -0
- package/dist/client/57.ace9538136438718.js +10 -0
- package/dist/client/65.ec4a55173511c06d.js +10 -0
- package/dist/client/660.546c702d1ddf7eff.js +10 -0
- package/dist/client/index.js +10 -0
- package/dist/client-v2/127.0ec4dce7b13750e9.js +10 -0
- package/dist/client-v2/57.e7cfc50fb651ac14.js +10 -0
- package/dist/client-v2/65.9c745ea32ac96e98.js +10 -0
- package/dist/client-v2/660.29ae3c3b4040039d.js +10 -0
- package/dist/client-v2/index.js +10 -0
- package/dist/externalVersion.js +20 -0
- package/dist/index.js +48 -0
- package/dist/locale/en-US.json +151 -0
- package/dist/locale/vi-VN.json +151 -0
- package/dist/locale/zh-CN.json +151 -0
- package/dist/node_modules/joi/dist/joi-browser.min.js +1 -0
- package/dist/node_modules/joi/lib/annotate.js +175 -0
- package/dist/node_modules/joi/lib/base.js +1069 -0
- package/dist/node_modules/joi/lib/cache.js +143 -0
- package/dist/node_modules/joi/lib/common.js +216 -0
- package/dist/node_modules/joi/lib/compile.js +283 -0
- package/dist/node_modules/joi/lib/errors.js +271 -0
- package/dist/node_modules/joi/lib/extend.js +312 -0
- package/dist/node_modules/joi/lib/index.d.ts +2365 -0
- package/dist/node_modules/joi/lib/index.js +1 -0
- package/dist/node_modules/joi/lib/manifest.js +476 -0
- package/dist/node_modules/joi/lib/messages.js +207 -0
- package/dist/node_modules/joi/lib/modify.js +267 -0
- package/dist/node_modules/joi/lib/ref.js +414 -0
- package/dist/node_modules/joi/lib/schemas.js +302 -0
- package/dist/node_modules/joi/lib/state.js +166 -0
- package/dist/node_modules/joi/lib/template.js +463 -0
- package/dist/node_modules/joi/lib/trace.js +346 -0
- package/dist/node_modules/joi/lib/types/alternatives.js +364 -0
- package/dist/node_modules/joi/lib/types/any.js +174 -0
- package/dist/node_modules/joi/lib/types/array.js +809 -0
- package/dist/node_modules/joi/lib/types/binary.js +100 -0
- package/dist/node_modules/joi/lib/types/boolean.js +150 -0
- package/dist/node_modules/joi/lib/types/date.js +233 -0
- package/dist/node_modules/joi/lib/types/function.js +93 -0
- package/dist/node_modules/joi/lib/types/keys.js +1084 -0
- package/dist/node_modules/joi/lib/types/link.js +184 -0
- package/dist/node_modules/joi/lib/types/number.js +363 -0
- package/dist/node_modules/joi/lib/types/object.js +22 -0
- package/dist/node_modules/joi/lib/types/string.js +850 -0
- package/dist/node_modules/joi/lib/types/symbol.js +102 -0
- package/dist/node_modules/joi/lib/validator.js +750 -0
- package/dist/node_modules/joi/lib/values.js +263 -0
- package/dist/node_modules/joi/node_modules/@hapi/topo/lib/index.d.ts +60 -0
- package/dist/node_modules/joi/node_modules/@hapi/topo/lib/index.js +225 -0
- package/dist/node_modules/joi/node_modules/@hapi/topo/package.json +30 -0
- package/dist/node_modules/joi/package.json +1 -0
- package/dist/server/actions/portainer.js +192 -0
- package/dist/server/collections/portainer-instances.js +54 -0
- package/dist/server/index.js +54 -0
- package/dist/server/instructions/PortainerStackControlInstruction.js +156 -0
- package/dist/server/instructions/PortainerStackRedeployInstruction.js +254 -0
- package/dist/server/instructions/helpers.js +211 -0
- package/dist/server/plugin.js +170 -0
- package/dist/server/services/PortainerClient.js +497 -0
- package/dist/shared/collection.js +57 -0
- package/dist/shared/constants.js +66 -0
- package/dist/shared/env.js +221 -0
- package/dist/shared/types.js +24 -0
- package/package.json +50 -4
- package/server.js +1 -0
- package/src/client/index.tsx +50 -0
- package/src/client/instructions.tsx +76 -0
- package/src/client-v2/__tests__/workflow-registration.test.tsx +132 -0
- package/src/client-v2/components/ControlFieldset.tsx +46 -0
- package/src/client-v2/components/PortainerEnvEditor.tsx +223 -0
- package/src/client-v2/components/PortainerSettingsPage.tsx +671 -0
- package/src/client-v2/components/PortainerTargetFields.tsx +317 -0
- package/src/client-v2/components/RedeployFieldset.tsx +123 -0
- package/src/client-v2/index.tsx +50 -0
- package/src/client-v2/instructions.tsx +162 -0
- package/src/client-v2/locale.ts +24 -0
- package/src/index.ts +11 -0
- package/src/locale/en-US.json +151 -0
- package/src/locale/vi-VN.json +151 -0
- package/src/locale/zh-CN.json +151 -0
- package/src/server/__tests__/portainer-workflow.test.ts +455 -0
- package/src/server/actions/portainer.ts +196 -0
- package/src/server/collections/portainer-instances.ts +34 -0
- package/src/server/index.ts +13 -0
- package/src/server/instructions/PortainerStackControlInstruction.ts +139 -0
- package/src/server/instructions/PortainerStackRedeployInstruction.ts +255 -0
- package/src/server/instructions/helpers.ts +237 -0
- package/src/server/plugin.ts +167 -0
- package/src/server/services/PortainerClient.ts +589 -0
- package/src/shared/collection.ts +32 -0
- package/src/shared/constants.ts +25 -0
- package/src/shared/env.ts +228 -0
- package/src/shared/types.ts +105 -0
|
@@ -0,0 +1,317 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* This file is part of the NocoBase (R) project.
|
|
3
|
+
* Copyright (c) 2020-2024 NocoBase Co., Ltd.
|
|
4
|
+
* Authors: NocoBase Team.
|
|
5
|
+
*
|
|
6
|
+
* This project is dual-licensed under AGPL-3.0 and NocoBase Commercial License.
|
|
7
|
+
* For more information, please refer to: https://www.nocobase.com/agreement.
|
|
8
|
+
*/
|
|
9
|
+
|
|
10
|
+
import { ReloadOutlined } from '@ant-design/icons';
|
|
11
|
+
import { useApp } from '@nocobase/client-v2';
|
|
12
|
+
import { isWorkflowVariableValue, WorkflowVariableWrapper } from '@nocobase/plugin-workflow/client-v2';
|
|
13
|
+
import { Button, Flex, Form, InputNumber, Select, Tag } from 'antd';
|
|
14
|
+
import React, { useCallback, useEffect, useMemo, useState } from 'react';
|
|
15
|
+
import { PORTAINER_RESOURCE } from '../../shared/constants';
|
|
16
|
+
import type { PortainerEndpointSummary, PortainerInstanceSummary, PortainerStackSummary } from '../../shared/types';
|
|
17
|
+
import { useT } from '../locale';
|
|
18
|
+
|
|
19
|
+
export interface StaticStackContext {
|
|
20
|
+
instanceId?: number;
|
|
21
|
+
stack?: PortainerStackSummary;
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
export function PortainerInstanceField() {
|
|
25
|
+
const t = useT();
|
|
26
|
+
const api = useApp().apiClient;
|
|
27
|
+
const [instances, setInstances] = useState<PortainerInstanceSummary[]>([]);
|
|
28
|
+
const [loading, setLoading] = useState(false);
|
|
29
|
+
|
|
30
|
+
const loadInstances = useCallback(async () => {
|
|
31
|
+
setLoading(true);
|
|
32
|
+
try {
|
|
33
|
+
const res = await api.request<{ data?: PortainerInstanceSummary[] }>({
|
|
34
|
+
url: `${PORTAINER_RESOURCE}:listInstances`,
|
|
35
|
+
method: 'get',
|
|
36
|
+
});
|
|
37
|
+
setInstances(Array.isArray(res?.data?.data) ? res.data.data : []);
|
|
38
|
+
} catch {
|
|
39
|
+
setInstances([]);
|
|
40
|
+
} finally {
|
|
41
|
+
setLoading(false);
|
|
42
|
+
}
|
|
43
|
+
}, [api]);
|
|
44
|
+
|
|
45
|
+
useEffect(() => {
|
|
46
|
+
loadInstances();
|
|
47
|
+
}, [loadInstances]);
|
|
48
|
+
|
|
49
|
+
const options = useMemo(
|
|
50
|
+
() =>
|
|
51
|
+
instances.map((inst) => ({
|
|
52
|
+
value: inst.id,
|
|
53
|
+
label: inst.isDefault ? `${inst.name} (${t('Default')})` : inst.name,
|
|
54
|
+
})),
|
|
55
|
+
[instances, t],
|
|
56
|
+
);
|
|
57
|
+
|
|
58
|
+
return (
|
|
59
|
+
<Form.Item
|
|
60
|
+
name={['config', 'instanceId']}
|
|
61
|
+
label={t('Portainer instance')}
|
|
62
|
+
extra={t('Leave empty to use the default enabled Portainer instance, or bind a workflow variable.')}
|
|
63
|
+
>
|
|
64
|
+
<WorkflowVariableWrapper<number>
|
|
65
|
+
render={({ value, onChange }) => (
|
|
66
|
+
<Select
|
|
67
|
+
allowClear
|
|
68
|
+
loading={loading}
|
|
69
|
+
value={typeof value === 'number' ? value : value ? Number(value) : undefined}
|
|
70
|
+
onChange={(nextVal) => onChange?.(typeof nextVal === 'number' ? nextVal : null)}
|
|
71
|
+
options={options}
|
|
72
|
+
placeholder={t('Default Portainer instance')}
|
|
73
|
+
style={{ width: '100%' }}
|
|
74
|
+
/>
|
|
75
|
+
)}
|
|
76
|
+
/>
|
|
77
|
+
</Form.Item>
|
|
78
|
+
);
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
export function PortainerTargetFields({
|
|
82
|
+
onStackContextChange,
|
|
83
|
+
}: {
|
|
84
|
+
onStackContextChange?: (ctx: StaticStackContext) => void;
|
|
85
|
+
}) {
|
|
86
|
+
const t = useT();
|
|
87
|
+
const api = useApp().apiClient;
|
|
88
|
+
const form = Form.useFormInstance();
|
|
89
|
+
|
|
90
|
+
const watchedInstanceId = Form.useWatch(['config', 'instanceId'], form) as string | number | null | undefined;
|
|
91
|
+
const watchedEndpointId = Form.useWatch(['config', 'endpointId'], form) as string | number | null | undefined;
|
|
92
|
+
const watchedStackId = Form.useWatch(['config', 'stackId'], form) as string | number | null | undefined;
|
|
93
|
+
|
|
94
|
+
const instanceIsVar = isWorkflowVariableValue(watchedInstanceId);
|
|
95
|
+
const endpointIsVar = isWorkflowVariableValue(watchedEndpointId);
|
|
96
|
+
const stackIsVar = isWorkflowVariableValue(watchedStackId);
|
|
97
|
+
|
|
98
|
+
const numericInstanceId =
|
|
99
|
+
!instanceIsVar && watchedInstanceId !== null && typeof watchedInstanceId !== 'undefined' && watchedInstanceId !== ''
|
|
100
|
+
? Number(watchedInstanceId)
|
|
101
|
+
: undefined;
|
|
102
|
+
const numericEndpointId =
|
|
103
|
+
!endpointIsVar && watchedEndpointId !== null && typeof watchedEndpointId !== 'undefined' && watchedEndpointId !== ''
|
|
104
|
+
? Number(watchedEndpointId)
|
|
105
|
+
: undefined;
|
|
106
|
+
const numericStackId =
|
|
107
|
+
!stackIsVar && watchedStackId !== null && typeof watchedStackId !== 'undefined' && watchedStackId !== ''
|
|
108
|
+
? Number(watchedStackId)
|
|
109
|
+
: undefined;
|
|
110
|
+
|
|
111
|
+
const [endpoints, setEndpoints] = useState<PortainerEndpointSummary[]>([]);
|
|
112
|
+
const [stacks, setStacks] = useState<PortainerStackSummary[]>([]);
|
|
113
|
+
const [loadingEndpoints, setLoadingEndpoints] = useState(false);
|
|
114
|
+
const [loadingStacks, setLoadingStacks] = useState(false);
|
|
115
|
+
|
|
116
|
+
const fetchEndpoints = useCallback(async () => {
|
|
117
|
+
if (instanceIsVar) {
|
|
118
|
+
setEndpoints([]);
|
|
119
|
+
return;
|
|
120
|
+
}
|
|
121
|
+
setLoadingEndpoints(true);
|
|
122
|
+
try {
|
|
123
|
+
const res = await api.request<{ data?: PortainerEndpointSummary[] }>({
|
|
124
|
+
url: `${PORTAINER_RESOURCE}:listEndpoints`,
|
|
125
|
+
method: 'get',
|
|
126
|
+
params: numericInstanceId ? { instanceId: numericInstanceId } : {},
|
|
127
|
+
});
|
|
128
|
+
setEndpoints(Array.isArray(res?.data?.data) ? res.data.data : []);
|
|
129
|
+
} catch {
|
|
130
|
+
setEndpoints([]);
|
|
131
|
+
} finally {
|
|
132
|
+
setLoadingEndpoints(false);
|
|
133
|
+
}
|
|
134
|
+
}, [api, instanceIsVar, numericInstanceId]);
|
|
135
|
+
|
|
136
|
+
const fetchStacks = useCallback(async () => {
|
|
137
|
+
if (instanceIsVar || endpointIsVar) {
|
|
138
|
+
setStacks([]);
|
|
139
|
+
return;
|
|
140
|
+
}
|
|
141
|
+
setLoadingStacks(true);
|
|
142
|
+
try {
|
|
143
|
+
const res = await api.request<{ data?: PortainerStackSummary[] }>({
|
|
144
|
+
url: `${PORTAINER_RESOURCE}:listStacks`,
|
|
145
|
+
method: 'get',
|
|
146
|
+
params: {
|
|
147
|
+
...(numericInstanceId ? { instanceId: numericInstanceId } : {}),
|
|
148
|
+
...(numericEndpointId ? { endpointId: numericEndpointId } : {}),
|
|
149
|
+
},
|
|
150
|
+
});
|
|
151
|
+
setStacks(Array.isArray(res?.data?.data) ? res.data.data : []);
|
|
152
|
+
} catch {
|
|
153
|
+
setStacks([]);
|
|
154
|
+
} finally {
|
|
155
|
+
setLoadingStacks(false);
|
|
156
|
+
}
|
|
157
|
+
}, [api, endpointIsVar, instanceIsVar, numericEndpointId, numericInstanceId]);
|
|
158
|
+
|
|
159
|
+
useEffect(() => {
|
|
160
|
+
fetchEndpoints();
|
|
161
|
+
}, [fetchEndpoints]);
|
|
162
|
+
|
|
163
|
+
useEffect(() => {
|
|
164
|
+
fetchStacks();
|
|
165
|
+
}, [fetchStacks]);
|
|
166
|
+
|
|
167
|
+
const selectedStack = useMemo(
|
|
168
|
+
() => (numericStackId ? stacks.find((item) => item.id === numericStackId) : undefined),
|
|
169
|
+
[numericStackId, stacks],
|
|
170
|
+
);
|
|
171
|
+
|
|
172
|
+
useEffect(() => {
|
|
173
|
+
onStackContextChange?.({
|
|
174
|
+
instanceId: instanceIsVar ? undefined : numericInstanceId,
|
|
175
|
+
stack: stackIsVar ? undefined : selectedStack,
|
|
176
|
+
});
|
|
177
|
+
}, [instanceIsVar, numericInstanceId, onStackContextChange, selectedStack, stackIsVar]);
|
|
178
|
+
|
|
179
|
+
const endpointOptions = useMemo(
|
|
180
|
+
() =>
|
|
181
|
+
endpoints.map((ep) => ({
|
|
182
|
+
value: ep.id,
|
|
183
|
+
searchLabel: `${ep.name} ${ep.id}`,
|
|
184
|
+
label: (
|
|
185
|
+
<Flex align="center" justify="space-between" gap="small">
|
|
186
|
+
<span>
|
|
187
|
+
{ep.name} (#{ep.id})
|
|
188
|
+
</span>
|
|
189
|
+
<Tag color={ep.status === 1 ? 'success' : 'default'} style={{ marginInlineEnd: 0 }}>
|
|
190
|
+
{ep.status === 1 ? t('Up') : t('Down')}
|
|
191
|
+
</Tag>
|
|
192
|
+
</Flex>
|
|
193
|
+
),
|
|
194
|
+
})),
|
|
195
|
+
[endpoints, t],
|
|
196
|
+
);
|
|
197
|
+
|
|
198
|
+
const stackOptions = useMemo(
|
|
199
|
+
() =>
|
|
200
|
+
stacks.map((st) => ({
|
|
201
|
+
value: st.id,
|
|
202
|
+
searchLabel: `${st.name} ${st.id} ${st.gitReference ?? ''}`,
|
|
203
|
+
label: (
|
|
204
|
+
<Flex align="center" justify="space-between" gap="small">
|
|
205
|
+
<span>
|
|
206
|
+
{st.name} (#{st.id})
|
|
207
|
+
</span>
|
|
208
|
+
<span>
|
|
209
|
+
<Tag color={st.isGitStack ? 'processing' : 'purple'}>{st.isGitStack ? t('Git Stack') : t('Compose')}</Tag>
|
|
210
|
+
{st.gitReference ? (
|
|
211
|
+
<Tag style={{ marginInlineEnd: 0 }}>{st.gitReference.replace(/^refs\/heads\//, '')}</Tag>
|
|
212
|
+
) : null}
|
|
213
|
+
</span>
|
|
214
|
+
</Flex>
|
|
215
|
+
),
|
|
216
|
+
})),
|
|
217
|
+
[stacks, t],
|
|
218
|
+
);
|
|
219
|
+
|
|
220
|
+
return (
|
|
221
|
+
<>
|
|
222
|
+
<PortainerInstanceField />
|
|
223
|
+
|
|
224
|
+
<Form.Item
|
|
225
|
+
name={['config', 'endpointId']}
|
|
226
|
+
label={t('Environment (Endpoint)')}
|
|
227
|
+
extra={t('Select a Portainer environment or bind a dynamic endpointId variable.')}
|
|
228
|
+
>
|
|
229
|
+
<WorkflowVariableWrapper<number>
|
|
230
|
+
render={({ value, onChange }) =>
|
|
231
|
+
instanceIsVar ? (
|
|
232
|
+
<InputNumber
|
|
233
|
+
min={1}
|
|
234
|
+
value={typeof value === 'number' ? value : value ? Number(value) : undefined}
|
|
235
|
+
onChange={(nextVal) => onChange?.(typeof nextVal === 'number' ? nextVal : null)}
|
|
236
|
+
placeholder={t('Endpoint ID (e.g. 1)')}
|
|
237
|
+
style={{ width: '100%' }}
|
|
238
|
+
/>
|
|
239
|
+
) : (
|
|
240
|
+
<Flex gap="small" style={{ width: '100%' }}>
|
|
241
|
+
<Select
|
|
242
|
+
allowClear
|
|
243
|
+
showSearch
|
|
244
|
+
optionFilterProp="searchLabel"
|
|
245
|
+
loading={loadingEndpoints}
|
|
246
|
+
value={typeof value === 'number' ? value : value ? Number(value) : undefined}
|
|
247
|
+
onChange={(nextVal) => onChange?.(typeof nextVal === 'number' ? nextVal : null)}
|
|
248
|
+
options={endpointOptions}
|
|
249
|
+
placeholder={t('Auto-resolve from Stack or select environment')}
|
|
250
|
+
style={{ flex: 1, minWidth: 0 }}
|
|
251
|
+
/>
|
|
252
|
+
<Button
|
|
253
|
+
htmlType="button"
|
|
254
|
+
aria-label={t('Refresh Portainer environments')}
|
|
255
|
+
icon={<ReloadOutlined />}
|
|
256
|
+
loading={loadingEndpoints}
|
|
257
|
+
onClick={() => {
|
|
258
|
+
fetchEndpoints();
|
|
259
|
+
fetchStacks();
|
|
260
|
+
}}
|
|
261
|
+
/>
|
|
262
|
+
</Flex>
|
|
263
|
+
)
|
|
264
|
+
}
|
|
265
|
+
/>
|
|
266
|
+
</Form.Item>
|
|
267
|
+
|
|
268
|
+
<Form.Item
|
|
269
|
+
name={['config', 'stackId']}
|
|
270
|
+
label={t('Target Stack')}
|
|
271
|
+
rules={[{ required: true, message: t('Please select a Stack or bind a Stack ID variable') }]}
|
|
272
|
+
extra={
|
|
273
|
+
selectedStack?.isGitStack
|
|
274
|
+
? `${t('Connected Git repository')}: ${selectedStack.gitRepoUrl ?? '-'} (${
|
|
275
|
+
selectedStack.gitReference ?? 'refs/heads/main'
|
|
276
|
+
})`
|
|
277
|
+
: t('Choose the Portainer Stack to control or bind a stackId variable from upstream data.')
|
|
278
|
+
}
|
|
279
|
+
>
|
|
280
|
+
<WorkflowVariableWrapper<number>
|
|
281
|
+
render={({ value, onChange }) =>
|
|
282
|
+
instanceIsVar || endpointIsVar ? (
|
|
283
|
+
<InputNumber
|
|
284
|
+
min={1}
|
|
285
|
+
value={typeof value === 'number' ? value : value ? Number(value) : undefined}
|
|
286
|
+
onChange={(nextVal) => onChange?.(typeof nextVal === 'number' ? nextVal : null)}
|
|
287
|
+
placeholder={t('Stack ID (e.g. 12)')}
|
|
288
|
+
style={{ width: '100%' }}
|
|
289
|
+
/>
|
|
290
|
+
) : (
|
|
291
|
+
<Select
|
|
292
|
+
allowClear
|
|
293
|
+
showSearch
|
|
294
|
+
optionFilterProp="searchLabel"
|
|
295
|
+
loading={loadingStacks}
|
|
296
|
+
value={typeof value === 'number' ? value : value ? Number(value) : undefined}
|
|
297
|
+
onChange={(nextVal) => {
|
|
298
|
+
const numVal = typeof nextVal === 'number' ? nextVal : null;
|
|
299
|
+
onChange?.(numVal);
|
|
300
|
+
if (numVal && !numericEndpointId) {
|
|
301
|
+
const matched = stacks.find((item) => item.id === numVal);
|
|
302
|
+
if (matched?.endpointId) {
|
|
303
|
+
form.setFieldValue(['config', 'endpointId'], matched.endpointId);
|
|
304
|
+
}
|
|
305
|
+
}
|
|
306
|
+
}}
|
|
307
|
+
options={stackOptions}
|
|
308
|
+
placeholder={t('Select Portainer Stack')}
|
|
309
|
+
style={{ width: '100%' }}
|
|
310
|
+
/>
|
|
311
|
+
)
|
|
312
|
+
}
|
|
313
|
+
/>
|
|
314
|
+
</Form.Item>
|
|
315
|
+
</>
|
|
316
|
+
);
|
|
317
|
+
}
|
|
@@ -0,0 +1,123 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* This file is part of the NocoBase (R) project.
|
|
3
|
+
* Copyright (c) 2020-2024 NocoBase Co., Ltd.
|
|
4
|
+
* Authors: NocoBase Team.
|
|
5
|
+
*
|
|
6
|
+
* This project is dual-licensed under AGPL-3.0 and NocoBase Commercial License.
|
|
7
|
+
* For more information, please refer to: https://www.nocobase.com/agreement.
|
|
8
|
+
*/
|
|
9
|
+
|
|
10
|
+
import { WorkflowVariableInput, WorkflowVariableWrapper } from '@nocobase/plugin-workflow/client-v2';
|
|
11
|
+
import { Checkbox, Form, InputNumber, Radio } from 'antd';
|
|
12
|
+
import React, { useState } from 'react';
|
|
13
|
+
import { DEFAULT_TIMEOUT_MS, MAX_TIMEOUT_MS, MIN_TIMEOUT_MS } from '../../shared/constants';
|
|
14
|
+
import type { RedeployTargetMode } from '../../shared/types';
|
|
15
|
+
import { useT } from '../locale';
|
|
16
|
+
import { PortainerEnvEditor } from './PortainerEnvEditor';
|
|
17
|
+
import { PortainerInstanceField, PortainerTargetFields, type StaticStackContext } from './PortainerTargetFields';
|
|
18
|
+
|
|
19
|
+
export function RedeployFieldset() {
|
|
20
|
+
const t = useT();
|
|
21
|
+
const form = Form.useFormInstance();
|
|
22
|
+
const watchedMode = (Form.useWatch(['config', 'mode'], form) as RedeployTargetMode | undefined) ?? 'stack';
|
|
23
|
+
const [stackContext, setStackContext] = useState<StaticStackContext>({});
|
|
24
|
+
|
|
25
|
+
return (
|
|
26
|
+
<>
|
|
27
|
+
<Form.Item
|
|
28
|
+
name={['config', 'mode']}
|
|
29
|
+
label={t('Execution mode')}
|
|
30
|
+
initialValue="stack"
|
|
31
|
+
extra={t(
|
|
32
|
+
'Use Stack API to control Environment, Stack, Git branch, and full Env variables; use Stack Webhook when triggering an unauthenticated Portainer webhook UUID.',
|
|
33
|
+
)}
|
|
34
|
+
>
|
|
35
|
+
<Radio.Group
|
|
36
|
+
options={[
|
|
37
|
+
{ value: 'stack', label: t('Stack API (Git / Compose)') },
|
|
38
|
+
{ value: 'webhook', label: t('Stack Webhook') },
|
|
39
|
+
]}
|
|
40
|
+
/>
|
|
41
|
+
</Form.Item>
|
|
42
|
+
|
|
43
|
+
{watchedMode === 'webhook' ? (
|
|
44
|
+
<>
|
|
45
|
+
<PortainerInstanceField />
|
|
46
|
+
<Form.Item
|
|
47
|
+
name={['config', 'webhookId']}
|
|
48
|
+
label={t('Stack Webhook token')}
|
|
49
|
+
rules={[{ required: true, message: t('Webhook token is required') }]}
|
|
50
|
+
extra={t('The UUID at the end of /api/stacks/webhooks/<token>.')}
|
|
51
|
+
>
|
|
52
|
+
<WorkflowVariableInput placeholder="638e6967-ef77-4906-8af8-236800621360" />
|
|
53
|
+
</Form.Item>
|
|
54
|
+
<Form.Item
|
|
55
|
+
name={['config', 'webhookTag']}
|
|
56
|
+
label={t('Image tag override (optional)')}
|
|
57
|
+
extra={t('Appends ?tag=<value> when triggering a Portainer Stack webhook.')}
|
|
58
|
+
>
|
|
59
|
+
<WorkflowVariableInput placeholder="latest" />
|
|
60
|
+
</Form.Item>
|
|
61
|
+
</>
|
|
62
|
+
) : (
|
|
63
|
+
<>
|
|
64
|
+
<PortainerTargetFields onStackContextChange={setStackContext} />
|
|
65
|
+
|
|
66
|
+
<Form.Item
|
|
67
|
+
name={['config', 'gitReference']}
|
|
68
|
+
label={t('Git branch / tag override (optional)')}
|
|
69
|
+
extra={t(
|
|
70
|
+
'Leave empty to keep the Git reference already configured on Portainer (e.g. refs/heads/main), or pass a branch/tag such as main or refs/tags/v1.2.0.',
|
|
71
|
+
)}
|
|
72
|
+
>
|
|
73
|
+
<WorkflowVariableInput placeholder={stackContext.stack?.gitReference || 'refs/heads/main'} />
|
|
74
|
+
</Form.Item>
|
|
75
|
+
|
|
76
|
+
<Form.Item
|
|
77
|
+
name={['config', 'repullImage']}
|
|
78
|
+
valuePropName="checked"
|
|
79
|
+
initialValue={false}
|
|
80
|
+
extra={t(
|
|
81
|
+
'Enable when deploying a separate Stack so Portainer pulls the newly built image from your registry.',
|
|
82
|
+
)}
|
|
83
|
+
>
|
|
84
|
+
<Checkbox>{t('Force pull / repull latest images')}</Checkbox>
|
|
85
|
+
</Form.Item>
|
|
86
|
+
|
|
87
|
+
<Form.Item name={['config', 'prune']} valuePropName="checked" initialValue={false}>
|
|
88
|
+
<Checkbox>{t('Prune orphan services on redeploy')}</Checkbox>
|
|
89
|
+
</Form.Item>
|
|
90
|
+
|
|
91
|
+
<PortainerEnvEditor stackContext={stackContext} />
|
|
92
|
+
</>
|
|
93
|
+
)}
|
|
94
|
+
|
|
95
|
+
<Form.Item
|
|
96
|
+
name={['config', 'timeoutMs']}
|
|
97
|
+
label={t('Request timeout')}
|
|
98
|
+
initialValue={DEFAULT_TIMEOUT_MS}
|
|
99
|
+
extra={t('Increase timeout for Stacks that run long Dockerfile builds during git/redeploy.')}
|
|
100
|
+
>
|
|
101
|
+
<WorkflowVariableWrapper<number>
|
|
102
|
+
render={({ value, onChange }) => (
|
|
103
|
+
<InputNumber
|
|
104
|
+
min={MIN_TIMEOUT_MS}
|
|
105
|
+
max={MAX_TIMEOUT_MS}
|
|
106
|
+
step={5000}
|
|
107
|
+
addonAfter={t('ms')}
|
|
108
|
+
value={typeof value === 'number' ? value : value ? Number(value) : DEFAULT_TIMEOUT_MS}
|
|
109
|
+
onChange={(nextVal) => onChange?.(typeof nextVal === 'number' ? nextVal : null)}
|
|
110
|
+
style={{ width: '100%' }}
|
|
111
|
+
/>
|
|
112
|
+
)}
|
|
113
|
+
/>
|
|
114
|
+
</Form.Item>
|
|
115
|
+
|
|
116
|
+
<Form.Item name={['config', 'ignoreFail']} valuePropName="checked" initialValue={false}>
|
|
117
|
+
<Checkbox>{t('Ignore failed execution and continue workflow')}</Checkbox>
|
|
118
|
+
</Form.Item>
|
|
119
|
+
</>
|
|
120
|
+
);
|
|
121
|
+
}
|
|
122
|
+
|
|
123
|
+
export default RedeployFieldset;
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* This file is part of the NocoBase (R) project.
|
|
3
|
+
* Copyright (c) 2020-2024 NocoBase Co., Ltd.
|
|
4
|
+
* Authors: NocoBase Team.
|
|
5
|
+
*
|
|
6
|
+
* This project is dual-licensed under AGPL-3.0 and NocoBase Commercial License.
|
|
7
|
+
* For more information, please refer to: https://www.nocobase.com/agreement.
|
|
8
|
+
*/
|
|
9
|
+
|
|
10
|
+
import { Application, ExtendCollectionsProvider, Plugin } from '@nocobase/client-v2';
|
|
11
|
+
import type { Instruction } from '@nocobase/plugin-workflow/client-v2';
|
|
12
|
+
import { portainerInstancesCollection } from '../shared/collection';
|
|
13
|
+
import { PORTAINER_ACL_SNIPPET } from '../shared/constants';
|
|
14
|
+
import { registerInstructionsV2, type WorkflowInstructionRegistryLike } from './instructions';
|
|
15
|
+
|
|
16
|
+
const MENU_KEY = 'workflow-portainer';
|
|
17
|
+
|
|
18
|
+
export class PluginWorkflowPortainerClientV2 extends Plugin<Record<string, never>, Application> {
|
|
19
|
+
async load() {
|
|
20
|
+
this.app.addProvider(ExtendCollectionsProvider, {
|
|
21
|
+
collections: [portainerInstancesCollection],
|
|
22
|
+
});
|
|
23
|
+
|
|
24
|
+
const workflow = (this.app.pm.get('workflow') || this.app.pm.get('@nocobase/plugin-workflow')) as
|
|
25
|
+
| WorkflowInstructionRegistryLike<Instruction>
|
|
26
|
+
| undefined;
|
|
27
|
+
|
|
28
|
+
if (workflow) {
|
|
29
|
+
registerInstructionsV2(workflow);
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
this.pluginSettingsManager.addMenuItem({
|
|
33
|
+
key: MENU_KEY,
|
|
34
|
+
title: this.t('Portainer Workflows'),
|
|
35
|
+
icon: 'CloudServerOutlined',
|
|
36
|
+
aclSnippet: PORTAINER_ACL_SNIPPET,
|
|
37
|
+
});
|
|
38
|
+
|
|
39
|
+
this.pluginSettingsManager.addPageTabItem({
|
|
40
|
+
menuKey: MENU_KEY,
|
|
41
|
+
key: 'instances',
|
|
42
|
+
title: this.t('Portainer Instances'),
|
|
43
|
+
aclSnippet: PORTAINER_ACL_SNIPPET,
|
|
44
|
+
componentLoader: () =>
|
|
45
|
+
import('./components/PortainerSettingsPage').then((m) => ({ default: m.PortainerSettingsPage })),
|
|
46
|
+
});
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
export default PluginWorkflowPortainerClientV2;
|
|
@@ -0,0 +1,162 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* This file is part of the NocoBase (R) project.
|
|
3
|
+
* Copyright (c) 2020-2024 NocoBase Co., Ltd.
|
|
4
|
+
* Authors: NocoBase Team.
|
|
5
|
+
*
|
|
6
|
+
* This project is dual-licensed under AGPL-3.0 and NocoBase Commercial License.
|
|
7
|
+
* For more information, please refer to: https://www.nocobase.com/agreement.
|
|
8
|
+
*/
|
|
9
|
+
|
|
10
|
+
import { CloudUploadOutlined, ClusterOutlined } from '@ant-design/icons';
|
|
11
|
+
import {
|
|
12
|
+
defaultFieldNames,
|
|
13
|
+
Instruction,
|
|
14
|
+
type UseVariableOptions,
|
|
15
|
+
type VariableOption,
|
|
16
|
+
} from '@nocobase/plugin-workflow/client-v2';
|
|
17
|
+
import React from 'react';
|
|
18
|
+
import { DEFAULT_TIMEOUT_MS, INSTRUCTION_GROUP_KEY, INSTRUCTION_TYPES } from '../shared/constants';
|
|
19
|
+
import type { PortainerStackControlConfig, PortainerStackRedeployConfig } from '../shared/types';
|
|
20
|
+
import { tExpr } from './locale';
|
|
21
|
+
|
|
22
|
+
type NodeLike = {
|
|
23
|
+
key: string;
|
|
24
|
+
title: string;
|
|
25
|
+
};
|
|
26
|
+
|
|
27
|
+
function makeVarNode(
|
|
28
|
+
fieldNames: NonNullable<UseVariableOptions['fieldNames']>,
|
|
29
|
+
value: string,
|
|
30
|
+
label: string,
|
|
31
|
+
): VariableOption {
|
|
32
|
+
return {
|
|
33
|
+
[fieldNames.value ?? defaultFieldNames.value]: value,
|
|
34
|
+
[fieldNames.label ?? defaultFieldNames.label]: label,
|
|
35
|
+
};
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
export function buildRedeployVariableOption(
|
|
39
|
+
{ key, title }: NodeLike,
|
|
40
|
+
{ fieldNames = defaultFieldNames }: UseVariableOptions = {},
|
|
41
|
+
): VariableOption {
|
|
42
|
+
const childrenKey = fieldNames.children ?? defaultFieldNames.children;
|
|
43
|
+
return {
|
|
44
|
+
...makeVarNode(fieldNames, key, title),
|
|
45
|
+
[childrenKey]: [
|
|
46
|
+
makeVarNode(fieldNames, 'ok', tExpr('Succeeded')),
|
|
47
|
+
makeVarNode(fieldNames, 'stackId', tExpr('Stack ID')),
|
|
48
|
+
makeVarNode(fieldNames, 'stackName', tExpr('Stack name')),
|
|
49
|
+
makeVarNode(fieldNames, 'endpointId', tExpr('Environment (Endpoint) ID')),
|
|
50
|
+
makeVarNode(fieldNames, 'stackType', tExpr('Stack type')),
|
|
51
|
+
makeVarNode(fieldNames, 'stackStatus', tExpr('Stack status')),
|
|
52
|
+
makeVarNode(fieldNames, 'gitReference', tExpr('Git reference')),
|
|
53
|
+
makeVarNode(fieldNames, 'appliedEnv', tExpr('Applied environment (masked)')),
|
|
54
|
+
makeVarNode(fieldNames, 'appliedEnvCount', tExpr('Applied variable count')),
|
|
55
|
+
makeVarNode(fieldNames, 'healthy', tExpr('Containers healthy')),
|
|
56
|
+
makeVarNode(fieldNames, 'runningCount', tExpr('Running containers')),
|
|
57
|
+
makeVarNode(fieldNames, 'totalCount', tExpr('Total containers')),
|
|
58
|
+
makeVarNode(fieldNames, 'durationMs', tExpr('Duration (ms)')),
|
|
59
|
+
makeVarNode(fieldNames, 'startedAt', tExpr('Started at')),
|
|
60
|
+
makeVarNode(fieldNames, 'finishedAt', tExpr('Finished at')),
|
|
61
|
+
makeVarNode(fieldNames, 'errorMessage', tExpr('Error message')),
|
|
62
|
+
],
|
|
63
|
+
};
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
export function buildControlVariableOption(
|
|
67
|
+
{ key, title }: NodeLike,
|
|
68
|
+
{ fieldNames = defaultFieldNames }: UseVariableOptions = {},
|
|
69
|
+
): VariableOption {
|
|
70
|
+
const childrenKey = fieldNames.children ?? defaultFieldNames.children;
|
|
71
|
+
return {
|
|
72
|
+
...makeVarNode(fieldNames, key, title),
|
|
73
|
+
[childrenKey]: [
|
|
74
|
+
makeVarNode(fieldNames, 'ok', tExpr('Succeeded')),
|
|
75
|
+
makeVarNode(fieldNames, 'action', tExpr('Executed action')),
|
|
76
|
+
makeVarNode(fieldNames, 'stackId', tExpr('Stack ID')),
|
|
77
|
+
makeVarNode(fieldNames, 'stackName', tExpr('Stack name')),
|
|
78
|
+
makeVarNode(fieldNames, 'endpointId', tExpr('Environment (Endpoint) ID')),
|
|
79
|
+
makeVarNode(fieldNames, 'stackType', tExpr('Stack type')),
|
|
80
|
+
makeVarNode(fieldNames, 'stackStatus', tExpr('Stack status')),
|
|
81
|
+
makeVarNode(fieldNames, 'gitReference', tExpr('Git reference')),
|
|
82
|
+
makeVarNode(fieldNames, 'healthy', tExpr('Stack healthy')),
|
|
83
|
+
makeVarNode(fieldNames, 'runningCount', tExpr('Running containers')),
|
|
84
|
+
makeVarNode(fieldNames, 'totalCount', tExpr('Total containers')),
|
|
85
|
+
makeVarNode(fieldNames, 'currentEnv', tExpr('Current environment (masked)')),
|
|
86
|
+
makeVarNode(fieldNames, 'durationMs', tExpr('Duration (ms)')),
|
|
87
|
+
makeVarNode(fieldNames, 'errorMessage', tExpr('Error message')),
|
|
88
|
+
],
|
|
89
|
+
};
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
export function defaultRedeployConfig(): PortainerStackRedeployConfig {
|
|
93
|
+
return {
|
|
94
|
+
mode: 'stack',
|
|
95
|
+
envStrategy: 'merge',
|
|
96
|
+
repullImage: false,
|
|
97
|
+
prune: false,
|
|
98
|
+
envPairs: [],
|
|
99
|
+
timeoutMs: DEFAULT_TIMEOUT_MS,
|
|
100
|
+
ignoreFail: false,
|
|
101
|
+
};
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
export function defaultControlConfig(): PortainerStackControlConfig {
|
|
105
|
+
return {
|
|
106
|
+
action: 'inspect',
|
|
107
|
+
ignoreFail: false,
|
|
108
|
+
};
|
|
109
|
+
}
|
|
110
|
+
|
|
111
|
+
export class PortainerStackRedeployInstructionV2 extends Instruction {
|
|
112
|
+
type = INSTRUCTION_TYPES.redeploy;
|
|
113
|
+
title = tExpr('Run / Redeploy Stack');
|
|
114
|
+
description = tExpr(
|
|
115
|
+
'Pull Git changes, build compose services, or redeploy a Portainer Stack with full environment variable control.',
|
|
116
|
+
);
|
|
117
|
+
group = INSTRUCTION_GROUP_KEY;
|
|
118
|
+
icon = (<CloudUploadOutlined />);
|
|
119
|
+
testable = true;
|
|
120
|
+
FieldsetLoader = () =>
|
|
121
|
+
import('./components/RedeployFieldset').then((module) => ({ default: module.RedeployFieldset }));
|
|
122
|
+
|
|
123
|
+
createDefaultConfig(): PortainerStackRedeployConfig {
|
|
124
|
+
return defaultRedeployConfig();
|
|
125
|
+
}
|
|
126
|
+
|
|
127
|
+
useVariables(node: NodeLike, options?: UseVariableOptions) {
|
|
128
|
+
return buildRedeployVariableOption(node, options);
|
|
129
|
+
}
|
|
130
|
+
}
|
|
131
|
+
|
|
132
|
+
export class PortainerStackControlInstructionV2 extends Instruction {
|
|
133
|
+
type = INSTRUCTION_TYPES.control;
|
|
134
|
+
title = tExpr('Control / Inspect Stack');
|
|
135
|
+
description = tExpr('Inspect Stack container health, start, or stop a Portainer Stack in an environment.');
|
|
136
|
+
group = INSTRUCTION_GROUP_KEY;
|
|
137
|
+
icon = (<ClusterOutlined />);
|
|
138
|
+
testable = true;
|
|
139
|
+
FieldsetLoader = () => import('./components/ControlFieldset').then((module) => ({ default: module.ControlFieldset }));
|
|
140
|
+
|
|
141
|
+
createDefaultConfig(): PortainerStackControlConfig {
|
|
142
|
+
return defaultControlConfig();
|
|
143
|
+
}
|
|
144
|
+
|
|
145
|
+
useVariables(node: NodeLike, options?: UseVariableOptions) {
|
|
146
|
+
return buildControlVariableOption(node, options);
|
|
147
|
+
}
|
|
148
|
+
}
|
|
149
|
+
|
|
150
|
+
export type WorkflowInstructionRegistryLike<TBase> = {
|
|
151
|
+
registerInstructionGroup?: (key: string, group: { key: string; label: string }) => void;
|
|
152
|
+
registerInstruction?: (type: string, instruction: TBase | { new (): TBase }) => void;
|
|
153
|
+
};
|
|
154
|
+
|
|
155
|
+
export function registerInstructionsV2(workflow: WorkflowInstructionRegistryLike<Instruction>) {
|
|
156
|
+
workflow.registerInstructionGroup?.(INSTRUCTION_GROUP_KEY, {
|
|
157
|
+
key: INSTRUCTION_GROUP_KEY,
|
|
158
|
+
label: tExpr('Portainer'),
|
|
159
|
+
});
|
|
160
|
+
workflow.registerInstruction?.(INSTRUCTION_TYPES.redeploy, PortainerStackRedeployInstructionV2);
|
|
161
|
+
workflow.registerInstruction?.(INSTRUCTION_TYPES.control, PortainerStackControlInstructionV2);
|
|
162
|
+
}
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* This file is part of the NocoBase (R) project.
|
|
3
|
+
* Copyright (c) 2020-2024 NocoBase Co., Ltd.
|
|
4
|
+
* Authors: NocoBase Team.
|
|
5
|
+
*
|
|
6
|
+
* This project is dual-licensed under AGPL-3.0 and NocoBase Commercial License.
|
|
7
|
+
* For more information, please refer to: https://www.nocobase.com/agreement.
|
|
8
|
+
*/
|
|
9
|
+
|
|
10
|
+
import { useApp } from '@nocobase/client-v2';
|
|
11
|
+
import { useCallback } from 'react';
|
|
12
|
+
import { PLUGIN_NAMESPACE } from '../shared/constants';
|
|
13
|
+
|
|
14
|
+
export const namespace = PLUGIN_NAMESPACE;
|
|
15
|
+
export const tExpr = (key: string) => `{{t("${key}", { ns: "${namespace}" })}}`;
|
|
16
|
+
|
|
17
|
+
export function useT() {
|
|
18
|
+
const app = useApp();
|
|
19
|
+
return useCallback(
|
|
20
|
+
(key: string, options?: Record<string, unknown>) =>
|
|
21
|
+
app.i18n.t(key, { ns: [namespace, 'client'], ...options }) as string,
|
|
22
|
+
[app.i18n],
|
|
23
|
+
);
|
|
24
|
+
}
|
package/src/index.ts
ADDED
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* This file is part of the NocoBase (R) project.
|
|
3
|
+
* Copyright (c) 2020-2024 NocoBase Co., Ltd.
|
|
4
|
+
* Authors: NocoBase Team.
|
|
5
|
+
*
|
|
6
|
+
* This project is dual-licensed under AGPL-3.0 and NocoBase Commercial License.
|
|
7
|
+
* For more information, please refer to: https://www.nocobase.com/agreement.
|
|
8
|
+
*/
|
|
9
|
+
|
|
10
|
+
export { default } from './server';
|
|
11
|
+
export * from './server';
|