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,707 @@
|
|
|
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 {
|
|
11
|
+
ApiOutlined,
|
|
12
|
+
AppstoreOutlined,
|
|
13
|
+
CheckCircleOutlined,
|
|
14
|
+
DeleteOutlined,
|
|
15
|
+
EditOutlined,
|
|
16
|
+
EyeOutlined,
|
|
17
|
+
PlusOutlined,
|
|
18
|
+
ReloadOutlined,
|
|
19
|
+
} from '@ant-design/icons';
|
|
20
|
+
import { useApp } from '@nocobase/client-v2';
|
|
21
|
+
import {
|
|
22
|
+
Alert,
|
|
23
|
+
Button,
|
|
24
|
+
Card,
|
|
25
|
+
Checkbox,
|
|
26
|
+
Collapse,
|
|
27
|
+
Drawer,
|
|
28
|
+
Flex,
|
|
29
|
+
Form,
|
|
30
|
+
Input,
|
|
31
|
+
InputNumber,
|
|
32
|
+
Modal,
|
|
33
|
+
Popconfirm,
|
|
34
|
+
Select,
|
|
35
|
+
Space,
|
|
36
|
+
Switch,
|
|
37
|
+
Table,
|
|
38
|
+
Tag,
|
|
39
|
+
Typography,
|
|
40
|
+
message,
|
|
41
|
+
} from 'antd';
|
|
42
|
+
import type { ColumnsType } from 'antd/es/table';
|
|
43
|
+
import React, { useCallback, useEffect, useState } from 'react';
|
|
44
|
+
import {
|
|
45
|
+
DEFAULT_TIMEOUT_MS,
|
|
46
|
+
MAX_TIMEOUT_MS,
|
|
47
|
+
MIN_TIMEOUT_MS,
|
|
48
|
+
PORTAINER_INSTANCES_COLLECTION,
|
|
49
|
+
PORTAINER_RESOURCE,
|
|
50
|
+
SECRET_MASK,
|
|
51
|
+
} from '../../shared/constants';
|
|
52
|
+
import type { PortainerEndpointSummary, PortainerInstanceSummary, PortainerStackSummary } from '../../shared/types';
|
|
53
|
+
import { useT } from '../locale';
|
|
54
|
+
import { StackDetailDrawer } from './StackDetailDrawer';
|
|
55
|
+
|
|
56
|
+
interface InstanceFormValues {
|
|
57
|
+
name: string;
|
|
58
|
+
baseUrl: string;
|
|
59
|
+
apiKey?: string;
|
|
60
|
+
gitCredentialId?: number | null;
|
|
61
|
+
gitUsername?: string;
|
|
62
|
+
gitAccessToken?: string;
|
|
63
|
+
allowInsecureTls?: boolean;
|
|
64
|
+
defaultTimeoutMs?: number;
|
|
65
|
+
isDefault?: boolean;
|
|
66
|
+
enabled?: boolean;
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
export function PortainerSettingsPage() {
|
|
70
|
+
const t = useT();
|
|
71
|
+
const api = useApp().apiClient;
|
|
72
|
+
const [form] = Form.useForm<InstanceFormValues>();
|
|
73
|
+
|
|
74
|
+
const [instances, setInstances] = useState<PortainerInstanceSummary[]>([]);
|
|
75
|
+
const [loading, setLoading] = useState(false);
|
|
76
|
+
const [modalOpen, setModalOpen] = useState(false);
|
|
77
|
+
const [editing, setEditing] = useState<PortainerInstanceSummary | null>(null);
|
|
78
|
+
const [saving, setSaving] = useState(false);
|
|
79
|
+
const [testingDraft, setTestingDraft] = useState(false);
|
|
80
|
+
const [testingId, setTestingId] = useState<number | null>(null);
|
|
81
|
+
|
|
82
|
+
const [explorerInstance, setExplorerInstance] = useState<PortainerInstanceSummary | null>(null);
|
|
83
|
+
const [endpoints, setEndpoints] = useState<PortainerEndpointSummary[]>([]);
|
|
84
|
+
const [selectedEndpointId, setSelectedEndpointId] = useState<number | undefined>(undefined);
|
|
85
|
+
const [stacks, setStacks] = useState<PortainerStackSummary[]>([]);
|
|
86
|
+
const [loadingStacks, setLoadingStacks] = useState(false);
|
|
87
|
+
const [selectedStack, setSelectedStack] = useState<PortainerStackSummary | null>(null);
|
|
88
|
+
|
|
89
|
+
const loadInstances = useCallback(async () => {
|
|
90
|
+
setLoading(true);
|
|
91
|
+
try {
|
|
92
|
+
const res = await api.request<{ data?: PortainerInstanceSummary[] }>({
|
|
93
|
+
url: `${PORTAINER_INSTANCES_COLLECTION}:list`,
|
|
94
|
+
method: 'get',
|
|
95
|
+
params: {
|
|
96
|
+
pageSize: 100,
|
|
97
|
+
sort: ['-isDefault', 'id'],
|
|
98
|
+
},
|
|
99
|
+
});
|
|
100
|
+
setInstances(Array.isArray(res?.data?.data) ? res.data.data : []);
|
|
101
|
+
} catch {
|
|
102
|
+
message.error(t('Failed to load Portainer instances'));
|
|
103
|
+
} finally {
|
|
104
|
+
setLoading(false);
|
|
105
|
+
}
|
|
106
|
+
}, [api, t]);
|
|
107
|
+
|
|
108
|
+
useEffect(() => {
|
|
109
|
+
loadInstances();
|
|
110
|
+
}, [loadInstances]);
|
|
111
|
+
|
|
112
|
+
const openCreateModal = () => {
|
|
113
|
+
setEditing(null);
|
|
114
|
+
form.resetFields();
|
|
115
|
+
form.setFieldsValue({
|
|
116
|
+
defaultTimeoutMs: DEFAULT_TIMEOUT_MS,
|
|
117
|
+
allowInsecureTls: false,
|
|
118
|
+
isDefault: instances.length === 0,
|
|
119
|
+
enabled: true,
|
|
120
|
+
});
|
|
121
|
+
setModalOpen(true);
|
|
122
|
+
};
|
|
123
|
+
|
|
124
|
+
const openEditModal = (record: PortainerInstanceSummary) => {
|
|
125
|
+
setEditing(record);
|
|
126
|
+
form.setFieldsValue({
|
|
127
|
+
name: record.name,
|
|
128
|
+
baseUrl: record.baseUrl,
|
|
129
|
+
apiKey: record.apiKey || SECRET_MASK,
|
|
130
|
+
gitCredentialId: record.gitCredentialId ?? undefined,
|
|
131
|
+
gitUsername: record.gitUsername ?? '',
|
|
132
|
+
gitAccessToken: record.gitAccessToken || '',
|
|
133
|
+
allowInsecureTls: Boolean(record.allowInsecureTls),
|
|
134
|
+
defaultTimeoutMs: record.defaultTimeoutMs ?? DEFAULT_TIMEOUT_MS,
|
|
135
|
+
isDefault: Boolean(record.isDefault),
|
|
136
|
+
enabled: record.enabled !== false,
|
|
137
|
+
});
|
|
138
|
+
setModalOpen(true);
|
|
139
|
+
};
|
|
140
|
+
|
|
141
|
+
const handleSave = async () => {
|
|
142
|
+
let values: InstanceFormValues;
|
|
143
|
+
try {
|
|
144
|
+
values = await form.validateFields();
|
|
145
|
+
} catch {
|
|
146
|
+
return;
|
|
147
|
+
}
|
|
148
|
+
setSaving(true);
|
|
149
|
+
try {
|
|
150
|
+
if (editing) {
|
|
151
|
+
await api.request({
|
|
152
|
+
url: `${PORTAINER_INSTANCES_COLLECTION}:update`,
|
|
153
|
+
method: 'post',
|
|
154
|
+
params: { filterByTk: editing.id },
|
|
155
|
+
data: values,
|
|
156
|
+
});
|
|
157
|
+
message.success(t('Portainer instance updated'));
|
|
158
|
+
} else {
|
|
159
|
+
await api.request({
|
|
160
|
+
url: `${PORTAINER_INSTANCES_COLLECTION}:create`,
|
|
161
|
+
method: 'post',
|
|
162
|
+
data: values,
|
|
163
|
+
});
|
|
164
|
+
message.success(t('Portainer instance created'));
|
|
165
|
+
}
|
|
166
|
+
setModalOpen(false);
|
|
167
|
+
await loadInstances();
|
|
168
|
+
} catch (err) {
|
|
169
|
+
const msg = err instanceof Error ? err.message : t('Failed to save Portainer instance');
|
|
170
|
+
message.error(msg);
|
|
171
|
+
} finally {
|
|
172
|
+
setSaving(false);
|
|
173
|
+
}
|
|
174
|
+
};
|
|
175
|
+
|
|
176
|
+
const handleTestDraft = async () => {
|
|
177
|
+
const values = form.getFieldsValue();
|
|
178
|
+
if (!values.baseUrl) {
|
|
179
|
+
message.warning(t('Please enter a Portainer base URL first'));
|
|
180
|
+
return;
|
|
181
|
+
}
|
|
182
|
+
setTestingDraft(true);
|
|
183
|
+
try {
|
|
184
|
+
const res = await api.request<{ data?: { version?: string; endpointCount?: number } }>({
|
|
185
|
+
url: `${PORTAINER_RESOURCE}:testConnectionDraft`,
|
|
186
|
+
method: 'post',
|
|
187
|
+
data: {
|
|
188
|
+
...values,
|
|
189
|
+
id: editing?.id,
|
|
190
|
+
},
|
|
191
|
+
});
|
|
192
|
+
const info = res?.data?.data;
|
|
193
|
+
message.success(
|
|
194
|
+
t('Connected to Portainer v{{version}} ({{count}} environments found)', {
|
|
195
|
+
version: info?.version ?? 'unknown',
|
|
196
|
+
count: info?.endpointCount ?? 0,
|
|
197
|
+
}),
|
|
198
|
+
);
|
|
199
|
+
} catch {
|
|
200
|
+
message.error(t('Connection test failed. Check URL, API key, and TLS settings.'));
|
|
201
|
+
} finally {
|
|
202
|
+
setTestingDraft(false);
|
|
203
|
+
}
|
|
204
|
+
};
|
|
205
|
+
|
|
206
|
+
const handleTestSaved = async (record: PortainerInstanceSummary) => {
|
|
207
|
+
setTestingId(record.id);
|
|
208
|
+
try {
|
|
209
|
+
const res = await api.request<{ data?: { version?: string; endpointCount?: number } }>({
|
|
210
|
+
url: `${PORTAINER_RESOURCE}:testConnection`,
|
|
211
|
+
method: 'post',
|
|
212
|
+
params: { filterByTk: record.id },
|
|
213
|
+
});
|
|
214
|
+
const info = res?.data?.data;
|
|
215
|
+
message.success(
|
|
216
|
+
t('Connected to Portainer v{{version}} ({{count}} environments found)', {
|
|
217
|
+
version: info?.version ?? 'unknown',
|
|
218
|
+
count: info?.endpointCount ?? 0,
|
|
219
|
+
}),
|
|
220
|
+
);
|
|
221
|
+
await loadInstances();
|
|
222
|
+
} catch {
|
|
223
|
+
message.error(t('Connection test failed'));
|
|
224
|
+
await loadInstances();
|
|
225
|
+
} finally {
|
|
226
|
+
setTestingId(null);
|
|
227
|
+
}
|
|
228
|
+
};
|
|
229
|
+
|
|
230
|
+
const handleToggleEnabled = async (record: PortainerInstanceSummary, enabled: boolean) => {
|
|
231
|
+
try {
|
|
232
|
+
await api.request({
|
|
233
|
+
url: `${PORTAINER_INSTANCES_COLLECTION}:update`,
|
|
234
|
+
method: 'post',
|
|
235
|
+
params: { filterByTk: record.id },
|
|
236
|
+
data: { enabled },
|
|
237
|
+
});
|
|
238
|
+
await loadInstances();
|
|
239
|
+
} catch {
|
|
240
|
+
message.error(t('Failed to update status'));
|
|
241
|
+
}
|
|
242
|
+
};
|
|
243
|
+
|
|
244
|
+
const handleDelete = async (record: PortainerInstanceSummary) => {
|
|
245
|
+
try {
|
|
246
|
+
await api.request({
|
|
247
|
+
url: `${PORTAINER_INSTANCES_COLLECTION}:destroy`,
|
|
248
|
+
method: 'post',
|
|
249
|
+
params: { filterByTk: record.id },
|
|
250
|
+
});
|
|
251
|
+
message.success(t('Portainer instance deleted'));
|
|
252
|
+
await loadInstances();
|
|
253
|
+
} catch {
|
|
254
|
+
message.error(t('Failed to delete Portainer instance'));
|
|
255
|
+
}
|
|
256
|
+
};
|
|
257
|
+
|
|
258
|
+
const loadExplorerData = useCallback(
|
|
259
|
+
async (instanceId: number, endpointId?: number) => {
|
|
260
|
+
setLoadingStacks(true);
|
|
261
|
+
try {
|
|
262
|
+
const [epRes, stRes] = await Promise.all([
|
|
263
|
+
api.request<{ data?: PortainerEndpointSummary[] }>({
|
|
264
|
+
url: `${PORTAINER_RESOURCE}:listEndpoints`,
|
|
265
|
+
method: 'get',
|
|
266
|
+
params: { instanceId },
|
|
267
|
+
}),
|
|
268
|
+
api.request<{ data?: PortainerStackSummary[] }>({
|
|
269
|
+
url: `${PORTAINER_RESOURCE}:listStacks`,
|
|
270
|
+
method: 'get',
|
|
271
|
+
params: {
|
|
272
|
+
instanceId,
|
|
273
|
+
...(endpointId ? { endpointId } : {}),
|
|
274
|
+
},
|
|
275
|
+
}),
|
|
276
|
+
]);
|
|
277
|
+
setEndpoints(Array.isArray(epRes?.data?.data) ? epRes.data.data : []);
|
|
278
|
+
setStacks(Array.isArray(stRes?.data?.data) ? stRes.data.data : []);
|
|
279
|
+
} catch {
|
|
280
|
+
message.error(t('Failed to load environments and stacks from Portainer'));
|
|
281
|
+
} finally {
|
|
282
|
+
setLoadingStacks(false);
|
|
283
|
+
}
|
|
284
|
+
},
|
|
285
|
+
[api, t],
|
|
286
|
+
);
|
|
287
|
+
|
|
288
|
+
const openExplorer = (record: PortainerInstanceSummary) => {
|
|
289
|
+
setExplorerInstance(record);
|
|
290
|
+
setSelectedStack(null);
|
|
291
|
+
setSelectedEndpointId(undefined);
|
|
292
|
+
loadExplorerData(record.id, undefined);
|
|
293
|
+
};
|
|
294
|
+
|
|
295
|
+
const columns: ColumnsType<PortainerInstanceSummary> = [
|
|
296
|
+
{
|
|
297
|
+
title: t('Name'),
|
|
298
|
+
dataIndex: 'name',
|
|
299
|
+
key: 'name',
|
|
300
|
+
render: (name: string, record) => (
|
|
301
|
+
<Space>
|
|
302
|
+
<Typography.Text strong>{name}</Typography.Text>
|
|
303
|
+
{record.isDefault ? <Tag color="blue">{t('Default')}</Tag> : null}
|
|
304
|
+
</Space>
|
|
305
|
+
),
|
|
306
|
+
},
|
|
307
|
+
{
|
|
308
|
+
title: t('Base URL'),
|
|
309
|
+
dataIndex: 'baseUrl',
|
|
310
|
+
key: 'baseUrl',
|
|
311
|
+
render: (url: string) => <Typography.Text code>{url}</Typography.Text>,
|
|
312
|
+
},
|
|
313
|
+
{
|
|
314
|
+
title: t('Health & Version'),
|
|
315
|
+
key: 'health',
|
|
316
|
+
render: (_, record) => {
|
|
317
|
+
if (!record.lastHealthStatus) {
|
|
318
|
+
return <Tag>{t('Not tested')}</Tag>;
|
|
319
|
+
}
|
|
320
|
+
return record.lastHealthStatus === 'ok' ? (
|
|
321
|
+
<Space size="small">
|
|
322
|
+
<Tag color="success" icon={<CheckCircleOutlined />}>
|
|
323
|
+
{t('Connected')}
|
|
324
|
+
</Tag>
|
|
325
|
+
{record.lastVersion ? <Typography.Text type="secondary">v{record.lastVersion}</Typography.Text> : null}
|
|
326
|
+
</Space>
|
|
327
|
+
) : (
|
|
328
|
+
<Tag color="error">{t('Unreachable')}</Tag>
|
|
329
|
+
);
|
|
330
|
+
},
|
|
331
|
+
},
|
|
332
|
+
{
|
|
333
|
+
title: t('Enabled'),
|
|
334
|
+
dataIndex: 'enabled',
|
|
335
|
+
key: 'enabled',
|
|
336
|
+
width: 100,
|
|
337
|
+
render: (enabled: boolean, record) => (
|
|
338
|
+
<Switch
|
|
339
|
+
checked={enabled !== false}
|
|
340
|
+
aria-label={`${t('Toggle Portainer instance')} ${record.name}`}
|
|
341
|
+
onChange={(checked) => {
|
|
342
|
+
handleToggleEnabled(record, checked);
|
|
343
|
+
}}
|
|
344
|
+
/>
|
|
345
|
+
),
|
|
346
|
+
},
|
|
347
|
+
{
|
|
348
|
+
title: t('Actions'),
|
|
349
|
+
key: 'actions',
|
|
350
|
+
width: 300,
|
|
351
|
+
render: (_, record) => (
|
|
352
|
+
<Space size="small" wrap>
|
|
353
|
+
<Button
|
|
354
|
+
size="small"
|
|
355
|
+
htmlType="button"
|
|
356
|
+
icon={<ApiOutlined />}
|
|
357
|
+
loading={testingId === record.id}
|
|
358
|
+
aria-label={`${t('Test connection')} ${record.name}`}
|
|
359
|
+
onClick={() => {
|
|
360
|
+
handleTestSaved(record);
|
|
361
|
+
}}
|
|
362
|
+
>
|
|
363
|
+
{t('Test')}
|
|
364
|
+
</Button>
|
|
365
|
+
<Button
|
|
366
|
+
size="small"
|
|
367
|
+
htmlType="button"
|
|
368
|
+
icon={<AppstoreOutlined />}
|
|
369
|
+
aria-label={`${t('Browse Stacks')} ${record.name}`}
|
|
370
|
+
onClick={() => openExplorer(record)}
|
|
371
|
+
>
|
|
372
|
+
{t('Stacks')}
|
|
373
|
+
</Button>
|
|
374
|
+
<Button
|
|
375
|
+
size="small"
|
|
376
|
+
htmlType="button"
|
|
377
|
+
icon={<EditOutlined />}
|
|
378
|
+
aria-label={`${t('Edit Portainer instance')} ${record.name}`}
|
|
379
|
+
onClick={() => openEditModal(record)}
|
|
380
|
+
/>
|
|
381
|
+
<Popconfirm title={t('Delete this Portainer instance?')} onConfirm={() => handleDelete(record)}>
|
|
382
|
+
<Button
|
|
383
|
+
size="small"
|
|
384
|
+
danger
|
|
385
|
+
htmlType="button"
|
|
386
|
+
icon={<DeleteOutlined />}
|
|
387
|
+
aria-label={`${t('Delete Portainer instance')} ${record.name}`}
|
|
388
|
+
/>
|
|
389
|
+
</Popconfirm>
|
|
390
|
+
</Space>
|
|
391
|
+
),
|
|
392
|
+
},
|
|
393
|
+
];
|
|
394
|
+
|
|
395
|
+
const stackColumns: ColumnsType<PortainerStackSummary> = [
|
|
396
|
+
{
|
|
397
|
+
title: t('ID'),
|
|
398
|
+
dataIndex: 'id',
|
|
399
|
+
key: 'id',
|
|
400
|
+
width: 72,
|
|
401
|
+
},
|
|
402
|
+
{
|
|
403
|
+
title: t('Stack Name'),
|
|
404
|
+
dataIndex: 'name',
|
|
405
|
+
key: 'name',
|
|
406
|
+
render: (name: string) => <Typography.Text strong>{name}</Typography.Text>,
|
|
407
|
+
},
|
|
408
|
+
{
|
|
409
|
+
title: t('Endpoint'),
|
|
410
|
+
dataIndex: 'endpointId',
|
|
411
|
+
key: 'endpointId',
|
|
412
|
+
width: 130,
|
|
413
|
+
render: (epId: number) => {
|
|
414
|
+
const ep = endpoints.find((item) => item.id === epId);
|
|
415
|
+
return ep ? `${ep.name} (#${epId})` : `#${epId}`;
|
|
416
|
+
},
|
|
417
|
+
},
|
|
418
|
+
{
|
|
419
|
+
title: t('Source'),
|
|
420
|
+
key: 'source',
|
|
421
|
+
render: (_, st) => (
|
|
422
|
+
<Space size="small" wrap>
|
|
423
|
+
<Tag color={st.isGitStack ? 'processing' : 'purple'}>{st.isGitStack ? t('Git Stack') : t('Compose')}</Tag>
|
|
424
|
+
{st.gitReference ? <Typography.Text code>{st.gitReference}</Typography.Text> : null}
|
|
425
|
+
</Space>
|
|
426
|
+
),
|
|
427
|
+
},
|
|
428
|
+
{
|
|
429
|
+
title: t('Status'),
|
|
430
|
+
dataIndex: 'status',
|
|
431
|
+
key: 'status',
|
|
432
|
+
width: 110,
|
|
433
|
+
render: (status: number) => {
|
|
434
|
+
if (status === 3) {
|
|
435
|
+
return <Tag color="processing">{t('Deploying')}</Tag>;
|
|
436
|
+
}
|
|
437
|
+
if (status === 4) {
|
|
438
|
+
return <Tag color="error">{t('Error')}</Tag>;
|
|
439
|
+
}
|
|
440
|
+
return <Tag color={status === 1 ? 'success' : 'default'}>{status === 1 ? t('Active') : t('Inactive')}</Tag>;
|
|
441
|
+
},
|
|
442
|
+
},
|
|
443
|
+
{
|
|
444
|
+
title: t('Env Vars'),
|
|
445
|
+
dataIndex: 'envCount',
|
|
446
|
+
key: 'envCount',
|
|
447
|
+
width: 90,
|
|
448
|
+
},
|
|
449
|
+
{
|
|
450
|
+
title: t('Actions'),
|
|
451
|
+
key: 'actions',
|
|
452
|
+
width: 105,
|
|
453
|
+
render: (_, st) => (
|
|
454
|
+
<Button
|
|
455
|
+
size="small"
|
|
456
|
+
htmlType="button"
|
|
457
|
+
icon={<EyeOutlined />}
|
|
458
|
+
aria-label={`${t('Detail')} ${st.name}`}
|
|
459
|
+
onClick={() => setSelectedStack(st)}
|
|
460
|
+
>
|
|
461
|
+
{t('Detail')}
|
|
462
|
+
</Button>
|
|
463
|
+
),
|
|
464
|
+
},
|
|
465
|
+
];
|
|
466
|
+
|
|
467
|
+
return (
|
|
468
|
+
<Card
|
|
469
|
+
title={t('Portainer Instances')}
|
|
470
|
+
extra={
|
|
471
|
+
<Space>
|
|
472
|
+
<Button
|
|
473
|
+
htmlType="button"
|
|
474
|
+
icon={<ReloadOutlined />}
|
|
475
|
+
loading={loading}
|
|
476
|
+
onClick={() => {
|
|
477
|
+
loadInstances();
|
|
478
|
+
}}
|
|
479
|
+
>
|
|
480
|
+
{t('Refresh')}
|
|
481
|
+
</Button>
|
|
482
|
+
<Button type="primary" htmlType="button" icon={<PlusOutlined />} onClick={openCreateModal}>
|
|
483
|
+
{t('Add Portainer instance')}
|
|
484
|
+
</Button>
|
|
485
|
+
</Space>
|
|
486
|
+
}
|
|
487
|
+
>
|
|
488
|
+
<Alert
|
|
489
|
+
type="info"
|
|
490
|
+
showIcon
|
|
491
|
+
style={{ marginBottom: 16 }}
|
|
492
|
+
message={t(
|
|
493
|
+
'Configure Portainer servers with an Access Token (X-API-Key). Workflow nodes can select Environments and Stacks directly or receive dynamic IDs and Env variables from upstream build catalogs.',
|
|
494
|
+
)}
|
|
495
|
+
/>
|
|
496
|
+
|
|
497
|
+
<Table<PortainerInstanceSummary>
|
|
498
|
+
rowKey="id"
|
|
499
|
+
loading={loading}
|
|
500
|
+
dataSource={instances}
|
|
501
|
+
columns={columns}
|
|
502
|
+
pagination={false}
|
|
503
|
+
/>
|
|
504
|
+
|
|
505
|
+
<Modal
|
|
506
|
+
open={modalOpen}
|
|
507
|
+
title={editing ? t('Edit Portainer instance') : t('Add Portainer instance')}
|
|
508
|
+
onCancel={() => setModalOpen(false)}
|
|
509
|
+
destroyOnClose
|
|
510
|
+
width={620}
|
|
511
|
+
footer={
|
|
512
|
+
<Flex justify="space-between" align="center">
|
|
513
|
+
<Button
|
|
514
|
+
htmlType="button"
|
|
515
|
+
icon={<ApiOutlined />}
|
|
516
|
+
loading={testingDraft}
|
|
517
|
+
onClick={() => {
|
|
518
|
+
handleTestDraft();
|
|
519
|
+
}}
|
|
520
|
+
>
|
|
521
|
+
{t('Test connection')}
|
|
522
|
+
</Button>
|
|
523
|
+
<Space>
|
|
524
|
+
<Button htmlType="button" onClick={() => setModalOpen(false)}>
|
|
525
|
+
{t('Cancel')}
|
|
526
|
+
</Button>
|
|
527
|
+
<Button
|
|
528
|
+
type="primary"
|
|
529
|
+
htmlType="button"
|
|
530
|
+
loading={saving}
|
|
531
|
+
onClick={() => {
|
|
532
|
+
handleSave();
|
|
533
|
+
}}
|
|
534
|
+
>
|
|
535
|
+
{t('Save')}
|
|
536
|
+
</Button>
|
|
537
|
+
</Space>
|
|
538
|
+
</Flex>
|
|
539
|
+
}
|
|
540
|
+
>
|
|
541
|
+
<Form form={form} layout="vertical">
|
|
542
|
+
<Form.Item
|
|
543
|
+
name="name"
|
|
544
|
+
label={t('Instance name')}
|
|
545
|
+
rules={[{ required: true, message: t('Instance name is required') }]}
|
|
546
|
+
>
|
|
547
|
+
<Input placeholder="Portainer Production" />
|
|
548
|
+
</Form.Item>
|
|
549
|
+
|
|
550
|
+
<Form.Item
|
|
551
|
+
name="baseUrl"
|
|
552
|
+
label={t('Portainer base URL')}
|
|
553
|
+
rules={[{ required: true, message: t('Base URL is required') }]}
|
|
554
|
+
extra={t('Example: https://portainer.internal:9443')}
|
|
555
|
+
>
|
|
556
|
+
<Input
|
|
557
|
+
placeholder="https://portainer.example.com:9443"
|
|
558
|
+
autoCorrect="off"
|
|
559
|
+
autoCapitalize="none"
|
|
560
|
+
spellCheck={false}
|
|
561
|
+
/>
|
|
562
|
+
</Form.Item>
|
|
563
|
+
|
|
564
|
+
<Form.Item
|
|
565
|
+
name="apiKey"
|
|
566
|
+
label={t('Portainer API key (X-API-Key)')}
|
|
567
|
+
rules={[{ required: !editing, message: t('API key is required') }]}
|
|
568
|
+
extra={t('Generated under Portainer -> My account -> Access tokens. Encrypted at rest.')}
|
|
569
|
+
>
|
|
570
|
+
<Input.Password
|
|
571
|
+
placeholder="ptr_..."
|
|
572
|
+
autoComplete="new-password"
|
|
573
|
+
autoCorrect="off"
|
|
574
|
+
autoCapitalize="none"
|
|
575
|
+
spellCheck={false}
|
|
576
|
+
/>
|
|
577
|
+
</Form.Item>
|
|
578
|
+
|
|
579
|
+
<Flex gap="middle" wrap="wrap">
|
|
580
|
+
<Form.Item
|
|
581
|
+
name="defaultTimeoutMs"
|
|
582
|
+
label={t('Default build/redeploy timeout (ms)')}
|
|
583
|
+
style={{ flex: '1 1 240px' }}
|
|
584
|
+
>
|
|
585
|
+
<InputNumber min={MIN_TIMEOUT_MS} max={MAX_TIMEOUT_MS} step={5000} style={{ width: '100%' }} />
|
|
586
|
+
</Form.Item>
|
|
587
|
+
</Flex>
|
|
588
|
+
|
|
589
|
+
<Space size="large" wrap style={{ marginBottom: 16 }}>
|
|
590
|
+
<Form.Item name="isDefault" valuePropName="checked" style={{ marginBottom: 0 }}>
|
|
591
|
+
<Checkbox>{t('Set as default instance')}</Checkbox>
|
|
592
|
+
</Form.Item>
|
|
593
|
+
<Form.Item name="allowInsecureTls" valuePropName="checked" style={{ marginBottom: 0 }}>
|
|
594
|
+
<Checkbox>{t('Allow self-signed TLS certificate (:9443)')}</Checkbox>
|
|
595
|
+
</Form.Item>
|
|
596
|
+
<Form.Item name="enabled" valuePropName="checked" style={{ marginBottom: 0 }}>
|
|
597
|
+
<Checkbox>{t('Enabled')}</Checkbox>
|
|
598
|
+
</Form.Item>
|
|
599
|
+
</Space>
|
|
600
|
+
|
|
601
|
+
<Collapse
|
|
602
|
+
size="small"
|
|
603
|
+
items={[
|
|
604
|
+
{
|
|
605
|
+
key: 'git-fallback',
|
|
606
|
+
label: t('Optional Git authentication fallback (when Stack has no saved GitCredentialID)'),
|
|
607
|
+
children: (
|
|
608
|
+
<>
|
|
609
|
+
<Form.Item
|
|
610
|
+
name="gitCredentialId"
|
|
611
|
+
label={t('Portainer saved Git Credential ID (optional)')}
|
|
612
|
+
extra={t(
|
|
613
|
+
'Automatically detected from each Git Stack when present; set here only to supply a default ID.',
|
|
614
|
+
)}
|
|
615
|
+
>
|
|
616
|
+
<InputNumber min={1} style={{ width: '100%' }} />
|
|
617
|
+
</Form.Item>
|
|
618
|
+
<Form.Item name="gitUsername" label={t('Fallback Git username (optional)')}>
|
|
619
|
+
<Input autoCorrect="off" autoCapitalize="none" spellCheck={false} placeholder="oauth2" />
|
|
620
|
+
</Form.Item>
|
|
621
|
+
<Form.Item
|
|
622
|
+
name="gitAccessToken"
|
|
623
|
+
label={t('Fallback Git Personal Access Token (optional)')}
|
|
624
|
+
style={{ marginBottom: 0 }}
|
|
625
|
+
>
|
|
626
|
+
<Input.Password
|
|
627
|
+
autoComplete="new-password"
|
|
628
|
+
autoCorrect="off"
|
|
629
|
+
autoCapitalize="none"
|
|
630
|
+
spellCheck={false}
|
|
631
|
+
/>
|
|
632
|
+
</Form.Item>
|
|
633
|
+
</>
|
|
634
|
+
),
|
|
635
|
+
},
|
|
636
|
+
]}
|
|
637
|
+
/>
|
|
638
|
+
</Form>
|
|
639
|
+
</Modal>
|
|
640
|
+
|
|
641
|
+
<Drawer
|
|
642
|
+
open={Boolean(explorerInstance)}
|
|
643
|
+
title={explorerInstance ? `${t('Portainer Stacks')} — ${explorerInstance.name}` : t('Portainer Stacks')}
|
|
644
|
+
onClose={() => {
|
|
645
|
+
setSelectedStack(null);
|
|
646
|
+
setExplorerInstance(null);
|
|
647
|
+
}}
|
|
648
|
+
width={820}
|
|
649
|
+
>
|
|
650
|
+
<Flex gap="small" align="center" style={{ marginBottom: 16 }}>
|
|
651
|
+
<Select
|
|
652
|
+
allowClear
|
|
653
|
+
style={{ width: 280 }}
|
|
654
|
+
placeholder={t('All environments (Endpoints)')}
|
|
655
|
+
value={selectedEndpointId}
|
|
656
|
+
options={endpoints.map((ep) => ({
|
|
657
|
+
value: ep.id,
|
|
658
|
+
label: `${ep.name} (#${ep.id})`,
|
|
659
|
+
}))}
|
|
660
|
+
onChange={(epId) => {
|
|
661
|
+
setSelectedEndpointId(epId);
|
|
662
|
+
if (explorerInstance) {
|
|
663
|
+
loadExplorerData(explorerInstance.id, epId);
|
|
664
|
+
}
|
|
665
|
+
}}
|
|
666
|
+
/>
|
|
667
|
+
<Button
|
|
668
|
+
htmlType="button"
|
|
669
|
+
icon={<ReloadOutlined />}
|
|
670
|
+
loading={loadingStacks}
|
|
671
|
+
onClick={() => {
|
|
672
|
+
if (explorerInstance) {
|
|
673
|
+
loadExplorerData(explorerInstance.id, selectedEndpointId);
|
|
674
|
+
}
|
|
675
|
+
}}
|
|
676
|
+
>
|
|
677
|
+
{t('Refresh')}
|
|
678
|
+
</Button>
|
|
679
|
+
</Flex>
|
|
680
|
+
|
|
681
|
+
<Table<PortainerStackSummary>
|
|
682
|
+
rowKey="id"
|
|
683
|
+
size="small"
|
|
684
|
+
loading={loadingStacks}
|
|
685
|
+
dataSource={stacks}
|
|
686
|
+
columns={stackColumns}
|
|
687
|
+
pagination={{ pageSize: 15 }}
|
|
688
|
+
/>
|
|
689
|
+
|
|
690
|
+
<StackDetailDrawer
|
|
691
|
+
open={Boolean(selectedStack)}
|
|
692
|
+
instance={explorerInstance}
|
|
693
|
+
stack={selectedStack}
|
|
694
|
+
endpoints={endpoints}
|
|
695
|
+
onClose={() => setSelectedStack(null)}
|
|
696
|
+
onStackChanged={() => {
|
|
697
|
+
if (explorerInstance) {
|
|
698
|
+
loadExplorerData(explorerInstance.id, selectedEndpointId);
|
|
699
|
+
}
|
|
700
|
+
}}
|
|
701
|
+
/>
|
|
702
|
+
</Drawer>
|
|
703
|
+
</Card>
|
|
704
|
+
);
|
|
705
|
+
}
|
|
706
|
+
|
|
707
|
+
export default PortainerSettingsPage;
|