plugin-workflow-portainer 0.0.0-stage → 0.1.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +176 -0
- package/README.md +31 -3
- package/client-v2.js +1 -0
- package/client.js +1 -0
- package/dist/client/127.5012da93825a6e5c.js +10 -0
- package/dist/client/57.ace9538136438718.js +10 -0
- package/dist/client/65.ec4a55173511c06d.js +10 -0
- package/dist/client/660.546c702d1ddf7eff.js +10 -0
- package/dist/client/index.js +10 -0
- package/dist/client-v2/127.0ec4dce7b13750e9.js +10 -0
- package/dist/client-v2/57.e7cfc50fb651ac14.js +10 -0
- package/dist/client-v2/65.9c745ea32ac96e98.js +10 -0
- package/dist/client-v2/660.29ae3c3b4040039d.js +10 -0
- package/dist/client-v2/index.js +10 -0
- package/dist/externalVersion.js +20 -0
- package/dist/index.js +48 -0
- package/dist/locale/en-US.json +151 -0
- package/dist/locale/vi-VN.json +151 -0
- package/dist/locale/zh-CN.json +151 -0
- package/dist/node_modules/joi/dist/joi-browser.min.js +1 -0
- package/dist/node_modules/joi/lib/annotate.js +175 -0
- package/dist/node_modules/joi/lib/base.js +1069 -0
- package/dist/node_modules/joi/lib/cache.js +143 -0
- package/dist/node_modules/joi/lib/common.js +216 -0
- package/dist/node_modules/joi/lib/compile.js +283 -0
- package/dist/node_modules/joi/lib/errors.js +271 -0
- package/dist/node_modules/joi/lib/extend.js +312 -0
- package/dist/node_modules/joi/lib/index.d.ts +2365 -0
- package/dist/node_modules/joi/lib/index.js +1 -0
- package/dist/node_modules/joi/lib/manifest.js +476 -0
- package/dist/node_modules/joi/lib/messages.js +207 -0
- package/dist/node_modules/joi/lib/modify.js +267 -0
- package/dist/node_modules/joi/lib/ref.js +414 -0
- package/dist/node_modules/joi/lib/schemas.js +302 -0
- package/dist/node_modules/joi/lib/state.js +166 -0
- package/dist/node_modules/joi/lib/template.js +463 -0
- package/dist/node_modules/joi/lib/trace.js +346 -0
- package/dist/node_modules/joi/lib/types/alternatives.js +364 -0
- package/dist/node_modules/joi/lib/types/any.js +174 -0
- package/dist/node_modules/joi/lib/types/array.js +809 -0
- package/dist/node_modules/joi/lib/types/binary.js +100 -0
- package/dist/node_modules/joi/lib/types/boolean.js +150 -0
- package/dist/node_modules/joi/lib/types/date.js +233 -0
- package/dist/node_modules/joi/lib/types/function.js +93 -0
- package/dist/node_modules/joi/lib/types/keys.js +1084 -0
- package/dist/node_modules/joi/lib/types/link.js +184 -0
- package/dist/node_modules/joi/lib/types/number.js +363 -0
- package/dist/node_modules/joi/lib/types/object.js +22 -0
- package/dist/node_modules/joi/lib/types/string.js +850 -0
- package/dist/node_modules/joi/lib/types/symbol.js +102 -0
- package/dist/node_modules/joi/lib/validator.js +750 -0
- package/dist/node_modules/joi/lib/values.js +263 -0
- package/dist/node_modules/joi/node_modules/@hapi/topo/lib/index.d.ts +60 -0
- package/dist/node_modules/joi/node_modules/@hapi/topo/lib/index.js +225 -0
- package/dist/node_modules/joi/node_modules/@hapi/topo/package.json +30 -0
- package/dist/node_modules/joi/package.json +1 -0
- package/dist/server/actions/portainer.js +192 -0
- package/dist/server/collections/portainer-instances.js +54 -0
- package/dist/server/index.js +54 -0
- package/dist/server/instructions/PortainerStackControlInstruction.js +156 -0
- package/dist/server/instructions/PortainerStackRedeployInstruction.js +254 -0
- package/dist/server/instructions/helpers.js +211 -0
- package/dist/server/plugin.js +170 -0
- package/dist/server/services/PortainerClient.js +497 -0
- package/dist/shared/collection.js +57 -0
- package/dist/shared/constants.js +66 -0
- package/dist/shared/env.js +221 -0
- package/dist/shared/types.js +24 -0
- package/package.json +50 -4
- package/server.js +1 -0
- package/src/client/index.tsx +50 -0
- package/src/client/instructions.tsx +76 -0
- package/src/client-v2/__tests__/workflow-registration.test.tsx +132 -0
- package/src/client-v2/components/ControlFieldset.tsx +46 -0
- package/src/client-v2/components/PortainerEnvEditor.tsx +223 -0
- package/src/client-v2/components/PortainerSettingsPage.tsx +671 -0
- package/src/client-v2/components/PortainerTargetFields.tsx +317 -0
- package/src/client-v2/components/RedeployFieldset.tsx +123 -0
- package/src/client-v2/index.tsx +50 -0
- package/src/client-v2/instructions.tsx +162 -0
- package/src/client-v2/locale.ts +24 -0
- package/src/index.ts +11 -0
- package/src/locale/en-US.json +151 -0
- package/src/locale/vi-VN.json +151 -0
- package/src/locale/zh-CN.json +151 -0
- package/src/server/__tests__/portainer-workflow.test.ts +455 -0
- package/src/server/actions/portainer.ts +196 -0
- package/src/server/collections/portainer-instances.ts +34 -0
- package/src/server/index.ts +13 -0
- package/src/server/instructions/PortainerStackControlInstruction.ts +139 -0
- package/src/server/instructions/PortainerStackRedeployInstruction.ts +255 -0
- package/src/server/instructions/helpers.ts +237 -0
- package/src/server/plugin.ts +167 -0
- package/src/server/services/PortainerClient.ts +589 -0
- package/src/shared/collection.ts +32 -0
- package/src/shared/constants.ts +25 -0
- package/src/shared/env.ts +228 -0
- package/src/shared/types.ts +105 -0
|
@@ -0,0 +1,192 @@
|
|
|
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
|
+
var __defProp = Object.defineProperty;
|
|
11
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
12
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
13
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
14
|
+
var __export = (target, all) => {
|
|
15
|
+
for (var name in all)
|
|
16
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
17
|
+
};
|
|
18
|
+
var __copyProps = (to, from, except, desc) => {
|
|
19
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
20
|
+
for (let key of __getOwnPropNames(from))
|
|
21
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
22
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
23
|
+
}
|
|
24
|
+
return to;
|
|
25
|
+
};
|
|
26
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
27
|
+
var portainer_exports = {};
|
|
28
|
+
__export(portainer_exports, {
|
|
29
|
+
createPortainerResourceActions: () => createPortainerResourceActions
|
|
30
|
+
});
|
|
31
|
+
module.exports = __toCommonJS(portainer_exports);
|
|
32
|
+
var import_constants = require("../../shared/constants");
|
|
33
|
+
var import_env = require("../../shared/env");
|
|
34
|
+
var import_helpers = require("../instructions/helpers");
|
|
35
|
+
var import_PortainerClient = require("../services/PortainerClient");
|
|
36
|
+
function getRequestParam(ctx, key) {
|
|
37
|
+
var _a;
|
|
38
|
+
const params = ((_a = ctx.action) == null ? void 0 : _a.params) ?? {};
|
|
39
|
+
const values = typeof params.values === "object" && params.values !== null ? params.values : {};
|
|
40
|
+
if (typeof values[key] !== "undefined") {
|
|
41
|
+
return values[key];
|
|
42
|
+
}
|
|
43
|
+
return params[key];
|
|
44
|
+
}
|
|
45
|
+
function sendPortainerError(ctx, error) {
|
|
46
|
+
if (error instanceof import_PortainerClient.PortainerApiError) {
|
|
47
|
+
const status = error.code === "INVALID_URL" || error.code === "INVALID_PARAM" || error.code === "MISSING_API_KEY" ? 400 : error.code === "INSTANCE_NOT_FOUND" ? 404 : error.status && error.status >= 400 && error.status < 500 ? error.status : 502;
|
|
48
|
+
ctx.throw(status, error.message);
|
|
49
|
+
}
|
|
50
|
+
throw error;
|
|
51
|
+
}
|
|
52
|
+
function createPortainerResourceActions(app) {
|
|
53
|
+
return {
|
|
54
|
+
async listInstances(ctx, next) {
|
|
55
|
+
const repo = app.db.getRepository(import_constants.PORTAINER_INSTANCES_COLLECTION);
|
|
56
|
+
const rows = await repo.find({
|
|
57
|
+
filter: { enabled: true },
|
|
58
|
+
sort: ["-isDefault", "id"]
|
|
59
|
+
});
|
|
60
|
+
const items = rows.map((row) => ({
|
|
61
|
+
id: Number(row.get("id")),
|
|
62
|
+
name: String(row.get("name") ?? ""),
|
|
63
|
+
baseUrl: String(row.get("baseUrl") ?? ""),
|
|
64
|
+
isDefault: Boolean(row.get("isDefault")),
|
|
65
|
+
enabled: Boolean(row.get("enabled")),
|
|
66
|
+
defaultTimeoutMs: Number(row.get("defaultTimeoutMs") ?? 6e5),
|
|
67
|
+
lastHealthStatus: row.get("lastHealthStatus") ?? null,
|
|
68
|
+
lastVersion: row.get("lastVersion") ?? null
|
|
69
|
+
}));
|
|
70
|
+
ctx.body = items;
|
|
71
|
+
await next();
|
|
72
|
+
},
|
|
73
|
+
async testConnection(ctx, next) {
|
|
74
|
+
const filterByTk = getRequestParam(ctx, "filterByTk") ?? getRequestParam(ctx, "instanceId");
|
|
75
|
+
try {
|
|
76
|
+
const instance = await (0, import_helpers.resolvePortainerInstance)(app, filterByTk ?? null);
|
|
77
|
+
const status = await instance.client.getStatus();
|
|
78
|
+
const endpoints = await instance.client.listEndpoints();
|
|
79
|
+
const version = String((status == null ? void 0 : status.Version) ?? "unknown");
|
|
80
|
+
await app.db.getRepository(import_constants.PORTAINER_INSTANCES_COLLECTION).update({
|
|
81
|
+
filterByTk: instance.id,
|
|
82
|
+
values: {
|
|
83
|
+
lastHealthStatus: "ok",
|
|
84
|
+
lastVersion: version,
|
|
85
|
+
lastCheckedAt: /* @__PURE__ */ new Date()
|
|
86
|
+
}
|
|
87
|
+
});
|
|
88
|
+
ctx.body = {
|
|
89
|
+
ok: true,
|
|
90
|
+
instanceId: instance.id,
|
|
91
|
+
version,
|
|
92
|
+
endpointCount: endpoints.length,
|
|
93
|
+
endpoints
|
|
94
|
+
};
|
|
95
|
+
} catch (error) {
|
|
96
|
+
if (filterByTk) {
|
|
97
|
+
const numId = Number(filterByTk);
|
|
98
|
+
if (Number.isSafeInteger(numId) && numId > 0) {
|
|
99
|
+
await app.db.getRepository(import_constants.PORTAINER_INSTANCES_COLLECTION).update({
|
|
100
|
+
filterByTk: numId,
|
|
101
|
+
values: {
|
|
102
|
+
lastHealthStatus: "error",
|
|
103
|
+
lastCheckedAt: /* @__PURE__ */ new Date()
|
|
104
|
+
}
|
|
105
|
+
}).catch(() => {
|
|
106
|
+
});
|
|
107
|
+
}
|
|
108
|
+
}
|
|
109
|
+
sendPortainerError(ctx, error);
|
|
110
|
+
}
|
|
111
|
+
await next();
|
|
112
|
+
},
|
|
113
|
+
async testConnectionDraft(ctx, next) {
|
|
114
|
+
try {
|
|
115
|
+
const baseUrl = String(getRequestParam(ctx, "baseUrl") ?? "").trim();
|
|
116
|
+
let apiKey = String(getRequestParam(ctx, "apiKey") ?? "").trim();
|
|
117
|
+
const instanceId = getRequestParam(ctx, "id") ?? getRequestParam(ctx, "instanceId");
|
|
118
|
+
const allowInsecureTls = Boolean(getRequestParam(ctx, "allowInsecureTls"));
|
|
119
|
+
const timeoutMs = (0, import_PortainerClient.clampTimeoutMs)(Number(getRequestParam(ctx, "defaultTimeoutMs") ?? 15e3), 15e3);
|
|
120
|
+
if ((!apiKey || apiKey === import_constants.SECRET_MASK) && instanceId) {
|
|
121
|
+
const existing = await app.db.getRepository(import_constants.PORTAINER_INSTANCES_COLLECTION).findOne({ filterByTk: Number(instanceId) });
|
|
122
|
+
if (existing) {
|
|
123
|
+
apiKey = await (0, import_helpers.decryptIfNeeded)(app, existing.get("apiKey"));
|
|
124
|
+
}
|
|
125
|
+
}
|
|
126
|
+
const client = new import_PortainerClient.PortainerClient({ baseUrl, apiKey, allowInsecureTls, timeoutMs });
|
|
127
|
+
const status = await client.getStatus();
|
|
128
|
+
const endpoints = await client.listEndpoints();
|
|
129
|
+
ctx.body = {
|
|
130
|
+
ok: true,
|
|
131
|
+
version: String((status == null ? void 0 : status.Version) ?? "unknown"),
|
|
132
|
+
endpointCount: endpoints.length,
|
|
133
|
+
endpoints
|
|
134
|
+
};
|
|
135
|
+
} catch (error) {
|
|
136
|
+
sendPortainerError(ctx, error);
|
|
137
|
+
}
|
|
138
|
+
await next();
|
|
139
|
+
},
|
|
140
|
+
async listEndpoints(ctx, next) {
|
|
141
|
+
const instanceId = getRequestParam(ctx, "instanceId");
|
|
142
|
+
try {
|
|
143
|
+
const instance = await (0, import_helpers.resolvePortainerInstance)(app, instanceId ?? null);
|
|
144
|
+
ctx.body = await instance.client.listEndpoints();
|
|
145
|
+
} catch (error) {
|
|
146
|
+
sendPortainerError(ctx, error);
|
|
147
|
+
}
|
|
148
|
+
await next();
|
|
149
|
+
},
|
|
150
|
+
async listStacks(ctx, next) {
|
|
151
|
+
const instanceId = getRequestParam(ctx, "instanceId");
|
|
152
|
+
const rawEndpointId = getRequestParam(ctx, "endpointId");
|
|
153
|
+
try {
|
|
154
|
+
const instance = await (0, import_helpers.resolvePortainerInstance)(app, instanceId ?? null);
|
|
155
|
+
const endpointId = rawEndpointId !== null && typeof rawEndpointId !== "undefined" && String(rawEndpointId).trim() !== "" ? (0, import_PortainerClient.assertPositiveInt)(rawEndpointId, "Environment (Endpoint) ID") : null;
|
|
156
|
+
ctx.body = await instance.client.listStacks(endpointId);
|
|
157
|
+
} catch (error) {
|
|
158
|
+
sendPortainerError(ctx, error);
|
|
159
|
+
}
|
|
160
|
+
await next();
|
|
161
|
+
},
|
|
162
|
+
async getStackDetail(ctx, next) {
|
|
163
|
+
const instanceId = getRequestParam(ctx, "instanceId");
|
|
164
|
+
const rawStackId = getRequestParam(ctx, "stackId");
|
|
165
|
+
const maskValues = getRequestParam(ctx, "includeValues") !== true && getRequestParam(ctx, "includeValues") !== "true";
|
|
166
|
+
try {
|
|
167
|
+
if (rawStackId === null || typeof rawStackId === "undefined" || String(rawStackId).trim() === "") {
|
|
168
|
+
ctx.throw(400, ctx.t("Stack ID is required", { ns: import_constants.PLUGIN_NAMESPACE }));
|
|
169
|
+
}
|
|
170
|
+
const instance = await (0, import_helpers.resolvePortainerInstance)(app, instanceId ?? null);
|
|
171
|
+
const stackId = (0, import_PortainerClient.assertPositiveInt)(rawStackId, "Stack ID");
|
|
172
|
+
const detail = await instance.client.getStackDetail(stackId);
|
|
173
|
+
ctx.body = {
|
|
174
|
+
...detail,
|
|
175
|
+
env: detail.env.map((pair) => ({
|
|
176
|
+
name: pair.name,
|
|
177
|
+
value: maskValues || (0, import_env.isLikelySensitiveKey)(pair.name) ? "" : pair.value,
|
|
178
|
+
hasExistingValue: pair.value.length > 0,
|
|
179
|
+
sensitive: (0, import_env.isLikelySensitiveKey)(pair.name)
|
|
180
|
+
}))
|
|
181
|
+
};
|
|
182
|
+
} catch (error) {
|
|
183
|
+
sendPortainerError(ctx, error);
|
|
184
|
+
}
|
|
185
|
+
await next();
|
|
186
|
+
}
|
|
187
|
+
};
|
|
188
|
+
}
|
|
189
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
190
|
+
0 && (module.exports = {
|
|
191
|
+
createPortainerResourceActions
|
|
192
|
+
});
|
|
@@ -0,0 +1,54 @@
|
|
|
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
|
+
var __defProp = Object.defineProperty;
|
|
11
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
12
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
13
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
14
|
+
var __export = (target, all) => {
|
|
15
|
+
for (var name in all)
|
|
16
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
17
|
+
};
|
|
18
|
+
var __copyProps = (to, from, except, desc) => {
|
|
19
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
20
|
+
for (let key of __getOwnPropNames(from))
|
|
21
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
22
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
23
|
+
}
|
|
24
|
+
return to;
|
|
25
|
+
};
|
|
26
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
27
|
+
var portainer_instances_exports = {};
|
|
28
|
+
__export(portainer_instances_exports, {
|
|
29
|
+
default: () => portainer_instances_default
|
|
30
|
+
});
|
|
31
|
+
module.exports = __toCommonJS(portainer_instances_exports);
|
|
32
|
+
var import_constants = require("../../shared/constants");
|
|
33
|
+
var portainer_instances_default = {
|
|
34
|
+
name: import_constants.PORTAINER_INSTANCES_COLLECTION,
|
|
35
|
+
title: "Portainer Instances",
|
|
36
|
+
fields: [
|
|
37
|
+
{ name: "id", type: "bigInt", autoIncrement: true, primaryKey: true },
|
|
38
|
+
{ name: "name", type: "string", length: 200 },
|
|
39
|
+
{ name: "baseUrl", type: "string", length: 500 },
|
|
40
|
+
{ name: "apiKey", type: "text" },
|
|
41
|
+
{ name: "gitUsername", type: "string", length: 200 },
|
|
42
|
+
{ name: "gitAccessToken", type: "text" },
|
|
43
|
+
{ name: "gitCredentialId", type: "integer" },
|
|
44
|
+
{ name: "allowInsecureTls", type: "boolean", defaultValue: false },
|
|
45
|
+
{ name: "defaultTimeoutMs", type: "integer", defaultValue: import_constants.DEFAULT_TIMEOUT_MS },
|
|
46
|
+
{ name: "isDefault", type: "boolean", defaultValue: false },
|
|
47
|
+
{ name: "enabled", type: "boolean", defaultValue: true },
|
|
48
|
+
{ name: "lastHealthStatus", type: "string", length: 32 },
|
|
49
|
+
{ name: "lastVersion", type: "string", length: 64 },
|
|
50
|
+
{ name: "lastCheckedAt", type: "date" },
|
|
51
|
+
{ name: "createdAt", type: "date" },
|
|
52
|
+
{ name: "updatedAt", type: "date" }
|
|
53
|
+
]
|
|
54
|
+
};
|
|
@@ -0,0 +1,54 @@
|
|
|
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
|
+
var __create = Object.create;
|
|
11
|
+
var __defProp = Object.defineProperty;
|
|
12
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
13
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
14
|
+
var __getProtoOf = Object.getPrototypeOf;
|
|
15
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
16
|
+
var __export = (target, all) => {
|
|
17
|
+
for (var name in all)
|
|
18
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
19
|
+
};
|
|
20
|
+
var __copyProps = (to, from, except, desc) => {
|
|
21
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
22
|
+
for (let key of __getOwnPropNames(from))
|
|
23
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
24
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
25
|
+
}
|
|
26
|
+
return to;
|
|
27
|
+
};
|
|
28
|
+
var __reExport = (target, mod, secondTarget) => (__copyProps(target, mod, "default"), secondTarget && __copyProps(secondTarget, mod, "default"));
|
|
29
|
+
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
|
30
|
+
// If the importer is in node compatibility mode or this is not an ESM
|
|
31
|
+
// file that has been converted to a CommonJS file using a Babel-
|
|
32
|
+
// compatible transform (i.e. "__esModule" has not been set), then set
|
|
33
|
+
// "default" to the CommonJS "module.exports" for node compatibility.
|
|
34
|
+
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
|
|
35
|
+
mod
|
|
36
|
+
));
|
|
37
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
38
|
+
var server_exports = {};
|
|
39
|
+
__export(server_exports, {
|
|
40
|
+
PluginWorkflowPortainerServer: () => import_plugin.PluginWorkflowPortainerServer,
|
|
41
|
+
default: () => import_plugin.default
|
|
42
|
+
});
|
|
43
|
+
module.exports = __toCommonJS(server_exports);
|
|
44
|
+
var import_plugin = __toESM(require("./plugin"));
|
|
45
|
+
__reExport(server_exports, require("./services/PortainerClient"), module.exports);
|
|
46
|
+
__reExport(server_exports, require("./instructions/PortainerStackRedeployInstruction"), module.exports);
|
|
47
|
+
__reExport(server_exports, require("./instructions/PortainerStackControlInstruction"), module.exports);
|
|
48
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
49
|
+
0 && (module.exports = {
|
|
50
|
+
PluginWorkflowPortainerServer,
|
|
51
|
+
...require("./services/PortainerClient"),
|
|
52
|
+
...require("./instructions/PortainerStackRedeployInstruction"),
|
|
53
|
+
...require("./instructions/PortainerStackControlInstruction")
|
|
54
|
+
});
|
|
@@ -0,0 +1,156 @@
|
|
|
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
|
+
var __create = Object.create;
|
|
11
|
+
var __defProp = Object.defineProperty;
|
|
12
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
13
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
14
|
+
var __getProtoOf = Object.getPrototypeOf;
|
|
15
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
16
|
+
var __export = (target, all) => {
|
|
17
|
+
for (var name in all)
|
|
18
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
19
|
+
};
|
|
20
|
+
var __copyProps = (to, from, except, desc) => {
|
|
21
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
22
|
+
for (let key of __getOwnPropNames(from))
|
|
23
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
24
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
25
|
+
}
|
|
26
|
+
return to;
|
|
27
|
+
};
|
|
28
|
+
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
|
29
|
+
// If the importer is in node compatibility mode or this is not an ESM
|
|
30
|
+
// file that has been converted to a CommonJS file using a Babel-
|
|
31
|
+
// compatible transform (i.e. "__esModule" has not been set), then set
|
|
32
|
+
// "default" to the CommonJS "module.exports" for node compatibility.
|
|
33
|
+
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
|
|
34
|
+
mod
|
|
35
|
+
));
|
|
36
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
37
|
+
var PortainerStackControlInstruction_exports = {};
|
|
38
|
+
__export(PortainerStackControlInstruction_exports, {
|
|
39
|
+
PortainerStackControlInstruction: () => PortainerStackControlInstruction,
|
|
40
|
+
default: () => PortainerStackControlInstruction_default,
|
|
41
|
+
executePortainerControl: () => executePortainerControl
|
|
42
|
+
});
|
|
43
|
+
module.exports = __toCommonJS(PortainerStackControlInstruction_exports);
|
|
44
|
+
var import_joi = __toESM(require("joi"));
|
|
45
|
+
var import_plugin_workflow = require("@nocobase/plugin-workflow");
|
|
46
|
+
var import_env = require("../../shared/env");
|
|
47
|
+
var import_PortainerClient = require("../services/PortainerClient");
|
|
48
|
+
var import_helpers = require("./helpers");
|
|
49
|
+
const numOrVar = import_joi.default.alternatives().try(import_joi.default.number(), import_joi.default.string().allow(""), import_joi.default.allow(null));
|
|
50
|
+
async function executePortainerControl(app, config, signal) {
|
|
51
|
+
const startedAt = /* @__PURE__ */ new Date();
|
|
52
|
+
const instance = await (0, import_helpers.resolvePortainerInstance)(app, config.instanceId ?? null);
|
|
53
|
+
const stackId = (0, import_PortainerClient.assertPositiveInt)(config.stackId ?? void 0, "Stack ID");
|
|
54
|
+
const action = config.action === "start" || config.action === "stop" ? config.action : "inspect";
|
|
55
|
+
let rawStack = await instance.client.getRawStack(stackId, signal);
|
|
56
|
+
const hasExplicitEndpoint = config.endpointId !== null && typeof config.endpointId !== "undefined" && String(config.endpointId).trim() !== "";
|
|
57
|
+
const endpointId = hasExplicitEndpoint ? (0, import_PortainerClient.assertPositiveInt)(config.endpointId ?? void 0, "Environment (Endpoint) ID") : (0, import_PortainerClient.assertPositiveInt)(rawStack.EndpointId, "Stack Endpoint ID");
|
|
58
|
+
if (action === "start") {
|
|
59
|
+
rawStack = await instance.client.startStack(stackId, endpointId, signal);
|
|
60
|
+
rawStack = await instance.client.waitForStackSettlement(stackId, rawStack, {
|
|
61
|
+
timeoutMs: config.timeoutMs ? Number(config.timeoutMs) : instance.defaultTimeoutMs,
|
|
62
|
+
signal
|
|
63
|
+
});
|
|
64
|
+
} else if (action === "stop") {
|
|
65
|
+
rawStack = await instance.client.stopStack(stackId, endpointId, signal);
|
|
66
|
+
rawStack = await instance.client.waitForStackSettlement(stackId, rawStack, {
|
|
67
|
+
timeoutMs: config.timeoutMs ? Number(config.timeoutMs) : instance.defaultTimeoutMs,
|
|
68
|
+
signal
|
|
69
|
+
});
|
|
70
|
+
}
|
|
71
|
+
const detail = (0, import_PortainerClient.toStackDetail)(rawStack);
|
|
72
|
+
const { maskedEnv } = (0, import_env.buildEffectiveStackEnv)({
|
|
73
|
+
existingEnv: detail.env,
|
|
74
|
+
strategy: "merge"
|
|
75
|
+
});
|
|
76
|
+
let containers = [];
|
|
77
|
+
try {
|
|
78
|
+
containers = await instance.client.listStackContainers(endpointId, detail.name, signal);
|
|
79
|
+
} catch {
|
|
80
|
+
containers = [];
|
|
81
|
+
}
|
|
82
|
+
const summary = (0, import_PortainerClient.summarizeContainersHealth)(containers);
|
|
83
|
+
const stackStatus = Number(rawStack.Status ?? detail.status ?? 1);
|
|
84
|
+
const healthy = action === "stop" ? summary.runningCount === 0 : containers.length > 0 ? summary.healthy : stackStatus === 1;
|
|
85
|
+
const finishedAt = /* @__PURE__ */ new Date();
|
|
86
|
+
return {
|
|
87
|
+
ok: true,
|
|
88
|
+
action,
|
|
89
|
+
instanceId: instance.id,
|
|
90
|
+
instanceName: instance.name,
|
|
91
|
+
endpointId,
|
|
92
|
+
stackId,
|
|
93
|
+
stackName: detail.name,
|
|
94
|
+
stackType: detail.isGitStack ? "git" : "compose",
|
|
95
|
+
stackStatus,
|
|
96
|
+
gitReference: detail.gitReference ?? null,
|
|
97
|
+
healthy,
|
|
98
|
+
runningCount: summary.runningCount,
|
|
99
|
+
totalCount: summary.totalCount,
|
|
100
|
+
containers,
|
|
101
|
+
currentEnv: maskedEnv,
|
|
102
|
+
startedAt: startedAt.toISOString(),
|
|
103
|
+
finishedAt: finishedAt.toISOString(),
|
|
104
|
+
durationMs: Math.max(0, finishedAt.getTime() - startedAt.getTime())
|
|
105
|
+
};
|
|
106
|
+
}
|
|
107
|
+
class PortainerStackControlInstruction extends import_plugin_workflow.Instruction {
|
|
108
|
+
configSchema = import_joi.default.object({
|
|
109
|
+
instanceId: numOrVar,
|
|
110
|
+
endpointId: numOrVar,
|
|
111
|
+
stackId: numOrVar,
|
|
112
|
+
action: import_joi.default.string().valid("inspect", "start", "stop").default("inspect"),
|
|
113
|
+
timeoutMs: numOrVar,
|
|
114
|
+
ignoreFail: import_joi.default.boolean().default(false)
|
|
115
|
+
}).unknown(true);
|
|
116
|
+
async run(node, prevJob, processor, options) {
|
|
117
|
+
const config = processor.getParsedValue(node.config ?? {}, node.id);
|
|
118
|
+
return (0, import_helpers.runPortainerWorkflowTask)({
|
|
119
|
+
workflow: this.workflow,
|
|
120
|
+
node,
|
|
121
|
+
prevJob,
|
|
122
|
+
processor,
|
|
123
|
+
ignoreFail: config.ignoreFail,
|
|
124
|
+
signal: options == null ? void 0 : options.signal,
|
|
125
|
+
execute: (signal) => executePortainerControl(this.workflow.app, config, signal)
|
|
126
|
+
});
|
|
127
|
+
}
|
|
128
|
+
async resume(node, job) {
|
|
129
|
+
const config = node.config ?? {};
|
|
130
|
+
if (config.ignoreFail) {
|
|
131
|
+
job.set("status", import_plugin_workflow.JOB_STATUS.RESOLVED);
|
|
132
|
+
}
|
|
133
|
+
return job;
|
|
134
|
+
}
|
|
135
|
+
async test(config) {
|
|
136
|
+
const startedAt = /* @__PURE__ */ new Date();
|
|
137
|
+
try {
|
|
138
|
+
const result = await executePortainerControl(this.workflow.app, config);
|
|
139
|
+
return {
|
|
140
|
+
status: import_plugin_workflow.JOB_STATUS.RESOLVED,
|
|
141
|
+
result
|
|
142
|
+
};
|
|
143
|
+
} catch (error) {
|
|
144
|
+
return {
|
|
145
|
+
status: config.ignoreFail ? import_plugin_workflow.JOB_STATUS.RESOLVED : import_plugin_workflow.JOB_STATUS.FAILED,
|
|
146
|
+
result: (0, import_helpers.formatFailureResult)(error, startedAt)
|
|
147
|
+
};
|
|
148
|
+
}
|
|
149
|
+
}
|
|
150
|
+
}
|
|
151
|
+
var PortainerStackControlInstruction_default = PortainerStackControlInstruction;
|
|
152
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
153
|
+
0 && (module.exports = {
|
|
154
|
+
PortainerStackControlInstruction,
|
|
155
|
+
executePortainerControl
|
|
156
|
+
});
|