dokku-compose 0.4.0 → 0.5.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/index.js +126 -22
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -284,6 +284,40 @@ var Apps = {
|
|
|
284
284
|
}
|
|
285
285
|
};
|
|
286
286
|
|
|
287
|
+
// src/resources/parsers.ts
|
|
288
|
+
function parseReport(raw, namespace) {
|
|
289
|
+
const result = {};
|
|
290
|
+
const prefix = new RegExp(`^${namespace}\\s+`, "i");
|
|
291
|
+
for (const line of raw.split("\n")) {
|
|
292
|
+
if (line.trimStart().startsWith("=====>")) continue;
|
|
293
|
+
const colonIdx = line.indexOf(":");
|
|
294
|
+
if (colonIdx === -1) continue;
|
|
295
|
+
const rawKey = line.slice(0, colonIdx).trim();
|
|
296
|
+
if (!rawKey) continue;
|
|
297
|
+
const value = line.slice(colonIdx + 1).trim();
|
|
298
|
+
const stripped = rawKey.replace(prefix, "");
|
|
299
|
+
const key = stripped.toLowerCase().replace(/\s+/g, "-");
|
|
300
|
+
if (key.startsWith("computed-") || key.startsWith("global-") || key === "last-visited-at") continue;
|
|
301
|
+
if (!value) continue;
|
|
302
|
+
result[key] = value;
|
|
303
|
+
}
|
|
304
|
+
return result;
|
|
305
|
+
}
|
|
306
|
+
function parseBulkReport(raw, namespace) {
|
|
307
|
+
const result = /* @__PURE__ */ new Map();
|
|
308
|
+
const sections = raw.split(/(?=^=====> )/m).filter((s) => s.trim());
|
|
309
|
+
for (const section of sections) {
|
|
310
|
+
const headerEnd = section.indexOf("\n");
|
|
311
|
+
if (headerEnd === -1) continue;
|
|
312
|
+
const header = section.slice(0, headerEnd);
|
|
313
|
+
const match = header.match(/^=====> (.+?)\s+\S+\s+information/);
|
|
314
|
+
if (!match) continue;
|
|
315
|
+
const app = match[1];
|
|
316
|
+
result.set(app, parseReport(section, namespace));
|
|
317
|
+
}
|
|
318
|
+
return result;
|
|
319
|
+
}
|
|
320
|
+
|
|
287
321
|
// src/resources/lists.ts
|
|
288
322
|
function splitWords(raw) {
|
|
289
323
|
return raw.split(/\s+/).map((s) => s.trim()).filter(Boolean);
|
|
@@ -297,6 +331,15 @@ var Ports = {
|
|
|
297
331
|
const raw = await ctx.query("ports:report", target, "--ports-map");
|
|
298
332
|
return splitWords(raw);
|
|
299
333
|
},
|
|
334
|
+
readAll: async (ctx) => {
|
|
335
|
+
const raw = await ctx.query("ports:report");
|
|
336
|
+
const bulk = parseBulkReport(raw, "ports");
|
|
337
|
+
const result = /* @__PURE__ */ new Map();
|
|
338
|
+
for (const [app, report] of bulk) {
|
|
339
|
+
result.set(app, report["map"] ? splitWords(report["map"]) : []);
|
|
340
|
+
}
|
|
341
|
+
return result;
|
|
342
|
+
},
|
|
300
343
|
onChange: async (ctx, target, change) => {
|
|
301
344
|
await ctx.run("ports:set", target, ...change.after);
|
|
302
345
|
}
|
|
@@ -307,6 +350,15 @@ var Domains = {
|
|
|
307
350
|
const raw = await ctx.query("domains:report", target, "--domains-app-vhosts");
|
|
308
351
|
return splitLines(raw);
|
|
309
352
|
},
|
|
353
|
+
readAll: async (ctx) => {
|
|
354
|
+
const raw = await ctx.query("domains:report");
|
|
355
|
+
const bulk = parseBulkReport(raw, "domains");
|
|
356
|
+
const result = /* @__PURE__ */ new Map();
|
|
357
|
+
for (const [app, report] of bulk) {
|
|
358
|
+
result.set(app, report["app-vhosts"] ? splitWords(report["app-vhosts"]) : []);
|
|
359
|
+
}
|
|
360
|
+
return result;
|
|
361
|
+
},
|
|
310
362
|
onChange: async (ctx, target, { added, removed }) => {
|
|
311
363
|
for (const d of removed) await ctx.run("domains:remove", target, d);
|
|
312
364
|
for (const d of added) await ctx.run("domains:add", target, d);
|
|
@@ -318,32 +370,21 @@ var Storage = {
|
|
|
318
370
|
const raw = await ctx.query("storage:report", target, "--storage-mounts");
|
|
319
371
|
return splitLines(raw);
|
|
320
372
|
},
|
|
373
|
+
readAll: async (ctx) => {
|
|
374
|
+
const raw = await ctx.query("storage:report");
|
|
375
|
+
const bulk = parseBulkReport(raw, "storage");
|
|
376
|
+
const result = /* @__PURE__ */ new Map();
|
|
377
|
+
for (const [app, report] of bulk) {
|
|
378
|
+
result.set(app, report["mounts"] ? splitLines(report["mounts"]) : []);
|
|
379
|
+
}
|
|
380
|
+
return result;
|
|
381
|
+
},
|
|
321
382
|
onChange: async (ctx, target, { added, removed }) => {
|
|
322
383
|
for (const m of removed) await ctx.run("storage:unmount", target, m);
|
|
323
384
|
for (const m of added) await ctx.run("storage:mount", target, m);
|
|
324
385
|
}
|
|
325
386
|
};
|
|
326
387
|
|
|
327
|
-
// src/resources/parsers.ts
|
|
328
|
-
function parseReport(raw, namespace) {
|
|
329
|
-
const result = {};
|
|
330
|
-
const prefix = new RegExp(`^${namespace}\\s+`, "i");
|
|
331
|
-
for (const line of raw.split("\n")) {
|
|
332
|
-
if (line.trimStart().startsWith("=====>")) continue;
|
|
333
|
-
const colonIdx = line.indexOf(":");
|
|
334
|
-
if (colonIdx === -1) continue;
|
|
335
|
-
const rawKey = line.slice(0, colonIdx).trim();
|
|
336
|
-
if (!rawKey) continue;
|
|
337
|
-
const value = line.slice(colonIdx + 1).trim();
|
|
338
|
-
const stripped = rawKey.replace(prefix, "");
|
|
339
|
-
const key = stripped.toLowerCase().replace(/\s+/g, "-");
|
|
340
|
-
if (key.startsWith("computed-") || key.startsWith("global-") || key === "last-visited-at") continue;
|
|
341
|
-
if (!value) continue;
|
|
342
|
-
result[key] = value;
|
|
343
|
-
}
|
|
344
|
-
return result;
|
|
345
|
-
}
|
|
346
|
-
|
|
347
388
|
// src/resources/properties.ts
|
|
348
389
|
function propertyResource(opts) {
|
|
349
390
|
return {
|
|
@@ -352,6 +393,10 @@ function propertyResource(opts) {
|
|
|
352
393
|
const raw = await ctx.query(`${opts.namespace}:report`, target);
|
|
353
394
|
return parseReport(raw, opts.namespace);
|
|
354
395
|
},
|
|
396
|
+
async readAll(ctx) {
|
|
397
|
+
const raw = await ctx.query(`${opts.namespace}:report`);
|
|
398
|
+
return parseBulkReport(raw, opts.namespace);
|
|
399
|
+
},
|
|
355
400
|
async onChange(ctx, target, change) {
|
|
356
401
|
for (const [key, value] of Object.entries({ ...change.added, ...change.modified })) {
|
|
357
402
|
await ctx.run(opts.setCmd, target, key, String(value));
|
|
@@ -387,6 +432,15 @@ var Scheduler = {
|
|
|
387
432
|
const report = parseReport(raw, "scheduler");
|
|
388
433
|
return report["selected"] ?? "";
|
|
389
434
|
},
|
|
435
|
+
async readAll(ctx) {
|
|
436
|
+
const raw = await ctx.query("scheduler:report");
|
|
437
|
+
const bulk = parseBulkReport(raw, "scheduler");
|
|
438
|
+
const result = /* @__PURE__ */ new Map();
|
|
439
|
+
for (const [app, report] of bulk) {
|
|
440
|
+
result.set(app, report["selected"] ?? "");
|
|
441
|
+
}
|
|
442
|
+
return result;
|
|
443
|
+
},
|
|
390
444
|
async onChange(ctx, target, change) {
|
|
391
445
|
await ctx.run("scheduler:set", target, "selected", change.after);
|
|
392
446
|
}
|
|
@@ -399,6 +453,15 @@ var Proxy = {
|
|
|
399
453
|
const raw = await ctx.query("proxy:report", target, "--proxy-enabled");
|
|
400
454
|
return raw.trim() === "true";
|
|
401
455
|
},
|
|
456
|
+
readAll: async (ctx) => {
|
|
457
|
+
const raw = await ctx.query("proxy:report");
|
|
458
|
+
const bulk = parseBulkReport(raw, "proxy");
|
|
459
|
+
const result = /* @__PURE__ */ new Map();
|
|
460
|
+
for (const [app, report] of bulk) {
|
|
461
|
+
result.set(app, report["enabled"] === "true");
|
|
462
|
+
}
|
|
463
|
+
return result;
|
|
464
|
+
},
|
|
402
465
|
onChange: async (ctx, target, { after }) => {
|
|
403
466
|
await ctx.run(after ? "proxy:enable" : "proxy:disable", target);
|
|
404
467
|
}
|
|
@@ -451,6 +514,15 @@ var Certs = {
|
|
|
451
514
|
const raw = await ctx.query("certs:report", target, "--ssl-enabled");
|
|
452
515
|
return raw.trim() === "true";
|
|
453
516
|
},
|
|
517
|
+
readAll: async (ctx) => {
|
|
518
|
+
const raw = await ctx.query("certs:report");
|
|
519
|
+
const bulk = parseBulkReport(raw, "ssl");
|
|
520
|
+
const result = /* @__PURE__ */ new Map();
|
|
521
|
+
for (const [app, report] of bulk) {
|
|
522
|
+
result.set(app, report["enabled"] === "true");
|
|
523
|
+
}
|
|
524
|
+
return result;
|
|
525
|
+
},
|
|
454
526
|
onChange: async (ctx, target, { before, after }) => {
|
|
455
527
|
if (after === false && before) {
|
|
456
528
|
await ctx.run("certs:remove", target);
|
|
@@ -505,6 +577,15 @@ var Git = {
|
|
|
505
577
|
const report = await ctx.query("git:report", target, "--git-deploy-branch");
|
|
506
578
|
return { deploy_branch: report.trim() || void 0 };
|
|
507
579
|
},
|
|
580
|
+
readAll: async (ctx) => {
|
|
581
|
+
const raw = await ctx.query("git:report");
|
|
582
|
+
const bulk = parseBulkReport(raw, "git");
|
|
583
|
+
const result = /* @__PURE__ */ new Map();
|
|
584
|
+
for (const [app, report] of bulk) {
|
|
585
|
+
result.set(app, { deploy_branch: report["deploy-branch"] || void 0 });
|
|
586
|
+
}
|
|
587
|
+
return result;
|
|
588
|
+
},
|
|
508
589
|
onChange: async (ctx, target, { after }) => {
|
|
509
590
|
if (after.deploy_branch) {
|
|
510
591
|
await ctx.run("git:set", target, "deploy-branch", after.deploy_branch);
|
|
@@ -542,6 +623,15 @@ var Networks = {
|
|
|
542
623
|
const raw = await ctx.query("network:report", target, "--network-attach-post-deploy");
|
|
543
624
|
return raw.trim() ? raw.trim().split(/\s+/) : [];
|
|
544
625
|
},
|
|
626
|
+
readAll: async (ctx) => {
|
|
627
|
+
const raw = await ctx.query("network:report");
|
|
628
|
+
const bulk = parseBulkReport(raw, "network");
|
|
629
|
+
const result = /* @__PURE__ */ new Map();
|
|
630
|
+
for (const [app, report] of bulk) {
|
|
631
|
+
result.set(app, report["attach-post-deploy"] ? report["attach-post-deploy"].split(/\s+/) : []);
|
|
632
|
+
}
|
|
633
|
+
return result;
|
|
634
|
+
},
|
|
545
635
|
onChange: async (ctx, target, { after }) => {
|
|
546
636
|
await ctx.run("network:set", target, "attach-post-deploy", ...after);
|
|
547
637
|
}
|
|
@@ -858,12 +948,19 @@ async function runExport(ctx, opts) {
|
|
|
858
948
|
if (networks.length > 0) config.networks = networks;
|
|
859
949
|
const services = await exportServices(ctx);
|
|
860
950
|
if (Object.keys(services).length > 0) config.services = services;
|
|
951
|
+
const prefetched = /* @__PURE__ */ new Map();
|
|
952
|
+
await Promise.all(
|
|
953
|
+
ALL_APP_RESOURCES.filter((r) => !r.forceApply && !r.key.startsWith("_") && r.readAll).map(async (r) => {
|
|
954
|
+
prefetched.set(r.key, await r.readAll(ctx));
|
|
955
|
+
})
|
|
956
|
+
);
|
|
861
957
|
for (const app of apps) {
|
|
862
958
|
const appConfig = {};
|
|
863
959
|
for (const resource of ALL_APP_RESOURCES) {
|
|
864
960
|
if (resource.key.startsWith("_")) continue;
|
|
865
961
|
if (resource.forceApply) continue;
|
|
866
|
-
const
|
|
962
|
+
const bulk = prefetched.get(resource.key);
|
|
963
|
+
const value = bulk ? bulk.get(app) : await resource.read(ctx, app);
|
|
867
964
|
if (value === void 0 || value === null || value === "") continue;
|
|
868
965
|
if (Array.isArray(value) && value.length === 0) continue;
|
|
869
966
|
if (typeof value === "object" && !Array.isArray(value) && Object.keys(value).length === 0) continue;
|
|
@@ -886,6 +983,12 @@ async function runExport(ctx, opts) {
|
|
|
886
983
|
import chalk2 from "chalk";
|
|
887
984
|
async function computeDiff(ctx, config) {
|
|
888
985
|
const result = { apps: {}, services: {}, inSync: true };
|
|
986
|
+
const prefetched = /* @__PURE__ */ new Map();
|
|
987
|
+
await Promise.all(
|
|
988
|
+
ALL_APP_RESOURCES.filter((r) => !r.forceApply && !r.key.startsWith("_") && r.readAll).map(async (r) => {
|
|
989
|
+
prefetched.set(r.key, await r.readAll(ctx));
|
|
990
|
+
})
|
|
991
|
+
);
|
|
889
992
|
for (const [app, appConfig] of Object.entries(config.apps)) {
|
|
890
993
|
const appDiff = {};
|
|
891
994
|
for (const resource of ALL_APP_RESOURCES) {
|
|
@@ -898,7 +1001,8 @@ async function computeDiff(ctx, config) {
|
|
|
898
1001
|
desired = appConfig[resource.key];
|
|
899
1002
|
}
|
|
900
1003
|
if (desired === void 0) continue;
|
|
901
|
-
const
|
|
1004
|
+
const bulk = prefetched.get(resource.key);
|
|
1005
|
+
const current = bulk ? bulk.get(app) : await resource.read(ctx, app);
|
|
902
1006
|
const change = computeChange(current, desired);
|
|
903
1007
|
if (!change.changed) {
|
|
904
1008
|
appDiff[resource.key] = { status: "in-sync", desired, current };
|