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
package/dist/locale/en-US.json
CHANGED
|
@@ -147,5 +147,47 @@
|
|
|
147
147
|
"Failed to update status": "Failed to update status",
|
|
148
148
|
"Portainer instance deleted": "Portainer instance deleted",
|
|
149
149
|
"Failed to delete Portainer instance": "Failed to delete Portainer instance",
|
|
150
|
-
"Failed to load environments and stacks from Portainer": "Failed to load environments and stacks from Portainer"
|
|
150
|
+
"Failed to load environments and stacks from Portainer": "Failed to load environments and stacks from Portainer",
|
|
151
|
+
"Detail": "Detail",
|
|
152
|
+
"Stack Detail": "Stack Detail",
|
|
153
|
+
"Auto-refresh (5s)": "Auto-refresh (5s)",
|
|
154
|
+
"Auto-refresh live metrics (5s)": "Auto-refresh live metrics (5s)",
|
|
155
|
+
"Stop this Stack on Portainer?": "Stop this Stack on Portainer?",
|
|
156
|
+
"Stack started": "Stack started",
|
|
157
|
+
"Stack stopped": "Stack stopped",
|
|
158
|
+
"Failed to control Stack": "Failed to control Stack",
|
|
159
|
+
"Operation must be start or stop": "Operation must be start or stop",
|
|
160
|
+
"Failed to load Stack details from Portainer": "Failed to load Stack details from Portainer",
|
|
161
|
+
"Containers Health": "Containers Health",
|
|
162
|
+
"Live CPU Usage": "Live CPU Usage",
|
|
163
|
+
"Live Memory Usage": "Live Memory Usage",
|
|
164
|
+
"Network I/O (RX / TX)": "Network I/O (RX / TX)",
|
|
165
|
+
"Containers & Live Metrics": "Containers & Live Metrics",
|
|
166
|
+
"Stack containers and live metrics": "Stack containers and live metrics",
|
|
167
|
+
"No containers found for this Stack": "No containers found for this Stack",
|
|
168
|
+
"Container / Service": "Container / Service",
|
|
169
|
+
"State & Uptime": "State & Uptime",
|
|
170
|
+
"Ports & IP": "Ports & IP",
|
|
171
|
+
"CPU": "CPU",
|
|
172
|
+
"Memory": "Memory",
|
|
173
|
+
"Network / PIDs": "Network / PIDs",
|
|
174
|
+
"Logs": "Logs",
|
|
175
|
+
"Container Logs": "Container Logs",
|
|
176
|
+
"Tail lines": "Tail lines",
|
|
177
|
+
"Close": "Close",
|
|
178
|
+
"No log output": "No log output",
|
|
179
|
+
"Failed to fetch container logs": "Failed to fetch container logs",
|
|
180
|
+
"Stack Metadata": "Stack Metadata",
|
|
181
|
+
"Entry point": "Entry point",
|
|
182
|
+
"Created at": "Created at",
|
|
183
|
+
"Last updated": "Last updated",
|
|
184
|
+
"Git commit / config": "Git commit / config",
|
|
185
|
+
"Project path": "Project path",
|
|
186
|
+
"Deployment History": "Deployment History",
|
|
187
|
+
"Time": "Time",
|
|
188
|
+
"Message": "Message",
|
|
189
|
+
"Value": "Value",
|
|
190
|
+
"No environment variables configured": "No environment variables configured",
|
|
191
|
+
"Compose File": "Compose File",
|
|
192
|
+
"Compose file content is unavailable": "Compose file content is unavailable"
|
|
151
193
|
}
|
package/dist/locale/vi-VN.json
CHANGED
|
@@ -147,5 +147,47 @@
|
|
|
147
147
|
"Failed to update status": "Cập nhật trạng thái thất bại",
|
|
148
148
|
"Portainer instance deleted": "Đã xóa kết nối Portainer",
|
|
149
149
|
"Failed to delete Portainer instance": "Xóa kết nối Portainer thất bại",
|
|
150
|
-
"Failed to load environments and stacks from Portainer": "Không thể tải danh sách môi trường và Stack từ Portainer"
|
|
150
|
+
"Failed to load environments and stacks from Portainer": "Không thể tải danh sách môi trường và Stack từ Portainer",
|
|
151
|
+
"Detail": "Chi tiết",
|
|
152
|
+
"Stack Detail": "Chi tiết Stack",
|
|
153
|
+
"Auto-refresh (5s)": "Tự làm mới (5s)",
|
|
154
|
+
"Auto-refresh live metrics (5s)": "Tự làm mới thông số trực tiếp (5s)",
|
|
155
|
+
"Stop this Stack on Portainer?": "Dừng Stack này trên Portainer?",
|
|
156
|
+
"Stack started": "Đã khởi động Stack",
|
|
157
|
+
"Stack stopped": "Đã dừng Stack",
|
|
158
|
+
"Failed to control Stack": "Điều khiển Stack thất bại",
|
|
159
|
+
"Operation must be start or stop": "Thao tác phải là start hoặc stop",
|
|
160
|
+
"Failed to load Stack details from Portainer": "Không thể tải chi tiết Stack từ Portainer",
|
|
161
|
+
"Containers Health": "Sức khỏe Container",
|
|
162
|
+
"Live CPU Usage": "CPU trực tiếp",
|
|
163
|
+
"Live Memory Usage": "Bộ nhớ RAM trực tiếp",
|
|
164
|
+
"Network I/O (RX / TX)": "Lưu lượng mạng (RX / TX)",
|
|
165
|
+
"Containers & Live Metrics": "Container & Thông số trực tiếp",
|
|
166
|
+
"Stack containers and live metrics": "Danh sách container và thông số trực tiếp của Stack",
|
|
167
|
+
"No containers found for this Stack": "Không có container nào thuộc Stack này",
|
|
168
|
+
"Container / Service": "Container / Dịch vụ",
|
|
169
|
+
"State & Uptime": "Trạng thái & Thời gian chạy",
|
|
170
|
+
"Ports & IP": "Cổng & Địa chỉ IP",
|
|
171
|
+
"CPU": "CPU",
|
|
172
|
+
"Memory": "Bộ nhớ",
|
|
173
|
+
"Network / PIDs": "Mạng / PIDs",
|
|
174
|
+
"Logs": "Nhật ký",
|
|
175
|
+
"Container Logs": "Nhật ký Container",
|
|
176
|
+
"Tail lines": "Số dòng cuối",
|
|
177
|
+
"Close": "Đóng",
|
|
178
|
+
"No log output": "Chưa có dữ liệu nhật ký",
|
|
179
|
+
"Failed to fetch container logs": "Không thể tải nhật ký container",
|
|
180
|
+
"Stack Metadata": "Thông tin cấu hình Stack",
|
|
181
|
+
"Entry point": "Tệp khởi chạy",
|
|
182
|
+
"Created at": "Thời gian tạo",
|
|
183
|
+
"Last updated": "Cập nhật gần nhất",
|
|
184
|
+
"Git commit / config": "Mã commit / Tệp cấu hình Git",
|
|
185
|
+
"Project path": "Đường dẫn dự án",
|
|
186
|
+
"Deployment History": "Lịch sử triển khai",
|
|
187
|
+
"Time": "Thời gian",
|
|
188
|
+
"Message": "Thông điệp",
|
|
189
|
+
"Value": "Giá trị",
|
|
190
|
+
"No environment variables configured": "Chưa cấu hình biến môi trường nào",
|
|
191
|
+
"Compose File": "Tệp Compose",
|
|
192
|
+
"Compose file content is unavailable": "Không đọc được nội dung tệp Compose"
|
|
151
193
|
}
|
package/dist/locale/zh-CN.json
CHANGED
|
@@ -147,5 +147,47 @@
|
|
|
147
147
|
"Failed to update status": "更新状态失败",
|
|
148
148
|
"Portainer instance deleted": "Portainer 实例已删除",
|
|
149
149
|
"Failed to delete Portainer instance": "删除 Portainer 实例失败",
|
|
150
|
-
"Failed to load environments and stacks from Portainer": "从 Portainer 加载环境与 Stack 列表失败"
|
|
150
|
+
"Failed to load environments and stacks from Portainer": "从 Portainer 加载环境与 Stack 列表失败",
|
|
151
|
+
"Detail": "详情",
|
|
152
|
+
"Stack Detail": "Stack 详情",
|
|
153
|
+
"Auto-refresh (5s)": "自动刷新 (5s)",
|
|
154
|
+
"Auto-refresh live metrics (5s)": "自动刷新实时指标 (5s)",
|
|
155
|
+
"Stop this Stack on Portainer?": "确定在 Portainer 上停止此 Stack 吗?",
|
|
156
|
+
"Stack started": "Stack 已启动",
|
|
157
|
+
"Stack stopped": "Stack 已停止",
|
|
158
|
+
"Failed to control Stack": "控制 Stack 失败",
|
|
159
|
+
"Operation must be start or stop": "操作必须为 start 或 stop",
|
|
160
|
+
"Failed to load Stack details from Portainer": "从 Portainer 加载 Stack 详情失败",
|
|
161
|
+
"Containers Health": "容器健康度",
|
|
162
|
+
"Live CPU Usage": "实时 CPU 使用率",
|
|
163
|
+
"Live Memory Usage": "实时内存使用",
|
|
164
|
+
"Network I/O (RX / TX)": "网络流量 (RX / TX)",
|
|
165
|
+
"Containers & Live Metrics": "容器与实时指标",
|
|
166
|
+
"Stack containers and live metrics": "Stack 容器与实时指标",
|
|
167
|
+
"No containers found for this Stack": "未找到该 Stack 的容器",
|
|
168
|
+
"Container / Service": "容器 / 服务",
|
|
169
|
+
"State & Uptime": "状态与运行时长",
|
|
170
|
+
"Ports & IP": "端口与 IP",
|
|
171
|
+
"CPU": "CPU",
|
|
172
|
+
"Memory": "内存",
|
|
173
|
+
"Network / PIDs": "网络 / PIDs",
|
|
174
|
+
"Logs": "日志",
|
|
175
|
+
"Container Logs": "容器日志",
|
|
176
|
+
"Tail lines": "末尾行数",
|
|
177
|
+
"Close": "关闭",
|
|
178
|
+
"No log output": "暂无日志输出",
|
|
179
|
+
"Failed to fetch container logs": "获取容器日志失败",
|
|
180
|
+
"Stack Metadata": "Stack 元数据",
|
|
181
|
+
"Entry point": "入口文件",
|
|
182
|
+
"Created at": "创建时间",
|
|
183
|
+
"Last updated": "最后更新",
|
|
184
|
+
"Git commit / config": "Git 提交 / 配置文件",
|
|
185
|
+
"Project path": "项目路径",
|
|
186
|
+
"Deployment History": "部署历史",
|
|
187
|
+
"Time": "时间",
|
|
188
|
+
"Message": "消息",
|
|
189
|
+
"Value": "值",
|
|
190
|
+
"No environment variables configured": "未配置环境变量",
|
|
191
|
+
"Compose File": "Compose 文件",
|
|
192
|
+
"Compose file content is unavailable": "无法获取 Compose 文件内容"
|
|
151
193
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"name":"joi","description":"Object schema validation","version":"17.13.8","repository":"git://github.com/hapijs/joi","main":"lib/index.js","types":"lib/index.d.ts","browser":"dist/joi-browser.min.js","files":["lib/**/*","dist/*"],"keywords":["schema","validation"],"dependencies":{"@hapi/hoek":"^9.3.0","@hapi/topo":"^5.1.0","@sideway/address":"^4.1.5","@sideway/formula":"^3.0.1","@sideway/pinpoint":"^2.0.0"},"devDependencies":{"@hapi/bourne":"2.x.x","@hapi/code":"8.x.x","@hapi/joi-legacy-test":"npm:@hapi/joi@15.x.x","@hapi/lab":"^25.1.3","@types/node":"^14.18.63","typescript":"4.3.x"},"scripts":{"prepublishOnly":"cd browser && npm install && npm run build","test":"lab -t 100 -a @hapi/code -L -Y","test-cov-html":"lab -r html -o coverage.html -a @hapi/code"},"license":"BSD-3-Clause","_lastModified":"2026-11-
|
|
1
|
+
{"name":"joi","description":"Object schema validation","version":"17.13.8","repository":"git://github.com/hapijs/joi","main":"lib/index.js","types":"lib/index.d.ts","browser":"dist/joi-browser.min.js","files":["lib/**/*","dist/*"],"keywords":["schema","validation"],"dependencies":{"@hapi/hoek":"^9.3.0","@hapi/topo":"^5.1.0","@sideway/address":"^4.1.5","@sideway/formula":"^3.0.1","@sideway/pinpoint":"^2.0.0"},"devDependencies":{"@hapi/bourne":"2.x.x","@hapi/code":"8.x.x","@hapi/joi-legacy-test":"npm:@hapi/joi@15.x.x","@hapi/lab":"^25.1.3","@types/node":"^14.18.63","typescript":"4.3.x"},"scripts":{"prepublishOnly":"cd browser && npm install && npm run build","test":"lab -t 100 -a @hapi/code -L -Y","test-cov-html":"lab -r html -o coverage.html -a @hapi/code"},"license":"BSD-3-Clause","_lastModified":"2026-11-27T01:54:26.599Z"}
|
|
@@ -183,6 +183,131 @@ function createPortainerResourceActions(app) {
|
|
|
183
183
|
sendPortainerError(ctx, error);
|
|
184
184
|
}
|
|
185
185
|
await next();
|
|
186
|
+
},
|
|
187
|
+
async getStackOverview(ctx, next) {
|
|
188
|
+
const instanceId = getRequestParam(ctx, "instanceId");
|
|
189
|
+
const rawStackId = getRequestParam(ctx, "stackId");
|
|
190
|
+
const includeStatsParam = getRequestParam(ctx, "includeStats");
|
|
191
|
+
const includeFileParam = getRequestParam(ctx, "includeFile");
|
|
192
|
+
const includeStats = includeStatsParam !== false && includeStatsParam !== "false";
|
|
193
|
+
const includeFile = includeFileParam !== false && includeFileParam !== "false";
|
|
194
|
+
try {
|
|
195
|
+
if (rawStackId === null || typeof rawStackId === "undefined" || String(rawStackId).trim() === "") {
|
|
196
|
+
ctx.throw(400, ctx.t("Stack ID is required", { ns: import_constants.PLUGIN_NAMESPACE }));
|
|
197
|
+
}
|
|
198
|
+
const instance = await (0, import_helpers.resolvePortainerInstance)(app, instanceId ?? null);
|
|
199
|
+
const stackId = (0, import_PortainerClient.assertPositiveInt)(rawStackId, "Stack ID");
|
|
200
|
+
const [detail, stackFileContent] = await Promise.all([
|
|
201
|
+
instance.client.getStackDetail(stackId),
|
|
202
|
+
includeFile ? instance.client.getStackFile(stackId).catch(() => "") : Promise.resolve("")
|
|
203
|
+
]);
|
|
204
|
+
const baseContainers = await instance.client.listStackContainers(detail.endpointId, detail.name).catch(() => []);
|
|
205
|
+
const containers = includeStats ? await Promise.all(
|
|
206
|
+
baseContainers.map(async (container) => {
|
|
207
|
+
if (container.state !== "running") {
|
|
208
|
+
return { ...container, stats: null };
|
|
209
|
+
}
|
|
210
|
+
const stats = await instance.client.getContainerLiveStats(detail.endpointId, container.id).catch(() => null);
|
|
211
|
+
return { ...container, stats };
|
|
212
|
+
})
|
|
213
|
+
) : baseContainers;
|
|
214
|
+
const health = (0, import_PortainerClient.summarizeContainersHealth)(containers);
|
|
215
|
+
let totalCpuPercent = 0;
|
|
216
|
+
let totalMemUsageBytes = 0;
|
|
217
|
+
let memLimitBytes = 0;
|
|
218
|
+
let totalNetRxBytes = 0;
|
|
219
|
+
let totalNetTxBytes = 0;
|
|
220
|
+
for (const item of containers) {
|
|
221
|
+
if (item.stats) {
|
|
222
|
+
totalCpuPercent += item.stats.cpuPercent;
|
|
223
|
+
totalMemUsageBytes += item.stats.memUsageBytes;
|
|
224
|
+
if (item.stats.memLimitBytes > memLimitBytes) {
|
|
225
|
+
memLimitBytes = item.stats.memLimitBytes;
|
|
226
|
+
}
|
|
227
|
+
totalNetRxBytes += item.stats.netRxBytes;
|
|
228
|
+
totalNetTxBytes += item.stats.netTxBytes;
|
|
229
|
+
}
|
|
230
|
+
}
|
|
231
|
+
const totalMemPercent = memLimitBytes > 0 ? Math.round((totalMemUsageBytes / memLimitBytes * 100 + Number.EPSILON) * 100) / 100 : 0;
|
|
232
|
+
const overview = {
|
|
233
|
+
detail: {
|
|
234
|
+
...detail,
|
|
235
|
+
env: detail.env.map((pair) => {
|
|
236
|
+
const sensitive = (0, import_env.isLikelySensitiveKey)(pair.name);
|
|
237
|
+
return {
|
|
238
|
+
name: pair.name,
|
|
239
|
+
value: sensitive ? import_constants.SECRET_MASK : pair.value,
|
|
240
|
+
hasExistingValue: pair.value.length > 0,
|
|
241
|
+
sensitive
|
|
242
|
+
};
|
|
243
|
+
})
|
|
244
|
+
},
|
|
245
|
+
stackFileContent,
|
|
246
|
+
containers,
|
|
247
|
+
summary: {
|
|
248
|
+
...health,
|
|
249
|
+
totalCpuPercent: Math.round((totalCpuPercent + Number.EPSILON) * 100) / 100,
|
|
250
|
+
totalMemUsageBytes,
|
|
251
|
+
memLimitBytes,
|
|
252
|
+
totalMemPercent,
|
|
253
|
+
totalNetRxBytes,
|
|
254
|
+
totalNetTxBytes
|
|
255
|
+
},
|
|
256
|
+
sampledAt: (/* @__PURE__ */ new Date()).toISOString()
|
|
257
|
+
};
|
|
258
|
+
ctx.body = overview;
|
|
259
|
+
} catch (error) {
|
|
260
|
+
sendPortainerError(ctx, error);
|
|
261
|
+
}
|
|
262
|
+
await next();
|
|
263
|
+
},
|
|
264
|
+
async getContainerLogs(ctx, next) {
|
|
265
|
+
const instanceId = getRequestParam(ctx, "instanceId");
|
|
266
|
+
const rawEndpointId = getRequestParam(ctx, "endpointId");
|
|
267
|
+
const rawContainerId = getRequestParam(ctx, "containerId");
|
|
268
|
+
const rawTail = getRequestParam(ctx, "tail");
|
|
269
|
+
try {
|
|
270
|
+
const instance = await (0, import_helpers.resolvePortainerInstance)(app, instanceId ?? null);
|
|
271
|
+
const endpointId = (0, import_PortainerClient.assertPositiveInt)(rawEndpointId, "Environment (Endpoint) ID");
|
|
272
|
+
const containerId = (0, import_PortainerClient.assertValidContainerId)(String(rawContainerId ?? ""));
|
|
273
|
+
const tail = Math.min(1e3, Math.max(10, Math.trunc(Number(rawTail) || 100)));
|
|
274
|
+
const logs = await instance.client.getContainerLogs(endpointId, containerId, tail);
|
|
275
|
+
ctx.body = {
|
|
276
|
+
containerId,
|
|
277
|
+
tail,
|
|
278
|
+
logs,
|
|
279
|
+
fetchedAt: (/* @__PURE__ */ new Date()).toISOString()
|
|
280
|
+
};
|
|
281
|
+
} catch (error) {
|
|
282
|
+
sendPortainerError(ctx, error);
|
|
283
|
+
}
|
|
284
|
+
await next();
|
|
285
|
+
},
|
|
286
|
+
async controlStack(ctx, next) {
|
|
287
|
+
const instanceId = getRequestParam(ctx, "instanceId");
|
|
288
|
+
const rawEndpointId = getRequestParam(ctx, "endpointId");
|
|
289
|
+
const rawStackId = getRequestParam(ctx, "stackId");
|
|
290
|
+
const operation = String(getRequestParam(ctx, "operation") ?? "").trim().toLowerCase();
|
|
291
|
+
try {
|
|
292
|
+
if (operation !== "start" && operation !== "stop") {
|
|
293
|
+
ctx.throw(400, ctx.t("Operation must be start or stop", { ns: import_constants.PLUGIN_NAMESPACE }));
|
|
294
|
+
}
|
|
295
|
+
const instance = await (0, import_helpers.resolvePortainerInstance)(app, instanceId ?? null);
|
|
296
|
+
const endpointId = (0, import_PortainerClient.assertPositiveInt)(rawEndpointId, "Environment (Endpoint) ID");
|
|
297
|
+
const stackId = (0, import_PortainerClient.assertPositiveInt)(rawStackId, "Stack ID");
|
|
298
|
+
const initial = operation === "start" ? await instance.client.startStack(stackId, endpointId) : await instance.client.stopStack(stackId, endpointId);
|
|
299
|
+
const settled = await instance.client.waitForStackSettlement(stackId, initial, { timeoutMs: 6e4 });
|
|
300
|
+
ctx.body = {
|
|
301
|
+
ok: true,
|
|
302
|
+
stackId,
|
|
303
|
+
endpointId,
|
|
304
|
+
operation,
|
|
305
|
+
status: Number((settled == null ? void 0 : settled.Status) ?? (operation === "start" ? 1 : 2))
|
|
306
|
+
};
|
|
307
|
+
} catch (error) {
|
|
308
|
+
sendPortainerError(ctx, error);
|
|
309
|
+
}
|
|
310
|
+
await next();
|
|
186
311
|
}
|
|
187
312
|
};
|
|
188
313
|
}
|
package/dist/server/plugin.js
CHANGED
|
@@ -38,7 +38,14 @@ var import_PortainerStackControlInstruction = require("./instructions/PortainerS
|
|
|
38
38
|
var import_PortainerStackRedeployInstruction = require("./instructions/PortainerStackRedeployInstruction");
|
|
39
39
|
var import_PortainerClient = require("./services/PortainerClient");
|
|
40
40
|
const ENCRYPTED_FIELDS = ["apiKey", "gitAccessToken"];
|
|
41
|
-
const METADATA_READ_ACTIONS = [
|
|
41
|
+
const METADATA_READ_ACTIONS = [
|
|
42
|
+
"listInstances",
|
|
43
|
+
"listEndpoints",
|
|
44
|
+
"listStacks",
|
|
45
|
+
"getStackDetail",
|
|
46
|
+
"getStackOverview",
|
|
47
|
+
"getContainerLogs"
|
|
48
|
+
];
|
|
42
49
|
function maskSecretFields(payload) {
|
|
43
50
|
if (!payload || typeof payload !== "object") {
|
|
44
51
|
return payload;
|
|
@@ -39,9 +39,12 @@ __export(PortainerClient_exports, {
|
|
|
39
39
|
PortainerApiError: () => PortainerApiError,
|
|
40
40
|
PortainerClient: () => PortainerClient,
|
|
41
41
|
assertPositiveInt: () => assertPositiveInt,
|
|
42
|
+
assertValidContainerId: () => assertValidContainerId,
|
|
42
43
|
assertValidPortainerUrl: () => assertValidPortainerUrl,
|
|
43
44
|
assertValidWebhookId: () => assertValidWebhookId,
|
|
44
45
|
clampTimeoutMs: () => clampTimeoutMs,
|
|
46
|
+
computeDockerContainerStats: () => computeDockerContainerStats,
|
|
47
|
+
demuxDockerLogBuffer: () => demuxDockerLogBuffer,
|
|
45
48
|
summarizeContainersHealth: () => summarizeContainersHealth,
|
|
46
49
|
toStackDetail: () => toStackDetail,
|
|
47
50
|
toStackSummary: () => toStackSummary
|
|
@@ -98,6 +101,92 @@ function assertValidWebhookId(rawWebhookId) {
|
|
|
98
101
|
}
|
|
99
102
|
return trimmed;
|
|
100
103
|
}
|
|
104
|
+
function assertValidContainerId(rawContainerId) {
|
|
105
|
+
const trimmed = String(rawContainerId ?? "").trim();
|
|
106
|
+
if (!trimmed || !/^[a-fA-F0-9]{12,64}$/.test(trimmed)) {
|
|
107
|
+
throw new PortainerApiError("Container ID must be a 12-64 character hexadecimal identifier", {
|
|
108
|
+
code: "INVALID_PARAM"
|
|
109
|
+
});
|
|
110
|
+
}
|
|
111
|
+
return trimmed;
|
|
112
|
+
}
|
|
113
|
+
function computeDockerContainerStats(raw) {
|
|
114
|
+
var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j, _k, _l, _m, _n, _o, _p, _q;
|
|
115
|
+
const cpuTotal = Number(((_b = (_a = raw == null ? void 0 : raw.cpu_stats) == null ? void 0 : _a.cpu_usage) == null ? void 0 : _b.total_usage) ?? 0);
|
|
116
|
+
const preCpuTotal = Number(((_d = (_c = raw == null ? void 0 : raw.precpu_stats) == null ? void 0 : _c.cpu_usage) == null ? void 0 : _d.total_usage) ?? 0);
|
|
117
|
+
const sysCpu = Number(((_e = raw == null ? void 0 : raw.cpu_stats) == null ? void 0 : _e.system_cpu_usage) ?? 0);
|
|
118
|
+
const preSysCpu = Number(((_f = raw == null ? void 0 : raw.precpu_stats) == null ? void 0 : _f.system_cpu_usage) ?? 0);
|
|
119
|
+
const cpuDelta = cpuTotal - preCpuTotal;
|
|
120
|
+
const sysDelta = sysCpu - preSysCpu;
|
|
121
|
+
const perCpu = (_h = (_g = raw == null ? void 0 : raw.cpu_stats) == null ? void 0 : _g.cpu_usage) == null ? void 0 : _h.percpu_usage;
|
|
122
|
+
const onlineCpus = Number(((_i = raw == null ? void 0 : raw.cpu_stats) == null ? void 0 : _i.online_cpus) ?? 0) || (Array.isArray(perCpu) ? perCpu.length : 0) || 1;
|
|
123
|
+
const cpuPercent = cpuDelta > 0 && sysDelta > 0 ? Math.round((cpuDelta / sysDelta * onlineCpus * 100 + Number.EPSILON) * 100) / 100 : 0;
|
|
124
|
+
const rawMemUsage = Number(((_j = raw == null ? void 0 : raw.memory_stats) == null ? void 0 : _j.usage) ?? 0);
|
|
125
|
+
const inactiveFile = Number(
|
|
126
|
+
((_l = (_k = raw == null ? void 0 : raw.memory_stats) == null ? void 0 : _k.stats) == null ? void 0 : _l.inactive_file) ?? ((_n = (_m = raw == null ? void 0 : raw.memory_stats) == null ? void 0 : _m.stats) == null ? void 0 : _n.total_inactive_file) ?? 0
|
|
127
|
+
);
|
|
128
|
+
const memUsageBytes = Math.max(0, rawMemUsage - inactiveFile);
|
|
129
|
+
const memLimitBytes = Math.max(0, Number(((_o = raw == null ? void 0 : raw.memory_stats) == null ? void 0 : _o.limit) ?? 0));
|
|
130
|
+
const memPercent = memLimitBytes > 0 ? Math.round((memUsageBytes / memLimitBytes * 100 + Number.EPSILON) * 100) / 100 : 0;
|
|
131
|
+
let netRxBytes = 0;
|
|
132
|
+
let netTxBytes = 0;
|
|
133
|
+
if ((raw == null ? void 0 : raw.networks) && typeof raw.networks === "object") {
|
|
134
|
+
for (const iface of Object.values(raw.networks)) {
|
|
135
|
+
netRxBytes += Math.max(0, Number((iface == null ? void 0 : iface.rx_bytes) ?? 0));
|
|
136
|
+
netTxBytes += Math.max(0, Number((iface == null ? void 0 : iface.tx_bytes) ?? 0));
|
|
137
|
+
}
|
|
138
|
+
}
|
|
139
|
+
let blockReadBytes = 0;
|
|
140
|
+
let blockWriteBytes = 0;
|
|
141
|
+
const ioEntries = (_p = raw == null ? void 0 : raw.blkio_stats) == null ? void 0 : _p.io_service_bytes_recursive;
|
|
142
|
+
if (Array.isArray(ioEntries)) {
|
|
143
|
+
for (const entry of ioEntries) {
|
|
144
|
+
const op = String((entry == null ? void 0 : entry.op) ?? "").toLowerCase();
|
|
145
|
+
const val = Math.max(0, Number((entry == null ? void 0 : entry.value) ?? 0));
|
|
146
|
+
if (op === "read") {
|
|
147
|
+
blockReadBytes += val;
|
|
148
|
+
} else if (op === "write") {
|
|
149
|
+
blockWriteBytes += val;
|
|
150
|
+
}
|
|
151
|
+
}
|
|
152
|
+
}
|
|
153
|
+
const pids = Math.max(0, Number(((_q = raw == null ? void 0 : raw.pids_stats) == null ? void 0 : _q.current) ?? 0));
|
|
154
|
+
return {
|
|
155
|
+
cpuPercent,
|
|
156
|
+
memUsageBytes,
|
|
157
|
+
memLimitBytes,
|
|
158
|
+
memPercent,
|
|
159
|
+
netRxBytes,
|
|
160
|
+
netTxBytes,
|
|
161
|
+
blockReadBytes,
|
|
162
|
+
blockWriteBytes,
|
|
163
|
+
pids
|
|
164
|
+
};
|
|
165
|
+
}
|
|
166
|
+
function demuxDockerLogBuffer(buf) {
|
|
167
|
+
if (!buf || buf.length === 0) {
|
|
168
|
+
return "";
|
|
169
|
+
}
|
|
170
|
+
const looksMultiplexed = buf.length >= 8 && (buf[0] === 0 || buf[0] === 1 || buf[0] === 2) && buf[1] === 0 && buf[2] === 0 && buf[3] === 0;
|
|
171
|
+
if (!looksMultiplexed) {
|
|
172
|
+
return buf.toString("utf8");
|
|
173
|
+
}
|
|
174
|
+
const parts = [];
|
|
175
|
+
let offset = 0;
|
|
176
|
+
while (offset + 8 <= buf.length) {
|
|
177
|
+
const streamType = buf[offset];
|
|
178
|
+
if (streamType !== 0 && streamType !== 1 && streamType !== 2 || buf[offset + 1] !== 0 || buf[offset + 2] !== 0 || buf[offset + 3] !== 0) {
|
|
179
|
+
parts.push(buf.subarray(offset));
|
|
180
|
+
break;
|
|
181
|
+
}
|
|
182
|
+
const frameLen = buf.readUInt32BE(offset + 4);
|
|
183
|
+
const payloadStart = offset + 8;
|
|
184
|
+
const payloadEnd = Math.min(buf.length, payloadStart + frameLen);
|
|
185
|
+
parts.push(buf.subarray(payloadStart, payloadEnd));
|
|
186
|
+
offset = payloadEnd;
|
|
187
|
+
}
|
|
188
|
+
return Buffer.concat(parts).toString("utf8");
|
|
189
|
+
}
|
|
101
190
|
function clampTimeoutMs(timeoutMs, fallback = import_constants.DEFAULT_TIMEOUT_MS) {
|
|
102
191
|
const num = Number(timeoutMs);
|
|
103
192
|
if (!Number.isFinite(num) || num <= 0) {
|
|
@@ -135,16 +224,30 @@ function toStackSummary(stack) {
|
|
|
135
224
|
};
|
|
136
225
|
}
|
|
137
226
|
function toStackDetail(stack) {
|
|
138
|
-
var _a;
|
|
139
227
|
const summary = toStackSummary(stack);
|
|
140
|
-
const
|
|
228
|
+
const git = stack.GitConfig;
|
|
229
|
+
const auth = git == null ? void 0 : git.Authentication;
|
|
141
230
|
const credId = Number((auth == null ? void 0 : auth.GitCredentialID) ?? 0);
|
|
231
|
+
const deployments = Array.isArray(stack.DeploymentStatus) ? stack.DeploymentStatus.map((item) => ({
|
|
232
|
+
status: Number((item == null ? void 0 : item.Status) ?? 0),
|
|
233
|
+
time: typeof (item == null ? void 0 : item.Time) === "number" && item.Time > 0 ? item.Time : void 0,
|
|
234
|
+
message: (item == null ? void 0 : item.Message) ? String(item.Message) : void 0
|
|
235
|
+
})) : void 0;
|
|
142
236
|
return {
|
|
143
237
|
...summary,
|
|
144
238
|
env: normalizeEnvArray(stack.Env),
|
|
145
239
|
hasSavedGitCredential: credId > 0,
|
|
146
240
|
gitCredentialId: credId > 0 ? credId : 0,
|
|
147
|
-
gitUsername: (auth == null ? void 0 : auth.Username) ? String(auth.Username) : void 0
|
|
241
|
+
gitUsername: (auth == null ? void 0 : auth.Username) ? String(auth.Username) : void 0,
|
|
242
|
+
entryPoint: stack.EntryPoint ? String(stack.EntryPoint) : void 0,
|
|
243
|
+
projectPath: stack.ProjectPath ? String(stack.ProjectPath) : void 0,
|
|
244
|
+
createdAt: typeof stack.CreationDate === "number" && stack.CreationDate > 0 ? stack.CreationDate : void 0,
|
|
245
|
+
createdBy: stack.CreatedBy ? String(stack.CreatedBy) : void 0,
|
|
246
|
+
updatedAt: typeof stack.UpdateDate === "number" && stack.UpdateDate > 0 ? stack.UpdateDate : void 0,
|
|
247
|
+
updatedBy: stack.UpdatedBy ? String(stack.UpdatedBy) : void 0,
|
|
248
|
+
gitConfigFilePath: (git == null ? void 0 : git.ConfigFilePath) ? String(git.ConfigFilePath) : void 0,
|
|
249
|
+
gitCommitHash: (git == null ? void 0 : git.ConfigHash) ? String(git.ConfigHash) : void 0,
|
|
250
|
+
deployments
|
|
148
251
|
};
|
|
149
252
|
}
|
|
150
253
|
class PortainerClient {
|
|
@@ -218,8 +321,13 @@ class PortainerClient {
|
|
|
218
321
|
const chunks = [];
|
|
219
322
|
res.on("data", (chunk) => chunks.push(Buffer.isBuffer(chunk) ? chunk : Buffer.from(chunk)));
|
|
220
323
|
res.on("end", () => {
|
|
221
|
-
const
|
|
324
|
+
const fullBuffer = Buffer.concat(chunks);
|
|
222
325
|
const status = res.statusCode ?? 500;
|
|
326
|
+
if (status >= 200 && status < 300 && options.rawBuffer) {
|
|
327
|
+
finish(() => resolve(fullBuffer));
|
|
328
|
+
return;
|
|
329
|
+
}
|
|
330
|
+
const rawText = fullBuffer.toString("utf8");
|
|
223
331
|
let parsedBody = rawText;
|
|
224
332
|
if (rawText.trim()) {
|
|
225
333
|
try {
|
|
@@ -462,20 +570,81 @@ class PortainerClient {
|
|
|
462
570
|
return [];
|
|
463
571
|
}
|
|
464
572
|
return raw.map((container) => {
|
|
573
|
+
var _a, _b;
|
|
465
574
|
const state = String(container.State ?? "unknown").toLowerCase();
|
|
466
575
|
const status = String(container.Status ?? "");
|
|
467
576
|
const unhealthy = /\(unhealthy\)/i.test(status) || state === "restarting" || state === "dead";
|
|
468
577
|
const firstName = Array.isArray(container.Names) && container.Names[0] ? container.Names[0] : "";
|
|
578
|
+
const service = (_a = container.Labels) == null ? void 0 : _a["com.docker.compose.service"];
|
|
579
|
+
const portsSet = /* @__PURE__ */ new Set();
|
|
580
|
+
if (Array.isArray(container.Ports)) {
|
|
581
|
+
for (const p of container.Ports) {
|
|
582
|
+
const proto = p.Type || "tcp";
|
|
583
|
+
if (p.PublicPort && p.PrivatePort) {
|
|
584
|
+
const hostPrefix = p.IP ? `${p.IP}:` : "";
|
|
585
|
+
portsSet.add(`${hostPrefix}${p.PublicPort}->${p.PrivatePort}/${proto}`);
|
|
586
|
+
} else if (p.PrivatePort) {
|
|
587
|
+
portsSet.add(`${p.PrivatePort}/${proto}`);
|
|
588
|
+
}
|
|
589
|
+
}
|
|
590
|
+
}
|
|
591
|
+
const ipAddresses = [];
|
|
592
|
+
if (((_b = container.NetworkSettings) == null ? void 0 : _b.Networks) && typeof container.NetworkSettings.Networks === "object") {
|
|
593
|
+
for (const net of Object.values(container.NetworkSettings.Networks)) {
|
|
594
|
+
if ((net == null ? void 0 : net.IPAddress) && !ipAddresses.includes(net.IPAddress)) {
|
|
595
|
+
ipAddresses.push(net.IPAddress);
|
|
596
|
+
}
|
|
597
|
+
}
|
|
598
|
+
}
|
|
469
599
|
return {
|
|
470
600
|
id: String(container.Id ?? "").slice(0, 12),
|
|
471
601
|
name: firstName.replace(/^\/+/, ""),
|
|
602
|
+
service: service ? String(service) : void 0,
|
|
472
603
|
image: String(container.Image ?? ""),
|
|
473
604
|
state,
|
|
474
605
|
status,
|
|
475
|
-
healthy: state === "running" && !unhealthy
|
|
606
|
+
healthy: state === "running" && !unhealthy,
|
|
607
|
+
created: typeof container.Created === "number" && container.Created > 0 ? container.Created : void 0,
|
|
608
|
+
ports: Array.from(portsSet),
|
|
609
|
+
ipAddresses
|
|
476
610
|
};
|
|
477
611
|
});
|
|
478
612
|
}
|
|
613
|
+
async getContainerLiveStats(endpointId, containerId, signal) {
|
|
614
|
+
const validEndpointId = assertPositiveInt(endpointId, "Environment (Endpoint) ID");
|
|
615
|
+
const validContainerId = assertValidContainerId(containerId);
|
|
616
|
+
const raw = await this.request({
|
|
617
|
+
method: "GET",
|
|
618
|
+
path: `/api/endpoints/${encodeURIComponent(String(validEndpointId))}/docker/containers/${encodeURIComponent(
|
|
619
|
+
validContainerId
|
|
620
|
+
)}/stats`,
|
|
621
|
+
query: { stream: "false" },
|
|
622
|
+
timeoutMs: 1e4,
|
|
623
|
+
signal
|
|
624
|
+
});
|
|
625
|
+
return computeDockerContainerStats(raw);
|
|
626
|
+
}
|
|
627
|
+
async getContainerLogs(endpointId, containerId, tail = 100, signal) {
|
|
628
|
+
const validEndpointId = assertPositiveInt(endpointId, "Environment (Endpoint) ID");
|
|
629
|
+
const validContainerId = assertValidContainerId(containerId);
|
|
630
|
+
const clampedTail = Math.min(1e3, Math.max(10, Math.trunc(Number(tail) || 100)));
|
|
631
|
+
const buf = await this.request({
|
|
632
|
+
method: "GET",
|
|
633
|
+
path: `/api/endpoints/${encodeURIComponent(String(validEndpointId))}/docker/containers/${encodeURIComponent(
|
|
634
|
+
validContainerId
|
|
635
|
+
)}/logs`,
|
|
636
|
+
query: {
|
|
637
|
+
stdout: 1,
|
|
638
|
+
stderr: 1,
|
|
639
|
+
tail: clampedTail,
|
|
640
|
+
timestamps: 1
|
|
641
|
+
},
|
|
642
|
+
rawBuffer: true,
|
|
643
|
+
timeoutMs: 15e3,
|
|
644
|
+
signal
|
|
645
|
+
});
|
|
646
|
+
return demuxDockerLogBuffer(buf);
|
|
647
|
+
}
|
|
479
648
|
}
|
|
480
649
|
function summarizeContainersHealth(containers) {
|
|
481
650
|
const totalCount = containers.length;
|
|
@@ -488,9 +657,12 @@ function summarizeContainersHealth(containers) {
|
|
|
488
657
|
PortainerApiError,
|
|
489
658
|
PortainerClient,
|
|
490
659
|
assertPositiveInt,
|
|
660
|
+
assertValidContainerId,
|
|
491
661
|
assertValidPortainerUrl,
|
|
492
662
|
assertValidWebhookId,
|
|
493
663
|
clampTimeoutMs,
|
|
664
|
+
computeDockerContainerStats,
|
|
665
|
+
demuxDockerLogBuffer,
|
|
494
666
|
summarizeContainersHealth,
|
|
495
667
|
toStackDetail,
|
|
496
668
|
toStackSummary
|
package/dist/shared/env.js
CHANGED
|
@@ -29,10 +29,12 @@ __export(env_exports, {
|
|
|
29
29
|
buildEffectiveStackEnv: () => buildEffectiveStackEnv,
|
|
30
30
|
isLikelySensitiveKey: () => isLikelySensitiveKey,
|
|
31
31
|
isValidEnvKey: () => isValidEnvKey,
|
|
32
|
+
isWorkflowVariableValue: () => isWorkflowVariableValue,
|
|
32
33
|
normalizeGitReference: () => normalizeGitReference,
|
|
33
34
|
parseDotEnvText: () => parseDotEnvText,
|
|
34
35
|
parseDynamicEnvInput: () => parseDynamicEnvInput,
|
|
35
|
-
stringifyEnvValue: () => stringifyEnvValue
|
|
36
|
+
stringifyEnvValue: () => stringifyEnvValue,
|
|
37
|
+
toFiniteNumber: () => toFiniteNumber
|
|
36
38
|
});
|
|
37
39
|
module.exports = __toCommonJS(env_exports);
|
|
38
40
|
var import_constants = require("./constants");
|
|
@@ -44,6 +46,19 @@ function isValidEnvKey(key) {
|
|
|
44
46
|
function isLikelySensitiveKey(key) {
|
|
45
47
|
return SENSITIVE_ENV_KEY_PATTERN.test(key);
|
|
46
48
|
}
|
|
49
|
+
function isWorkflowVariableValue(value) {
|
|
50
|
+
return typeof value === "string" && /^\{\{\s*[\s\S]+?\s*\}\}$/.test(value.trim());
|
|
51
|
+
}
|
|
52
|
+
function toFiniteNumber(value) {
|
|
53
|
+
if (typeof value === "number") {
|
|
54
|
+
return Number.isFinite(value) ? value : void 0;
|
|
55
|
+
}
|
|
56
|
+
if (typeof value === "string" && value.trim() !== "" && !isWorkflowVariableValue(value)) {
|
|
57
|
+
const parsed = Number(value);
|
|
58
|
+
return Number.isFinite(parsed) ? parsed : void 0;
|
|
59
|
+
}
|
|
60
|
+
return void 0;
|
|
61
|
+
}
|
|
47
62
|
function stripMatchingQuotes(raw) {
|
|
48
63
|
if (raw.length >= 2) {
|
|
49
64
|
const first = raw[0];
|
|
@@ -214,8 +229,10 @@ function normalizeGitReference(ref, fallback) {
|
|
|
214
229
|
buildEffectiveStackEnv,
|
|
215
230
|
isLikelySensitiveKey,
|
|
216
231
|
isValidEnvKey,
|
|
232
|
+
isWorkflowVariableValue,
|
|
217
233
|
normalizeGitReference,
|
|
218
234
|
parseDotEnvText,
|
|
219
235
|
parseDynamicEnvInput,
|
|
220
|
-
stringifyEnvValue
|
|
236
|
+
stringifyEnvValue,
|
|
237
|
+
toFiniteNumber
|
|
221
238
|
});
|
package/package.json
CHANGED
|
@@ -6,7 +6,7 @@
|
|
|
6
6
|
"description": "Workflow nodes and connection management for running, redeploying, and controlling Portainer stacks across environments.",
|
|
7
7
|
"description.zh-CN": "用于在多环境中运行、重新部署和控制 Portainer Stack 的工作流节点与连接管理插件。",
|
|
8
8
|
"description.vi-VN": "Cung cấp các node Workflow và quản lý kết nối để chạy, redeploy và kiểm soát Portainer Stack đa môi trường.",
|
|
9
|
-
"version": "0.
|
|
9
|
+
"version": "0.2.0",
|
|
10
10
|
"license": "Apache-2.0",
|
|
11
11
|
"main": "dist/server/index.js",
|
|
12
12
|
"keywords": [
|
|
@@ -44,7 +44,7 @@
|
|
|
44
44
|
"url": "git+https://github.com/OrgGem/nocobase-beta.git",
|
|
45
45
|
"directory": "packages/plugins/plugin-workflow-portainer"
|
|
46
46
|
},
|
|
47
|
-
"gitHead": "
|
|
47
|
+
"gitHead": "80fa4ca378070b31799b572a8cdc1d4fbbac00d5",
|
|
48
48
|
"publishConfig": {
|
|
49
49
|
"access": "public",
|
|
50
50
|
"registry": "https://registry.npmjs.org/"
|