plugin-workflow-portainer 0.0.0-stage → 0.2.0
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.09e6675863ac8138.js +10 -0
- package/dist/client/57.67f04a547ead06b8.js +10 -0
- package/dist/client/660.546c702d1ddf7eff.js +10 -0
- package/dist/client/981.e38099c59bf992f0.js +10 -0
- package/dist/client/index.js +10 -0
- package/dist/client-v2/127.9f65dc2e3d0df10a.js +10 -0
- package/dist/client-v2/57.a60e16e4b4e4fa28.js +10 -0
- package/dist/client-v2/660.29ae3c3b4040039d.js +10 -0
- package/dist/client-v2/981.8627062881ad83d1.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 +193 -0
- package/dist/locale/vi-VN.json +193 -0
- package/dist/locale/zh-CN.json +193 -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 +317 -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 +177 -0
- package/dist/server/services/PortainerClient.js +669 -0
- package/dist/shared/collection.js +57 -0
- package/dist/shared/constants.js +66 -0
- package/dist/shared/env.js +238 -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 +242 -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 +707 -0
- package/src/client-v2/components/PortainerTargetFields.tsx +309 -0
- package/src/client-v2/components/RedeployFieldset.tsx +124 -0
- package/src/client-v2/components/StackDetailDrawer.tsx +790 -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 +193 -0
- package/src/locale/vi-VN.json +193 -0
- package/src/locale/zh-CN.json +193 -0
- package/src/server/__tests__/portainer-workflow.test.ts +559 -0
- package/src/server/actions/portainer.ts +361 -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 +174 -0
- package/src/server/services/PortainerClient.ts +846 -0
- package/src/shared/collection.ts +32 -0
- package/src/shared/constants.ts +25 -0
- package/src/shared/env.ts +243 -0
- package/src/shared/types.ts +164 -0
|
@@ -0,0 +1,309 @@
|
|
|
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 { 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 { isWorkflowVariableValue, toFiniteNumber } from '../../shared/env';
|
|
17
|
+
import type { PortainerEndpointSummary, PortainerInstanceSummary, PortainerStackSummary } from '../../shared/types';
|
|
18
|
+
import { useT } from '../locale';
|
|
19
|
+
|
|
20
|
+
export interface StaticStackContext {
|
|
21
|
+
instanceId?: number;
|
|
22
|
+
stack?: PortainerStackSummary;
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
export function PortainerInstanceField() {
|
|
26
|
+
const t = useT();
|
|
27
|
+
const api = useApp().apiClient;
|
|
28
|
+
const [instances, setInstances] = useState<PortainerInstanceSummary[]>([]);
|
|
29
|
+
const [loading, setLoading] = useState(false);
|
|
30
|
+
|
|
31
|
+
const loadInstances = useCallback(async () => {
|
|
32
|
+
setLoading(true);
|
|
33
|
+
try {
|
|
34
|
+
const res = await api.request<{ data?: PortainerInstanceSummary[] }>({
|
|
35
|
+
url: `${PORTAINER_RESOURCE}:listInstances`,
|
|
36
|
+
method: 'get',
|
|
37
|
+
});
|
|
38
|
+
setInstances(Array.isArray(res?.data?.data) ? res.data.data : []);
|
|
39
|
+
} catch {
|
|
40
|
+
setInstances([]);
|
|
41
|
+
} finally {
|
|
42
|
+
setLoading(false);
|
|
43
|
+
}
|
|
44
|
+
}, [api]);
|
|
45
|
+
|
|
46
|
+
useEffect(() => {
|
|
47
|
+
loadInstances();
|
|
48
|
+
}, [loadInstances]);
|
|
49
|
+
|
|
50
|
+
const options = useMemo(
|
|
51
|
+
() =>
|
|
52
|
+
instances.map((inst) => ({
|
|
53
|
+
value: inst.id,
|
|
54
|
+
label: inst.isDefault ? `${inst.name} (${t('Default')})` : inst.name,
|
|
55
|
+
})),
|
|
56
|
+
[instances, t],
|
|
57
|
+
);
|
|
58
|
+
|
|
59
|
+
return (
|
|
60
|
+
<Form.Item
|
|
61
|
+
name={['config', 'instanceId']}
|
|
62
|
+
label={t('Portainer instance')}
|
|
63
|
+
extra={t('Leave empty to use the default enabled Portainer instance, or bind a workflow variable.')}
|
|
64
|
+
>
|
|
65
|
+
<WorkflowVariableWrapper<number>
|
|
66
|
+
render={({ value, onChange }) => (
|
|
67
|
+
<Select
|
|
68
|
+
allowClear
|
|
69
|
+
loading={loading}
|
|
70
|
+
value={toFiniteNumber(value)}
|
|
71
|
+
onChange={(nextVal) => onChange?.(typeof nextVal === 'number' ? nextVal : null)}
|
|
72
|
+
options={options}
|
|
73
|
+
placeholder={t('Default Portainer instance')}
|
|
74
|
+
style={{ width: '100%' }}
|
|
75
|
+
/>
|
|
76
|
+
)}
|
|
77
|
+
/>
|
|
78
|
+
</Form.Item>
|
|
79
|
+
);
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
export function PortainerTargetFields({
|
|
83
|
+
onStackContextChange,
|
|
84
|
+
}: {
|
|
85
|
+
onStackContextChange?: (ctx: StaticStackContext) => void;
|
|
86
|
+
}) {
|
|
87
|
+
const t = useT();
|
|
88
|
+
const api = useApp().apiClient;
|
|
89
|
+
const form = Form.useFormInstance();
|
|
90
|
+
|
|
91
|
+
const watchedInstanceId = Form.useWatch(['config', 'instanceId'], form) as string | number | null | undefined;
|
|
92
|
+
const watchedEndpointId = Form.useWatch(['config', 'endpointId'], form) as string | number | null | undefined;
|
|
93
|
+
const watchedStackId = Form.useWatch(['config', 'stackId'], form) as string | number | null | undefined;
|
|
94
|
+
|
|
95
|
+
const instanceIsVar = isWorkflowVariableValue(watchedInstanceId);
|
|
96
|
+
const endpointIsVar = isWorkflowVariableValue(watchedEndpointId);
|
|
97
|
+
const stackIsVar = isWorkflowVariableValue(watchedStackId);
|
|
98
|
+
|
|
99
|
+
const numericInstanceId = toFiniteNumber(watchedInstanceId);
|
|
100
|
+
const numericEndpointId = toFiniteNumber(watchedEndpointId);
|
|
101
|
+
const numericStackId = toFiniteNumber(watchedStackId);
|
|
102
|
+
|
|
103
|
+
const [endpoints, setEndpoints] = useState<PortainerEndpointSummary[]>([]);
|
|
104
|
+
const [stacks, setStacks] = useState<PortainerStackSummary[]>([]);
|
|
105
|
+
const [loadingEndpoints, setLoadingEndpoints] = useState(false);
|
|
106
|
+
const [loadingStacks, setLoadingStacks] = useState(false);
|
|
107
|
+
|
|
108
|
+
const fetchEndpoints = useCallback(async () => {
|
|
109
|
+
if (instanceIsVar) {
|
|
110
|
+
setEndpoints([]);
|
|
111
|
+
return;
|
|
112
|
+
}
|
|
113
|
+
setLoadingEndpoints(true);
|
|
114
|
+
try {
|
|
115
|
+
const res = await api.request<{ data?: PortainerEndpointSummary[] }>({
|
|
116
|
+
url: `${PORTAINER_RESOURCE}:listEndpoints`,
|
|
117
|
+
method: 'get',
|
|
118
|
+
params: numericInstanceId ? { instanceId: numericInstanceId } : {},
|
|
119
|
+
});
|
|
120
|
+
setEndpoints(Array.isArray(res?.data?.data) ? res.data.data : []);
|
|
121
|
+
} catch {
|
|
122
|
+
setEndpoints([]);
|
|
123
|
+
} finally {
|
|
124
|
+
setLoadingEndpoints(false);
|
|
125
|
+
}
|
|
126
|
+
}, [api, instanceIsVar, numericInstanceId]);
|
|
127
|
+
|
|
128
|
+
const fetchStacks = useCallback(async () => {
|
|
129
|
+
if (instanceIsVar || endpointIsVar) {
|
|
130
|
+
setStacks([]);
|
|
131
|
+
return;
|
|
132
|
+
}
|
|
133
|
+
setLoadingStacks(true);
|
|
134
|
+
try {
|
|
135
|
+
const res = await api.request<{ data?: PortainerStackSummary[] }>({
|
|
136
|
+
url: `${PORTAINER_RESOURCE}:listStacks`,
|
|
137
|
+
method: 'get',
|
|
138
|
+
params: {
|
|
139
|
+
...(numericInstanceId ? { instanceId: numericInstanceId } : {}),
|
|
140
|
+
...(numericEndpointId ? { endpointId: numericEndpointId } : {}),
|
|
141
|
+
},
|
|
142
|
+
});
|
|
143
|
+
setStacks(Array.isArray(res?.data?.data) ? res.data.data : []);
|
|
144
|
+
} catch {
|
|
145
|
+
setStacks([]);
|
|
146
|
+
} finally {
|
|
147
|
+
setLoadingStacks(false);
|
|
148
|
+
}
|
|
149
|
+
}, [api, endpointIsVar, instanceIsVar, numericEndpointId, numericInstanceId]);
|
|
150
|
+
|
|
151
|
+
useEffect(() => {
|
|
152
|
+
fetchEndpoints();
|
|
153
|
+
}, [fetchEndpoints]);
|
|
154
|
+
|
|
155
|
+
useEffect(() => {
|
|
156
|
+
fetchStacks();
|
|
157
|
+
}, [fetchStacks]);
|
|
158
|
+
|
|
159
|
+
const selectedStack = useMemo(
|
|
160
|
+
() => (numericStackId ? stacks.find((item) => item.id === numericStackId) : undefined),
|
|
161
|
+
[numericStackId, stacks],
|
|
162
|
+
);
|
|
163
|
+
|
|
164
|
+
useEffect(() => {
|
|
165
|
+
onStackContextChange?.({
|
|
166
|
+
instanceId: instanceIsVar ? undefined : numericInstanceId,
|
|
167
|
+
stack: stackIsVar ? undefined : selectedStack,
|
|
168
|
+
});
|
|
169
|
+
}, [instanceIsVar, numericInstanceId, onStackContextChange, selectedStack, stackIsVar]);
|
|
170
|
+
|
|
171
|
+
const endpointOptions = useMemo(
|
|
172
|
+
() =>
|
|
173
|
+
endpoints.map((ep) => ({
|
|
174
|
+
value: ep.id,
|
|
175
|
+
searchLabel: `${ep.name} ${ep.id}`,
|
|
176
|
+
label: (
|
|
177
|
+
<Flex align="center" justify="space-between" gap="small">
|
|
178
|
+
<span>
|
|
179
|
+
{ep.name} (#{ep.id})
|
|
180
|
+
</span>
|
|
181
|
+
<Tag color={ep.status === 1 ? 'success' : 'default'} style={{ marginInlineEnd: 0 }}>
|
|
182
|
+
{ep.status === 1 ? t('Up') : t('Down')}
|
|
183
|
+
</Tag>
|
|
184
|
+
</Flex>
|
|
185
|
+
),
|
|
186
|
+
})),
|
|
187
|
+
[endpoints, t],
|
|
188
|
+
);
|
|
189
|
+
|
|
190
|
+
const stackOptions = useMemo(
|
|
191
|
+
() =>
|
|
192
|
+
stacks.map((st) => ({
|
|
193
|
+
value: st.id,
|
|
194
|
+
searchLabel: `${st.name} ${st.id} ${st.gitReference ?? ''}`,
|
|
195
|
+
label: (
|
|
196
|
+
<Flex align="center" justify="space-between" gap="small">
|
|
197
|
+
<span>
|
|
198
|
+
{st.name} (#{st.id})
|
|
199
|
+
</span>
|
|
200
|
+
<span>
|
|
201
|
+
<Tag color={st.isGitStack ? 'processing' : 'purple'}>{st.isGitStack ? t('Git Stack') : t('Compose')}</Tag>
|
|
202
|
+
{st.gitReference ? (
|
|
203
|
+
<Tag style={{ marginInlineEnd: 0 }}>{st.gitReference.replace(/^refs\/heads\//, '')}</Tag>
|
|
204
|
+
) : null}
|
|
205
|
+
</span>
|
|
206
|
+
</Flex>
|
|
207
|
+
),
|
|
208
|
+
})),
|
|
209
|
+
[stacks, t],
|
|
210
|
+
);
|
|
211
|
+
|
|
212
|
+
return (
|
|
213
|
+
<>
|
|
214
|
+
<PortainerInstanceField />
|
|
215
|
+
|
|
216
|
+
<Form.Item
|
|
217
|
+
name={['config', 'endpointId']}
|
|
218
|
+
label={t('Environment (Endpoint)')}
|
|
219
|
+
extra={t('Select a Portainer environment or bind a dynamic endpointId variable.')}
|
|
220
|
+
>
|
|
221
|
+
<WorkflowVariableWrapper<number>
|
|
222
|
+
render={({ value, onChange }) =>
|
|
223
|
+
instanceIsVar ? (
|
|
224
|
+
<InputNumber
|
|
225
|
+
min={1}
|
|
226
|
+
value={toFiniteNumber(value)}
|
|
227
|
+
onChange={(nextVal) => onChange?.(typeof nextVal === 'number' ? nextVal : null)}
|
|
228
|
+
placeholder={t('Endpoint ID (e.g. 1)')}
|
|
229
|
+
style={{ width: '100%' }}
|
|
230
|
+
/>
|
|
231
|
+
) : (
|
|
232
|
+
<Flex gap="small" style={{ width: '100%' }}>
|
|
233
|
+
<Select
|
|
234
|
+
allowClear
|
|
235
|
+
showSearch
|
|
236
|
+
optionFilterProp="searchLabel"
|
|
237
|
+
loading={loadingEndpoints}
|
|
238
|
+
value={toFiniteNumber(value)}
|
|
239
|
+
onChange={(nextVal) => onChange?.(typeof nextVal === 'number' ? nextVal : null)}
|
|
240
|
+
options={endpointOptions}
|
|
241
|
+
placeholder={t('Auto-resolve from Stack or select environment')}
|
|
242
|
+
style={{ flex: 1, minWidth: 0 }}
|
|
243
|
+
/>
|
|
244
|
+
<Button
|
|
245
|
+
htmlType="button"
|
|
246
|
+
aria-label={t('Refresh Portainer environments')}
|
|
247
|
+
icon={<ReloadOutlined />}
|
|
248
|
+
loading={loadingEndpoints}
|
|
249
|
+
onClick={() => {
|
|
250
|
+
fetchEndpoints();
|
|
251
|
+
fetchStacks();
|
|
252
|
+
}}
|
|
253
|
+
/>
|
|
254
|
+
</Flex>
|
|
255
|
+
)
|
|
256
|
+
}
|
|
257
|
+
/>
|
|
258
|
+
</Form.Item>
|
|
259
|
+
|
|
260
|
+
<Form.Item
|
|
261
|
+
name={['config', 'stackId']}
|
|
262
|
+
label={t('Target Stack')}
|
|
263
|
+
rules={[{ required: true, message: t('Please select a Stack or bind a Stack ID variable') }]}
|
|
264
|
+
extra={
|
|
265
|
+
selectedStack?.isGitStack
|
|
266
|
+
? `${t('Connected Git repository')}: ${selectedStack.gitRepoUrl ?? '-'} (${
|
|
267
|
+
selectedStack.gitReference ?? 'refs/heads/main'
|
|
268
|
+
})`
|
|
269
|
+
: t('Choose the Portainer Stack to control or bind a stackId variable from upstream data.')
|
|
270
|
+
}
|
|
271
|
+
>
|
|
272
|
+
<WorkflowVariableWrapper<number>
|
|
273
|
+
render={({ value, onChange }) =>
|
|
274
|
+
instanceIsVar || endpointIsVar ? (
|
|
275
|
+
<InputNumber
|
|
276
|
+
min={1}
|
|
277
|
+
value={toFiniteNumber(value)}
|
|
278
|
+
onChange={(nextVal) => onChange?.(typeof nextVal === 'number' ? nextVal : null)}
|
|
279
|
+
placeholder={t('Stack ID (e.g. 12)')}
|
|
280
|
+
style={{ width: '100%' }}
|
|
281
|
+
/>
|
|
282
|
+
) : (
|
|
283
|
+
<Select
|
|
284
|
+
allowClear
|
|
285
|
+
showSearch
|
|
286
|
+
optionFilterProp="searchLabel"
|
|
287
|
+
loading={loadingStacks}
|
|
288
|
+
value={toFiniteNumber(value)}
|
|
289
|
+
onChange={(nextVal) => {
|
|
290
|
+
const numVal = typeof nextVal === 'number' ? nextVal : null;
|
|
291
|
+
onChange?.(numVal);
|
|
292
|
+
if (numVal && !numericEndpointId) {
|
|
293
|
+
const matched = stacks.find((item) => item.id === numVal);
|
|
294
|
+
if (matched?.endpointId) {
|
|
295
|
+
form.setFieldValue(['config', 'endpointId'], matched.endpointId);
|
|
296
|
+
}
|
|
297
|
+
}
|
|
298
|
+
}}
|
|
299
|
+
options={stackOptions}
|
|
300
|
+
placeholder={t('Select Portainer Stack')}
|
|
301
|
+
style={{ width: '100%' }}
|
|
302
|
+
/>
|
|
303
|
+
)
|
|
304
|
+
}
|
|
305
|
+
/>
|
|
306
|
+
</Form.Item>
|
|
307
|
+
</>
|
|
308
|
+
);
|
|
309
|
+
}
|
|
@@ -0,0 +1,124 @@
|
|
|
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 { toFiniteNumber } from '../../shared/env';
|
|
15
|
+
import type { RedeployTargetMode } from '../../shared/types';
|
|
16
|
+
import { useT } from '../locale';
|
|
17
|
+
import { PortainerEnvEditor } from './PortainerEnvEditor';
|
|
18
|
+
import { PortainerInstanceField, PortainerTargetFields, type StaticStackContext } from './PortainerTargetFields';
|
|
19
|
+
|
|
20
|
+
export function RedeployFieldset() {
|
|
21
|
+
const t = useT();
|
|
22
|
+
const form = Form.useFormInstance();
|
|
23
|
+
const watchedMode = (Form.useWatch(['config', 'mode'], form) as RedeployTargetMode | undefined) ?? 'stack';
|
|
24
|
+
const [stackContext, setStackContext] = useState<StaticStackContext>({});
|
|
25
|
+
|
|
26
|
+
return (
|
|
27
|
+
<>
|
|
28
|
+
<Form.Item
|
|
29
|
+
name={['config', 'mode']}
|
|
30
|
+
label={t('Execution mode')}
|
|
31
|
+
initialValue="stack"
|
|
32
|
+
extra={t(
|
|
33
|
+
'Use Stack API to control Environment, Stack, Git branch, and full Env variables; use Stack Webhook when triggering an unauthenticated Portainer webhook UUID.',
|
|
34
|
+
)}
|
|
35
|
+
>
|
|
36
|
+
<Radio.Group
|
|
37
|
+
options={[
|
|
38
|
+
{ value: 'stack', label: t('Stack API (Git / Compose)') },
|
|
39
|
+
{ value: 'webhook', label: t('Stack Webhook') },
|
|
40
|
+
]}
|
|
41
|
+
/>
|
|
42
|
+
</Form.Item>
|
|
43
|
+
|
|
44
|
+
{watchedMode === 'webhook' ? (
|
|
45
|
+
<>
|
|
46
|
+
<PortainerInstanceField />
|
|
47
|
+
<Form.Item
|
|
48
|
+
name={['config', 'webhookId']}
|
|
49
|
+
label={t('Stack Webhook token')}
|
|
50
|
+
rules={[{ required: true, message: t('Webhook token is required') }]}
|
|
51
|
+
extra={t('The UUID at the end of /api/stacks/webhooks/<token>.')}
|
|
52
|
+
>
|
|
53
|
+
<WorkflowVariableInput placeholder="638e6967-ef77-4906-8af8-236800621360" />
|
|
54
|
+
</Form.Item>
|
|
55
|
+
<Form.Item
|
|
56
|
+
name={['config', 'webhookTag']}
|
|
57
|
+
label={t('Image tag override (optional)')}
|
|
58
|
+
extra={t('Appends ?tag=<value> when triggering a Portainer Stack webhook.')}
|
|
59
|
+
>
|
|
60
|
+
<WorkflowVariableInput placeholder="latest" />
|
|
61
|
+
</Form.Item>
|
|
62
|
+
</>
|
|
63
|
+
) : (
|
|
64
|
+
<>
|
|
65
|
+
<PortainerTargetFields onStackContextChange={setStackContext} />
|
|
66
|
+
|
|
67
|
+
<Form.Item
|
|
68
|
+
name={['config', 'gitReference']}
|
|
69
|
+
label={t('Git branch / tag override (optional)')}
|
|
70
|
+
extra={t(
|
|
71
|
+
'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.',
|
|
72
|
+
)}
|
|
73
|
+
>
|
|
74
|
+
<WorkflowVariableInput placeholder={stackContext.stack?.gitReference || 'refs/heads/main'} />
|
|
75
|
+
</Form.Item>
|
|
76
|
+
|
|
77
|
+
<Form.Item
|
|
78
|
+
name={['config', 'repullImage']}
|
|
79
|
+
valuePropName="checked"
|
|
80
|
+
initialValue={false}
|
|
81
|
+
extra={t(
|
|
82
|
+
'Enable when deploying a separate Stack so Portainer pulls the newly built image from your registry.',
|
|
83
|
+
)}
|
|
84
|
+
>
|
|
85
|
+
<Checkbox>{t('Force pull / repull latest images')}</Checkbox>
|
|
86
|
+
</Form.Item>
|
|
87
|
+
|
|
88
|
+
<Form.Item name={['config', 'prune']} valuePropName="checked" initialValue={false}>
|
|
89
|
+
<Checkbox>{t('Prune orphan services on redeploy')}</Checkbox>
|
|
90
|
+
</Form.Item>
|
|
91
|
+
|
|
92
|
+
<PortainerEnvEditor stackContext={stackContext} />
|
|
93
|
+
</>
|
|
94
|
+
)}
|
|
95
|
+
|
|
96
|
+
<Form.Item
|
|
97
|
+
name={['config', 'timeoutMs']}
|
|
98
|
+
label={t('Request timeout')}
|
|
99
|
+
initialValue={DEFAULT_TIMEOUT_MS}
|
|
100
|
+
extra={t('Increase timeout for Stacks that run long Dockerfile builds during git/redeploy.')}
|
|
101
|
+
>
|
|
102
|
+
<WorkflowVariableWrapper<number>
|
|
103
|
+
render={({ value, onChange }) => (
|
|
104
|
+
<InputNumber
|
|
105
|
+
min={MIN_TIMEOUT_MS}
|
|
106
|
+
max={MAX_TIMEOUT_MS}
|
|
107
|
+
step={5000}
|
|
108
|
+
addonAfter={t('ms')}
|
|
109
|
+
value={toFiniteNumber(value) ?? DEFAULT_TIMEOUT_MS}
|
|
110
|
+
onChange={(nextVal) => onChange?.(typeof nextVal === 'number' ? nextVal : null)}
|
|
111
|
+
style={{ width: '100%' }}
|
|
112
|
+
/>
|
|
113
|
+
)}
|
|
114
|
+
/>
|
|
115
|
+
</Form.Item>
|
|
116
|
+
|
|
117
|
+
<Form.Item name={['config', 'ignoreFail']} valuePropName="checked" initialValue={false}>
|
|
118
|
+
<Checkbox>{t('Ignore failed execution and continue workflow')}</Checkbox>
|
|
119
|
+
</Form.Item>
|
|
120
|
+
</>
|
|
121
|
+
);
|
|
122
|
+
}
|
|
123
|
+
|
|
124
|
+
export default RedeployFieldset;
|