plugin-workflow-portainer 0.1.1 → 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/dist/client/127.09e6675863ac8138.js +10 -0
- package/dist/client/57.67f04a547ead06b8.js +10 -0
- package/dist/client/981.e38099c59bf992f0.js +10 -0
- package/dist/client/index.js +1 -1
- package/dist/client-v2/127.9f65dc2e3d0df10a.js +10 -0
- package/dist/client-v2/57.a60e16e4b4e4fa28.js +10 -0
- package/dist/client-v2/981.8627062881ad83d1.js +10 -0
- package/dist/client-v2/index.js +1 -1
- package/dist/locale/en-US.json +43 -1
- package/dist/locale/vi-VN.json +43 -1
- package/dist/locale/zh-CN.json +43 -1
- package/dist/node_modules/joi/package.json +1 -1
- package/dist/server/actions/portainer.js +125 -0
- package/dist/server/plugin.js +8 -1
- package/dist/server/services/PortainerClient.js +177 -5
- package/dist/shared/env.js +19 -2
- package/package.json +2 -2
- package/src/client-v2/__tests__/workflow-registration.test.tsx +111 -1
- package/src/client-v2/components/PortainerSettingsPage.tsx +38 -2
- package/src/client-v2/components/PortainerTargetFields.tsx +10 -18
- package/src/client-v2/components/RedeployFieldset.tsx +2 -1
- package/src/client-v2/components/StackDetailDrawer.tsx +790 -0
- package/src/locale/en-US.json +43 -1
- package/src/locale/vi-VN.json +43 -1
- package/src/locale/zh-CN.json +43 -1
- package/src/server/__tests__/portainer-workflow.test.ts +105 -1
- package/src/server/actions/portainer.ts +167 -2
- package/src/server/plugin.ts +8 -1
- package/src/server/services/PortainerClient.ts +259 -2
- package/src/shared/env.ts +15 -0
- package/src/shared/types.ts +59 -0
- package/dist/client/127.5012da93825a6e5c.js +0 -10
- package/dist/client/57.ace9538136438718.js +0 -10
- package/dist/client/65.ec4a55173511c06d.js +0 -10
- package/dist/client-v2/127.0ec4dce7b13750e9.js +0 -10
- package/dist/client-v2/57.e7cfc50fb651ac14.js +0 -10
- package/dist/client-v2/65.9c745ea32ac96e98.js +0 -10
|
@@ -0,0 +1,790 @@
|
|
|
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
|
+
CheckCircleOutlined,
|
|
12
|
+
CloseCircleOutlined,
|
|
13
|
+
CodeOutlined,
|
|
14
|
+
FileTextOutlined,
|
|
15
|
+
PauseCircleOutlined,
|
|
16
|
+
PlayCircleOutlined,
|
|
17
|
+
ReloadOutlined,
|
|
18
|
+
} from '@ant-design/icons';
|
|
19
|
+
import { useApp } from '@nocobase/client-v2';
|
|
20
|
+
import {
|
|
21
|
+
Alert,
|
|
22
|
+
Button,
|
|
23
|
+
Card,
|
|
24
|
+
Descriptions,
|
|
25
|
+
Drawer,
|
|
26
|
+
Empty,
|
|
27
|
+
Flex,
|
|
28
|
+
Modal,
|
|
29
|
+
Popconfirm,
|
|
30
|
+
Progress,
|
|
31
|
+
Select,
|
|
32
|
+
Space,
|
|
33
|
+
Spin,
|
|
34
|
+
Statistic,
|
|
35
|
+
Switch,
|
|
36
|
+
Table,
|
|
37
|
+
Tabs,
|
|
38
|
+
Tag,
|
|
39
|
+
Typography,
|
|
40
|
+
message,
|
|
41
|
+
} from 'antd';
|
|
42
|
+
import type { ColumnsType } from 'antd/es/table';
|
|
43
|
+
import React, { useCallback, useEffect, useRef, useState } from 'react';
|
|
44
|
+
import { PORTAINER_RESOURCE } from '../../shared/constants';
|
|
45
|
+
import type {
|
|
46
|
+
PortainerContainerSummary,
|
|
47
|
+
PortainerDeploymentRecord,
|
|
48
|
+
PortainerEndpointSummary,
|
|
49
|
+
PortainerInstanceSummary,
|
|
50
|
+
PortainerMaskedEnvItem,
|
|
51
|
+
PortainerStackOverview,
|
|
52
|
+
PortainerStackSummary,
|
|
53
|
+
} from '../../shared/types';
|
|
54
|
+
import { useT } from '../locale';
|
|
55
|
+
|
|
56
|
+
export function formatBytes(bytes?: number | null): string {
|
|
57
|
+
const num = Number(bytes ?? 0);
|
|
58
|
+
if (!Number.isFinite(num) || num <= 0) {
|
|
59
|
+
return '0 B';
|
|
60
|
+
}
|
|
61
|
+
const units = ['B', 'KB', 'MB', 'GB', 'TB'];
|
|
62
|
+
let idx = 0;
|
|
63
|
+
let val = num;
|
|
64
|
+
while (val >= 1024 && idx < units.length - 1) {
|
|
65
|
+
val /= 1024;
|
|
66
|
+
idx += 1;
|
|
67
|
+
}
|
|
68
|
+
return `${val >= 100 || idx === 0 ? Math.round(val) : val.toFixed(1)} ${units[idx]}`;
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
function formatUnixTime(unixSeconds?: number): string {
|
|
72
|
+
if (!unixSeconds || !Number.isFinite(unixSeconds) || unixSeconds <= 0) {
|
|
73
|
+
return '-';
|
|
74
|
+
}
|
|
75
|
+
return new Date(unixSeconds * 1000).toLocaleString();
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
function renderStackStatusTag(status: number, t: ReturnType<typeof useT>) {
|
|
79
|
+
if (status === 3) {
|
|
80
|
+
return <Tag color="processing">{t('Deploying')}</Tag>;
|
|
81
|
+
}
|
|
82
|
+
if (status === 4) {
|
|
83
|
+
return <Tag color="error">{t('Error')}</Tag>;
|
|
84
|
+
}
|
|
85
|
+
return <Tag color={status === 1 ? 'success' : 'default'}>{status === 1 ? t('Active') : t('Inactive')}</Tag>;
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
export interface StackDetailDrawerProps {
|
|
89
|
+
open: boolean;
|
|
90
|
+
instance: PortainerInstanceSummary | null;
|
|
91
|
+
stack: PortainerStackSummary | null;
|
|
92
|
+
endpoints: PortainerEndpointSummary[];
|
|
93
|
+
onClose: () => void;
|
|
94
|
+
onStackChanged?: () => void;
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
export function StackDetailDrawer({
|
|
98
|
+
open,
|
|
99
|
+
instance,
|
|
100
|
+
stack,
|
|
101
|
+
endpoints,
|
|
102
|
+
onClose,
|
|
103
|
+
onStackChanged,
|
|
104
|
+
}: StackDetailDrawerProps) {
|
|
105
|
+
const t = useT();
|
|
106
|
+
const api = useApp().apiClient;
|
|
107
|
+
|
|
108
|
+
const [overview, setOverview] = useState<PortainerStackOverview | null>(null);
|
|
109
|
+
const [initialLoading, setInitialLoading] = useState(false);
|
|
110
|
+
const [refreshing, setRefreshing] = useState(false);
|
|
111
|
+
const [errorMsg, setErrorMsg] = useState<string | null>(null);
|
|
112
|
+
const [autoRefresh, setAutoRefresh] = useState(false);
|
|
113
|
+
const [controlling, setControlling] = useState<'start' | 'stop' | null>(null);
|
|
114
|
+
|
|
115
|
+
const [logContainer, setLogContainer] = useState<PortainerContainerSummary | null>(null);
|
|
116
|
+
const [logTail, setLogTail] = useState<number>(100);
|
|
117
|
+
const [logText, setLogText] = useState<string>('');
|
|
118
|
+
const [loadingLogs, setLoadingLogs] = useState(false);
|
|
119
|
+
|
|
120
|
+
const inFlightRef = useRef(false);
|
|
121
|
+
|
|
122
|
+
const fetchOverview = useCallback(
|
|
123
|
+
async (options?: { silent?: boolean; includeFile?: boolean }) => {
|
|
124
|
+
if (!instance || !stack || inFlightRef.current) {
|
|
125
|
+
return;
|
|
126
|
+
}
|
|
127
|
+
inFlightRef.current = true;
|
|
128
|
+
if (options?.silent) {
|
|
129
|
+
setRefreshing(true);
|
|
130
|
+
} else {
|
|
131
|
+
setInitialLoading(true);
|
|
132
|
+
}
|
|
133
|
+
try {
|
|
134
|
+
const res = await api.request<{ data?: PortainerStackOverview }>({
|
|
135
|
+
url: `${PORTAINER_RESOURCE}:getStackOverview`,
|
|
136
|
+
method: 'get',
|
|
137
|
+
params: {
|
|
138
|
+
instanceId: instance.id,
|
|
139
|
+
stackId: stack.id,
|
|
140
|
+
includeStats: 'true',
|
|
141
|
+
includeFile: options?.includeFile === false ? 'false' : 'true',
|
|
142
|
+
},
|
|
143
|
+
});
|
|
144
|
+
const data = res?.data?.data;
|
|
145
|
+
if (data) {
|
|
146
|
+
setOverview((prev) => ({
|
|
147
|
+
...data,
|
|
148
|
+
stackFileContent: options?.includeFile === false && prev ? prev.stackFileContent : data.stackFileContent,
|
|
149
|
+
}));
|
|
150
|
+
setErrorMsg(null);
|
|
151
|
+
}
|
|
152
|
+
} catch (err) {
|
|
153
|
+
const msg = err instanceof Error ? err.message : t('Failed to load Stack details from Portainer');
|
|
154
|
+
setErrorMsg(msg);
|
|
155
|
+
} finally {
|
|
156
|
+
inFlightRef.current = false;
|
|
157
|
+
setInitialLoading(false);
|
|
158
|
+
setRefreshing(false);
|
|
159
|
+
}
|
|
160
|
+
},
|
|
161
|
+
[api, instance, stack, t],
|
|
162
|
+
);
|
|
163
|
+
|
|
164
|
+
useEffect(() => {
|
|
165
|
+
if (open && instance && stack) {
|
|
166
|
+
setOverview(null);
|
|
167
|
+
setErrorMsg(null);
|
|
168
|
+
fetchOverview({ silent: false, includeFile: true });
|
|
169
|
+
} else {
|
|
170
|
+
setAutoRefresh(false);
|
|
171
|
+
setLogContainer(null);
|
|
172
|
+
}
|
|
173
|
+
}, [fetchOverview, instance, open, stack]);
|
|
174
|
+
|
|
175
|
+
useEffect(() => {
|
|
176
|
+
if (!open || !autoRefresh || !instance || !stack) {
|
|
177
|
+
return;
|
|
178
|
+
}
|
|
179
|
+
const timer = window.setInterval(() => {
|
|
180
|
+
if (typeof document !== 'undefined' && document.visibilityState === 'hidden') {
|
|
181
|
+
return;
|
|
182
|
+
}
|
|
183
|
+
fetchOverview({ silent: true, includeFile: false });
|
|
184
|
+
}, 5000);
|
|
185
|
+
return () => window.clearInterval(timer);
|
|
186
|
+
}, [autoRefresh, fetchOverview, instance, open, stack]);
|
|
187
|
+
|
|
188
|
+
const fetchContainerLogs = useCallback(
|
|
189
|
+
async (target: PortainerContainerSummary, tailLines: number) => {
|
|
190
|
+
if (!instance || !stack) {
|
|
191
|
+
return;
|
|
192
|
+
}
|
|
193
|
+
const epId = overview?.detail.endpointId ?? stack.endpointId;
|
|
194
|
+
setLoadingLogs(true);
|
|
195
|
+
try {
|
|
196
|
+
const res = await api.request<{ data?: { logs?: string } }>({
|
|
197
|
+
url: `${PORTAINER_RESOURCE}:getContainerLogs`,
|
|
198
|
+
method: 'get',
|
|
199
|
+
params: {
|
|
200
|
+
instanceId: instance.id,
|
|
201
|
+
endpointId: epId,
|
|
202
|
+
containerId: target.id,
|
|
203
|
+
tail: tailLines,
|
|
204
|
+
},
|
|
205
|
+
});
|
|
206
|
+
setLogText(String(res?.data?.data?.logs ?? ''));
|
|
207
|
+
} catch {
|
|
208
|
+
message.error(t('Failed to fetch container logs'));
|
|
209
|
+
} finally {
|
|
210
|
+
setLoadingLogs(false);
|
|
211
|
+
}
|
|
212
|
+
},
|
|
213
|
+
[api, instance, overview?.detail.endpointId, stack, t],
|
|
214
|
+
);
|
|
215
|
+
|
|
216
|
+
const openLogsModal = (container: PortainerContainerSummary) => {
|
|
217
|
+
setLogContainer(container);
|
|
218
|
+
setLogText('');
|
|
219
|
+
fetchContainerLogs(container, logTail);
|
|
220
|
+
};
|
|
221
|
+
|
|
222
|
+
const handleControlStack = async (operation: 'start' | 'stop') => {
|
|
223
|
+
if (!instance || !stack) {
|
|
224
|
+
return;
|
|
225
|
+
}
|
|
226
|
+
const epId = overview?.detail.endpointId ?? stack.endpointId;
|
|
227
|
+
setControlling(operation);
|
|
228
|
+
try {
|
|
229
|
+
await api.request({
|
|
230
|
+
url: `${PORTAINER_RESOURCE}:controlStack`,
|
|
231
|
+
method: 'post',
|
|
232
|
+
data: {
|
|
233
|
+
instanceId: instance.id,
|
|
234
|
+
endpointId: epId,
|
|
235
|
+
stackId: stack.id,
|
|
236
|
+
operation,
|
|
237
|
+
},
|
|
238
|
+
});
|
|
239
|
+
message.success(operation === 'start' ? t('Stack started') : t('Stack stopped'));
|
|
240
|
+
await fetchOverview({ silent: true, includeFile: false });
|
|
241
|
+
onStackChanged?.();
|
|
242
|
+
} catch (err) {
|
|
243
|
+
const msg = err instanceof Error ? err.message : t('Failed to control Stack');
|
|
244
|
+
message.error(msg);
|
|
245
|
+
} finally {
|
|
246
|
+
setControlling(null);
|
|
247
|
+
}
|
|
248
|
+
};
|
|
249
|
+
|
|
250
|
+
const detail = overview?.detail;
|
|
251
|
+
const summary = overview?.summary;
|
|
252
|
+
const endpointId = detail?.endpointId ?? stack?.endpointId;
|
|
253
|
+
const endpointName = endpointId ? endpoints.find((ep) => ep.id === endpointId)?.name ?? `#${endpointId}` : '-';
|
|
254
|
+
const currentStatus = detail?.status ?? stack?.status ?? 1;
|
|
255
|
+
|
|
256
|
+
const containerColumns: ColumnsType<PortainerContainerSummary> = [
|
|
257
|
+
{
|
|
258
|
+
title: t('Container / Service'),
|
|
259
|
+
key: 'name',
|
|
260
|
+
width: 230,
|
|
261
|
+
render: (_, record) => (
|
|
262
|
+
<Space direction="vertical" size={2}>
|
|
263
|
+
<Space size="small" wrap>
|
|
264
|
+
<Typography.Text strong>{record.name || record.id}</Typography.Text>
|
|
265
|
+
{record.service ? <Tag color="geekblue">{record.service}</Tag> : null}
|
|
266
|
+
</Space>
|
|
267
|
+
<Typography.Text type="secondary" style={{ fontSize: 12 }}>
|
|
268
|
+
{record.image}
|
|
269
|
+
</Typography.Text>
|
|
270
|
+
</Space>
|
|
271
|
+
),
|
|
272
|
+
},
|
|
273
|
+
{
|
|
274
|
+
title: t('State & Uptime'),
|
|
275
|
+
key: 'state',
|
|
276
|
+
width: 150,
|
|
277
|
+
render: (_, record) => (
|
|
278
|
+
<Space direction="vertical" size={2}>
|
|
279
|
+
<Tag
|
|
280
|
+
color={record.healthy ? 'success' : record.state === 'exited' ? 'default' : 'error'}
|
|
281
|
+
icon={record.healthy ? <CheckCircleOutlined /> : <CloseCircleOutlined />}
|
|
282
|
+
>
|
|
283
|
+
{record.state}
|
|
284
|
+
</Tag>
|
|
285
|
+
{record.status ? (
|
|
286
|
+
<Typography.Text type="secondary" style={{ fontSize: 12 }}>
|
|
287
|
+
{record.status}
|
|
288
|
+
</Typography.Text>
|
|
289
|
+
) : null}
|
|
290
|
+
</Space>
|
|
291
|
+
),
|
|
292
|
+
},
|
|
293
|
+
{
|
|
294
|
+
title: t('Ports & IP'),
|
|
295
|
+
key: 'network',
|
|
296
|
+
width: 190,
|
|
297
|
+
render: (_, record) => (
|
|
298
|
+
<Space direction="vertical" size={2}>
|
|
299
|
+
{record.ports && record.ports.length > 0 ? (
|
|
300
|
+
record.ports.map((p) => (
|
|
301
|
+
<Typography.Text key={p} code style={{ fontSize: 12 }}>
|
|
302
|
+
{p}
|
|
303
|
+
</Typography.Text>
|
|
304
|
+
))
|
|
305
|
+
) : (
|
|
306
|
+
<Typography.Text type="secondary">-</Typography.Text>
|
|
307
|
+
)}
|
|
308
|
+
{record.ipAddresses && record.ipAddresses.length > 0 ? (
|
|
309
|
+
<Typography.Text type="secondary" style={{ fontSize: 12 }}>
|
|
310
|
+
IP: {record.ipAddresses.join(', ')}
|
|
311
|
+
</Typography.Text>
|
|
312
|
+
) : null}
|
|
313
|
+
</Space>
|
|
314
|
+
),
|
|
315
|
+
},
|
|
316
|
+
{
|
|
317
|
+
title: t('CPU'),
|
|
318
|
+
key: 'cpu',
|
|
319
|
+
width: 130,
|
|
320
|
+
render: (_, record) =>
|
|
321
|
+
record.stats ? (
|
|
322
|
+
<Space direction="vertical" size={0} style={{ width: '100%' }}>
|
|
323
|
+
<Typography.Text strong>{record.stats.cpuPercent.toFixed(2)}%</Typography.Text>
|
|
324
|
+
<Progress
|
|
325
|
+
percent={Math.min(100, Number(record.stats.cpuPercent.toFixed(1)))}
|
|
326
|
+
size="small"
|
|
327
|
+
showInfo={false}
|
|
328
|
+
aria-label={`${t('CPU')} ${record.name}`}
|
|
329
|
+
/>
|
|
330
|
+
</Space>
|
|
331
|
+
) : (
|
|
332
|
+
<Typography.Text type="secondary">-</Typography.Text>
|
|
333
|
+
),
|
|
334
|
+
},
|
|
335
|
+
{
|
|
336
|
+
title: t('Memory'),
|
|
337
|
+
key: 'memory',
|
|
338
|
+
width: 175,
|
|
339
|
+
render: (_, record) =>
|
|
340
|
+
record.stats ? (
|
|
341
|
+
<Space direction="vertical" size={0} style={{ width: '100%' }}>
|
|
342
|
+
<Typography.Text strong>
|
|
343
|
+
{formatBytes(record.stats.memUsageBytes)}{' '}
|
|
344
|
+
<Typography.Text type="secondary" style={{ fontWeight: 400, fontSize: 12 }}>
|
|
345
|
+
/ {formatBytes(record.stats.memLimitBytes)}
|
|
346
|
+
</Typography.Text>
|
|
347
|
+
</Typography.Text>
|
|
348
|
+
<Progress
|
|
349
|
+
percent={Math.min(100, Number(record.stats.memPercent.toFixed(1)))}
|
|
350
|
+
size="small"
|
|
351
|
+
showInfo={false}
|
|
352
|
+
aria-label={`${t('Memory')} ${record.name}`}
|
|
353
|
+
/>
|
|
354
|
+
</Space>
|
|
355
|
+
) : (
|
|
356
|
+
<Typography.Text type="secondary">-</Typography.Text>
|
|
357
|
+
),
|
|
358
|
+
},
|
|
359
|
+
{
|
|
360
|
+
title: t('Network / PIDs'),
|
|
361
|
+
key: 'io',
|
|
362
|
+
width: 165,
|
|
363
|
+
render: (_, record) =>
|
|
364
|
+
record.stats ? (
|
|
365
|
+
<Space direction="vertical" size={0} style={{ fontSize: 12 }}>
|
|
366
|
+
<Typography.Text style={{ fontSize: 12 }}>
|
|
367
|
+
↓ {formatBytes(record.stats.netRxBytes)} / ↑ {formatBytes(record.stats.netTxBytes)}
|
|
368
|
+
</Typography.Text>
|
|
369
|
+
<Typography.Text type="secondary" style={{ fontSize: 12 }}>
|
|
370
|
+
PIDs: {record.stats.pids}
|
|
371
|
+
</Typography.Text>
|
|
372
|
+
</Space>
|
|
373
|
+
) : (
|
|
374
|
+
<Typography.Text type="secondary">-</Typography.Text>
|
|
375
|
+
),
|
|
376
|
+
},
|
|
377
|
+
{
|
|
378
|
+
title: t('Actions'),
|
|
379
|
+
key: 'actions',
|
|
380
|
+
width: 96,
|
|
381
|
+
fixed: 'right',
|
|
382
|
+
render: (_, record) => (
|
|
383
|
+
<Button
|
|
384
|
+
size="small"
|
|
385
|
+
htmlType="button"
|
|
386
|
+
icon={<FileTextOutlined />}
|
|
387
|
+
aria-label={`${t('Logs')} ${record.name || record.id}`}
|
|
388
|
+
onClick={() => openLogsModal(record)}
|
|
389
|
+
>
|
|
390
|
+
{t('Logs')}
|
|
391
|
+
</Button>
|
|
392
|
+
),
|
|
393
|
+
},
|
|
394
|
+
];
|
|
395
|
+
|
|
396
|
+
const envColumns: ColumnsType<PortainerMaskedEnvItem> = [
|
|
397
|
+
{
|
|
398
|
+
title: t('Name'),
|
|
399
|
+
dataIndex: 'name',
|
|
400
|
+
key: 'name',
|
|
401
|
+
width: 240,
|
|
402
|
+
render: (name: string, row) => (
|
|
403
|
+
<Space size="small">
|
|
404
|
+
<Typography.Text code>{name}</Typography.Text>
|
|
405
|
+
{row.sensitive ? <Tag color="warning">{t('Secret')}</Tag> : null}
|
|
406
|
+
</Space>
|
|
407
|
+
),
|
|
408
|
+
},
|
|
409
|
+
{
|
|
410
|
+
title: t('Value'),
|
|
411
|
+
dataIndex: 'value',
|
|
412
|
+
key: 'value',
|
|
413
|
+
render: (val: string, row) =>
|
|
414
|
+
row.sensitive ? (
|
|
415
|
+
<Typography.Text type="secondary">{val}</Typography.Text>
|
|
416
|
+
) : (
|
|
417
|
+
<Typography.Text style={{ wordBreak: 'break-all' }}>{val || '-'}</Typography.Text>
|
|
418
|
+
),
|
|
419
|
+
},
|
|
420
|
+
];
|
|
421
|
+
|
|
422
|
+
const deploymentColumns: ColumnsType<PortainerDeploymentRecord> = [
|
|
423
|
+
{
|
|
424
|
+
title: t('Time'),
|
|
425
|
+
dataIndex: 'time',
|
|
426
|
+
key: 'time',
|
|
427
|
+
width: 190,
|
|
428
|
+
render: (time?: number) => formatUnixTime(time),
|
|
429
|
+
},
|
|
430
|
+
{
|
|
431
|
+
title: t('Status'),
|
|
432
|
+
dataIndex: 'status',
|
|
433
|
+
key: 'status',
|
|
434
|
+
width: 120,
|
|
435
|
+
render: (st: number) => renderStackStatusTag(st, t),
|
|
436
|
+
},
|
|
437
|
+
{
|
|
438
|
+
title: t('Message'),
|
|
439
|
+
dataIndex: 'message',
|
|
440
|
+
key: 'message',
|
|
441
|
+
render: (msg?: string) => msg || '-',
|
|
442
|
+
},
|
|
443
|
+
];
|
|
444
|
+
|
|
445
|
+
return (
|
|
446
|
+
<>
|
|
447
|
+
<Drawer
|
|
448
|
+
open={open}
|
|
449
|
+
width={920}
|
|
450
|
+
onClose={onClose}
|
|
451
|
+
title={
|
|
452
|
+
<Space size="small" wrap>
|
|
453
|
+
<span>
|
|
454
|
+
{t('Stack Detail')} — {stack?.name ?? ''}
|
|
455
|
+
</span>
|
|
456
|
+
{stack ? renderStackStatusTag(currentStatus, t) : null}
|
|
457
|
+
{stack ? (
|
|
458
|
+
<Tag color={detail?.isGitStack ?? stack.isGitStack ? 'processing' : 'purple'}>
|
|
459
|
+
{detail?.isGitStack ?? stack.isGitStack ? t('Git Stack') : t('Compose')}
|
|
460
|
+
</Tag>
|
|
461
|
+
) : null}
|
|
462
|
+
</Space>
|
|
463
|
+
}
|
|
464
|
+
extra={
|
|
465
|
+
<Space size="small" wrap>
|
|
466
|
+
<Space size={6}>
|
|
467
|
+
<Switch
|
|
468
|
+
size="small"
|
|
469
|
+
checked={autoRefresh}
|
|
470
|
+
aria-label={t('Auto-refresh live metrics (5s)')}
|
|
471
|
+
onChange={(checked) => setAutoRefresh(checked)}
|
|
472
|
+
/>
|
|
473
|
+
<Typography.Text style={{ fontSize: 12 }}>{t('Auto-refresh (5s)')}</Typography.Text>
|
|
474
|
+
</Space>
|
|
475
|
+
{currentStatus === 2 ? (
|
|
476
|
+
<Button
|
|
477
|
+
size="small"
|
|
478
|
+
type="primary"
|
|
479
|
+
htmlType="button"
|
|
480
|
+
icon={<PlayCircleOutlined />}
|
|
481
|
+
loading={controlling === 'start'}
|
|
482
|
+
onClick={() => {
|
|
483
|
+
handleControlStack('start');
|
|
484
|
+
}}
|
|
485
|
+
>
|
|
486
|
+
{t('Start Stack')}
|
|
487
|
+
</Button>
|
|
488
|
+
) : (
|
|
489
|
+
<Popconfirm title={t('Stop this Stack on Portainer?')} onConfirm={() => handleControlStack('stop')}>
|
|
490
|
+
<Button
|
|
491
|
+
size="small"
|
|
492
|
+
danger
|
|
493
|
+
htmlType="button"
|
|
494
|
+
icon={<PauseCircleOutlined />}
|
|
495
|
+
loading={controlling === 'stop'}
|
|
496
|
+
>
|
|
497
|
+
{t('Stop Stack')}
|
|
498
|
+
</Button>
|
|
499
|
+
</Popconfirm>
|
|
500
|
+
)}
|
|
501
|
+
<Button
|
|
502
|
+
size="small"
|
|
503
|
+
htmlType="button"
|
|
504
|
+
icon={<ReloadOutlined />}
|
|
505
|
+
loading={refreshing || initialLoading}
|
|
506
|
+
onClick={() => {
|
|
507
|
+
fetchOverview({ silent: Boolean(overview), includeFile: true });
|
|
508
|
+
}}
|
|
509
|
+
>
|
|
510
|
+
{t('Refresh')}
|
|
511
|
+
</Button>
|
|
512
|
+
</Space>
|
|
513
|
+
}
|
|
514
|
+
>
|
|
515
|
+
{errorMsg ? <Alert type="error" showIcon style={{ marginBottom: 16 }} message={errorMsg} /> : null}
|
|
516
|
+
|
|
517
|
+
{initialLoading && !overview ? (
|
|
518
|
+
<Flex justify="center" align="center" style={{ minHeight: 260 }}>
|
|
519
|
+
<Spin size="large" />
|
|
520
|
+
</Flex>
|
|
521
|
+
) : overview ? (
|
|
522
|
+
<>
|
|
523
|
+
<Flex gap="small" wrap="wrap" style={{ marginBottom: 16 }}>
|
|
524
|
+
<Card size="small" style={{ flex: '1 1 180px' }}>
|
|
525
|
+
<Statistic
|
|
526
|
+
title={t('Containers Health')}
|
|
527
|
+
value={summary?.runningCount ?? 0}
|
|
528
|
+
suffix={`/ ${summary?.totalCount ?? 0}`}
|
|
529
|
+
valueStyle={{
|
|
530
|
+
color: (summary?.totalCount ?? 0) === 0 ? undefined : summary?.healthy ? '#389e0d' : '#cf1322',
|
|
531
|
+
}}
|
|
532
|
+
/>
|
|
533
|
+
<Typography.Text type="secondary" style={{ fontSize: 12 }}>
|
|
534
|
+
{endpointName} (#{endpointId})
|
|
535
|
+
</Typography.Text>
|
|
536
|
+
</Card>
|
|
537
|
+
|
|
538
|
+
<Card size="small" style={{ flex: '1 1 190px' }}>
|
|
539
|
+
<Statistic title={t('Live CPU Usage')} value={summary?.totalCpuPercent ?? 0} precision={2} suffix="%" />
|
|
540
|
+
<Progress
|
|
541
|
+
percent={Math.min(100, Number((summary?.totalCpuPercent ?? 0).toFixed(1)))}
|
|
542
|
+
size="small"
|
|
543
|
+
showInfo={false}
|
|
544
|
+
aria-label={t('Live CPU Usage')}
|
|
545
|
+
/>
|
|
546
|
+
</Card>
|
|
547
|
+
|
|
548
|
+
<Card size="small" style={{ flex: '1 1 220px' }}>
|
|
549
|
+
<Statistic
|
|
550
|
+
title={t('Live Memory Usage')}
|
|
551
|
+
value={formatBytes(summary?.totalMemUsageBytes ?? 0)}
|
|
552
|
+
suffix={
|
|
553
|
+
summary?.memLimitBytes ? (
|
|
554
|
+
<Typography.Text type="secondary" style={{ fontSize: 13 }}>
|
|
555
|
+
/ {formatBytes(summary.memLimitBytes)} ({summary.totalMemPercent.toFixed(1)}%)
|
|
556
|
+
</Typography.Text>
|
|
557
|
+
) : null
|
|
558
|
+
}
|
|
559
|
+
/>
|
|
560
|
+
<Progress
|
|
561
|
+
percent={Math.min(100, Number((summary?.totalMemPercent ?? 0).toFixed(1)))}
|
|
562
|
+
size="small"
|
|
563
|
+
showInfo={false}
|
|
564
|
+
aria-label={t('Live Memory Usage')}
|
|
565
|
+
/>
|
|
566
|
+
</Card>
|
|
567
|
+
|
|
568
|
+
<Card size="small" style={{ flex: '1 1 200px' }}>
|
|
569
|
+
<Statistic
|
|
570
|
+
title={t('Network I/O (RX / TX)')}
|
|
571
|
+
value={`↓ ${formatBytes(summary?.totalNetRxBytes ?? 0)}`}
|
|
572
|
+
valueStyle={{ fontSize: 16 }}
|
|
573
|
+
/>
|
|
574
|
+
<Typography.Text type="secondary" style={{ fontSize: 12 }}>
|
|
575
|
+
↑ {formatBytes(summary?.totalNetTxBytes ?? 0)}
|
|
576
|
+
</Typography.Text>
|
|
577
|
+
</Card>
|
|
578
|
+
</Flex>
|
|
579
|
+
|
|
580
|
+
<Tabs
|
|
581
|
+
defaultActiveKey="containers"
|
|
582
|
+
items={[
|
|
583
|
+
{
|
|
584
|
+
key: 'containers',
|
|
585
|
+
label: `${t('Containers & Live Metrics')} (${overview.containers.length})`,
|
|
586
|
+
children: (
|
|
587
|
+
<div
|
|
588
|
+
tabIndex={0}
|
|
589
|
+
role="region"
|
|
590
|
+
aria-label={t('Stack containers and live metrics')}
|
|
591
|
+
style={{ overflowX: 'auto', maxInlineSize: '100%' }}
|
|
592
|
+
>
|
|
593
|
+
<Table<PortainerContainerSummary>
|
|
594
|
+
rowKey="id"
|
|
595
|
+
size="small"
|
|
596
|
+
pagination={false}
|
|
597
|
+
scroll={{ x: 1120 }}
|
|
598
|
+
dataSource={overview.containers}
|
|
599
|
+
columns={containerColumns}
|
|
600
|
+
locale={{ emptyText: <Empty description={t('No containers found for this Stack')} /> }}
|
|
601
|
+
/>
|
|
602
|
+
</div>
|
|
603
|
+
),
|
|
604
|
+
},
|
|
605
|
+
{
|
|
606
|
+
key: 'metadata',
|
|
607
|
+
label: t('Stack Metadata'),
|
|
608
|
+
children: (
|
|
609
|
+
<Space direction="vertical" size="middle" style={{ width: '100%' }}>
|
|
610
|
+
<Descriptions bordered size="small" column={{ xs: 1, sm: 2 }}>
|
|
611
|
+
<Descriptions.Item label={t('Stack ID')}>{detail?.id}</Descriptions.Item>
|
|
612
|
+
<Descriptions.Item label={t('Stack Name')}>{detail?.name}</Descriptions.Item>
|
|
613
|
+
<Descriptions.Item label={t('Endpoint')}>
|
|
614
|
+
{endpointName} (#{endpointId})
|
|
615
|
+
</Descriptions.Item>
|
|
616
|
+
<Descriptions.Item label={t('Entry point')}>
|
|
617
|
+
<Typography.Text code>{detail?.entryPoint || 'docker-compose.yml'}</Typography.Text>
|
|
618
|
+
</Descriptions.Item>
|
|
619
|
+
<Descriptions.Item label={t('Created at')}>
|
|
620
|
+
{formatUnixTime(detail?.createdAt)}
|
|
621
|
+
{detail?.createdBy ? ` (${detail.createdBy})` : ''}
|
|
622
|
+
</Descriptions.Item>
|
|
623
|
+
<Descriptions.Item label={t('Last updated')}>
|
|
624
|
+
{formatUnixTime(detail?.updatedAt)}
|
|
625
|
+
{detail?.updatedBy ? ` (${detail.updatedBy})` : ''}
|
|
626
|
+
</Descriptions.Item>
|
|
627
|
+
{detail?.isGitStack ? (
|
|
628
|
+
<>
|
|
629
|
+
<Descriptions.Item label={t('Connected Git repository')} span={2}>
|
|
630
|
+
<Typography.Text code>{detail.gitRepoUrl || '-'}</Typography.Text>
|
|
631
|
+
</Descriptions.Item>
|
|
632
|
+
<Descriptions.Item label={t('Git reference')}>
|
|
633
|
+
<Typography.Text code>{detail.gitReference || '-'}</Typography.Text>
|
|
634
|
+
</Descriptions.Item>
|
|
635
|
+
<Descriptions.Item label={t('Git commit / config')}>
|
|
636
|
+
{detail.gitCommitHash ? (
|
|
637
|
+
<Typography.Text code>{detail.gitCommitHash.slice(0, 12)}</Typography.Text>
|
|
638
|
+
) : (
|
|
639
|
+
'-'
|
|
640
|
+
)}
|
|
641
|
+
{detail.gitConfigFilePath ? ` (${detail.gitConfigFilePath})` : ''}
|
|
642
|
+
</Descriptions.Item>
|
|
643
|
+
</>
|
|
644
|
+
) : null}
|
|
645
|
+
{detail?.projectPath ? (
|
|
646
|
+
<Descriptions.Item label={t('Project path')} span={2}>
|
|
647
|
+
<Typography.Text code>{detail.projectPath}</Typography.Text>
|
|
648
|
+
</Descriptions.Item>
|
|
649
|
+
) : null}
|
|
650
|
+
</Descriptions>
|
|
651
|
+
|
|
652
|
+
{detail?.deployments && detail.deployments.length > 0 ? (
|
|
653
|
+
<Card size="small" title={t('Deployment History')}>
|
|
654
|
+
<Table<PortainerDeploymentRecord>
|
|
655
|
+
rowKey={(row, idx) => `${row.time ?? 0}-${idx ?? 0}`}
|
|
656
|
+
size="small"
|
|
657
|
+
pagination={{ pageSize: 5 }}
|
|
658
|
+
dataSource={[...detail.deployments].reverse()}
|
|
659
|
+
columns={deploymentColumns}
|
|
660
|
+
/>
|
|
661
|
+
</Card>
|
|
662
|
+
) : null}
|
|
663
|
+
</Space>
|
|
664
|
+
),
|
|
665
|
+
},
|
|
666
|
+
{
|
|
667
|
+
key: 'env',
|
|
668
|
+
label: `${t('Env Vars')} (${detail?.env.length ?? 0})`,
|
|
669
|
+
children: (
|
|
670
|
+
<Table<PortainerMaskedEnvItem>
|
|
671
|
+
rowKey="name"
|
|
672
|
+
size="small"
|
|
673
|
+
pagination={{ pageSize: 15 }}
|
|
674
|
+
dataSource={detail?.env ?? []}
|
|
675
|
+
columns={envColumns}
|
|
676
|
+
locale={{ emptyText: <Empty description={t('No environment variables configured')} /> }}
|
|
677
|
+
/>
|
|
678
|
+
),
|
|
679
|
+
},
|
|
680
|
+
{
|
|
681
|
+
key: 'compose',
|
|
682
|
+
label: (
|
|
683
|
+
<span>
|
|
684
|
+
<CodeOutlined style={{ marginInlineEnd: 6 }} />
|
|
685
|
+
{t('Compose File')}
|
|
686
|
+
</span>
|
|
687
|
+
),
|
|
688
|
+
children: overview.stackFileContent ? (
|
|
689
|
+
<pre
|
|
690
|
+
tabIndex={0}
|
|
691
|
+
role="region"
|
|
692
|
+
aria-label={t('Compose File')}
|
|
693
|
+
style={{
|
|
694
|
+
margin: 0,
|
|
695
|
+
padding: 12,
|
|
696
|
+
maxHeight: 480,
|
|
697
|
+
overflow: 'auto',
|
|
698
|
+
borderRadius: 6,
|
|
699
|
+
background: '#141414',
|
|
700
|
+
color: '#e6f4ff',
|
|
701
|
+
fontSize: 12,
|
|
702
|
+
lineHeight: 1.55,
|
|
703
|
+
}}
|
|
704
|
+
>
|
|
705
|
+
{overview.stackFileContent}
|
|
706
|
+
</pre>
|
|
707
|
+
) : (
|
|
708
|
+
<Empty description={t('Compose file content is unavailable')} />
|
|
709
|
+
),
|
|
710
|
+
},
|
|
711
|
+
]}
|
|
712
|
+
/>
|
|
713
|
+
</>
|
|
714
|
+
) : null}
|
|
715
|
+
</Drawer>
|
|
716
|
+
|
|
717
|
+
<Modal
|
|
718
|
+
open={Boolean(logContainer)}
|
|
719
|
+
width={840}
|
|
720
|
+
onCancel={() => setLogContainer(null)}
|
|
721
|
+
footer={
|
|
722
|
+
<Flex justify="space-between" align="center">
|
|
723
|
+
<Space size="small">
|
|
724
|
+
<Typography.Text type="secondary">{t('Tail lines')}:</Typography.Text>
|
|
725
|
+
<Select<number>
|
|
726
|
+
size="small"
|
|
727
|
+
style={{ width: 110 }}
|
|
728
|
+
value={logTail}
|
|
729
|
+
aria-label={t('Tail lines')}
|
|
730
|
+
options={[
|
|
731
|
+
{ value: 50, label: '50' },
|
|
732
|
+
{ value: 100, label: '100' },
|
|
733
|
+
{ value: 300, label: '300' },
|
|
734
|
+
]}
|
|
735
|
+
onChange={(nextTail) => {
|
|
736
|
+
setLogTail(nextTail);
|
|
737
|
+
if (logContainer) {
|
|
738
|
+
fetchContainerLogs(logContainer, nextTail);
|
|
739
|
+
}
|
|
740
|
+
}}
|
|
741
|
+
/>
|
|
742
|
+
</Space>
|
|
743
|
+
<Space>
|
|
744
|
+
<Button
|
|
745
|
+
htmlType="button"
|
|
746
|
+
icon={<ReloadOutlined />}
|
|
747
|
+
loading={loadingLogs}
|
|
748
|
+
onClick={() => {
|
|
749
|
+
if (logContainer) {
|
|
750
|
+
fetchContainerLogs(logContainer, logTail);
|
|
751
|
+
}
|
|
752
|
+
}}
|
|
753
|
+
>
|
|
754
|
+
{t('Refresh')}
|
|
755
|
+
</Button>
|
|
756
|
+
<Button type="primary" htmlType="button" onClick={() => setLogContainer(null)}>
|
|
757
|
+
{t('Close')}
|
|
758
|
+
</Button>
|
|
759
|
+
</Space>
|
|
760
|
+
</Flex>
|
|
761
|
+
}
|
|
762
|
+
title={logContainer ? `${t('Container Logs')} — ${logContainer.name || logContainer.id}` : t('Container Logs')}
|
|
763
|
+
>
|
|
764
|
+
<Spin spinning={loadingLogs}>
|
|
765
|
+
<pre
|
|
766
|
+
tabIndex={0}
|
|
767
|
+
role="region"
|
|
768
|
+
aria-label={t('Container Logs')}
|
|
769
|
+
style={{
|
|
770
|
+
margin: 0,
|
|
771
|
+
padding: 12,
|
|
772
|
+
minHeight: 240,
|
|
773
|
+
maxHeight: 460,
|
|
774
|
+
overflow: 'auto',
|
|
775
|
+
borderRadius: 6,
|
|
776
|
+
background: '#141414',
|
|
777
|
+
color: '#d9f7be',
|
|
778
|
+
fontSize: 12,
|
|
779
|
+
lineHeight: 1.5,
|
|
780
|
+
whiteSpace: 'pre-wrap',
|
|
781
|
+
wordBreak: 'break-word',
|
|
782
|
+
}}
|
|
783
|
+
>
|
|
784
|
+
{logText || t('No log output')}
|
|
785
|
+
</pre>
|
|
786
|
+
</Spin>
|
|
787
|
+
</Modal>
|
|
788
|
+
</>
|
|
789
|
+
);
|
|
790
|
+
}
|