dokku-compose 0.5.2 → 0.6.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.
Files changed (2) hide show
  1. package/dist/index.js +97 -13
  2. package/package.json +1 -1
package/dist/index.js CHANGED
@@ -285,7 +285,8 @@ var Apps = {
285
285
  // src/resources/parsers.ts
286
286
  function parseReport(raw, namespace) {
287
287
  const result = {};
288
- const prefix = new RegExp(`^${namespace}\\s+`, "i");
288
+ const prefixPattern = namespace.replace(/-/g, "[\\s-]");
289
+ const prefix = new RegExp(`^${prefixPattern}\\s+`, "i");
289
290
  for (const line of raw.split("\n")) {
290
291
  if (line.trimStart().startsWith("=====>")) continue;
291
292
  const colonIdx = line.indexOf(":");
@@ -532,11 +533,64 @@ var Certs = {
532
533
  };
533
534
 
534
535
  // src/resources/builder.ts
536
+ function parseBuildArgs(dockerOptsBuild) {
537
+ const args = {};
538
+ const matches = dockerOptsBuild.matchAll(/--build-arg\s+(\S+?)=(\S+)/g);
539
+ for (const m of matches) args[m[1]] = m[2];
540
+ return args;
541
+ }
542
+ function buildConfigFromReports(builderReport, dockerfileReport, appJsonReport, dockerOptsBuild) {
543
+ const config = {};
544
+ if (dockerfileReport["dockerfile-path"])
545
+ config.dockerfile = dockerfileReport["dockerfile-path"];
546
+ if (appJsonReport["selected"])
547
+ config.app_json = appJsonReport["selected"];
548
+ if (builderReport["build-dir"])
549
+ config.context = builderReport["build-dir"];
550
+ const args = parseBuildArgs(dockerOptsBuild);
551
+ if (Object.keys(args).length > 0) config.args = args;
552
+ return config;
553
+ }
535
554
  var Builder = {
536
555
  key: "build",
537
- forceApply: true,
538
- read: async () => ({}),
539
- onChange: async (ctx, target, { after }) => {
556
+ async read(ctx, target) {
557
+ const [builderRaw, dockerfileRaw, appJsonRaw, dockerOptsRaw] = await Promise.all([
558
+ ctx.query("builder:report", target),
559
+ ctx.query("builder-dockerfile:report", target),
560
+ ctx.query("app-json:report", target),
561
+ ctx.query("docker-options:report", target)
562
+ ]);
563
+ const dockerOptsReport = parseReport(dockerOptsRaw, "docker-options");
564
+ return buildConfigFromReports(
565
+ parseReport(builderRaw, "builder"),
566
+ parseReport(dockerfileRaw, "builder-dockerfile"),
567
+ parseReport(appJsonRaw, "app-json"),
568
+ dockerOptsReport["build"] ?? ""
569
+ );
570
+ },
571
+ async readAll(ctx) {
572
+ const [builderRaw, dockerfileRaw, appJsonRaw, dockerOptsRaw] = await Promise.all([
573
+ ctx.query("builder:report"),
574
+ ctx.query("builder-dockerfile:report"),
575
+ ctx.query("app-json:report"),
576
+ ctx.query("docker-options:report")
577
+ ]);
578
+ const builderBulk = parseBulkReport(builderRaw, "builder");
579
+ const dockerfileBulk = parseBulkReport(dockerfileRaw, "builder-dockerfile");
580
+ const appJsonBulk = parseBulkReport(appJsonRaw, "app-json");
581
+ const dockerOptsBulk = parseBulkReport(dockerOptsRaw, "docker-options");
582
+ const result = /* @__PURE__ */ new Map();
583
+ for (const app of builderBulk.keys()) {
584
+ result.set(app, buildConfigFromReports(
585
+ builderBulk.get(app) ?? {},
586
+ dockerfileBulk.get(app) ?? {},
587
+ appJsonBulk.get(app) ?? {},
588
+ dockerOptsBulk.get(app)?.["build"] ?? ""
589
+ ));
590
+ }
591
+ return result;
592
+ },
593
+ async onChange(ctx, target, { after }) {
540
594
  if (after.dockerfile)
541
595
  await ctx.run("builder-dockerfile:set", target, "dockerfile-path", after.dockerfile);
542
596
  if (after.app_json)
@@ -552,17 +606,47 @@ var Builder = {
552
606
  };
553
607
 
554
608
  // src/resources/docker-options.ts
609
+ var PHASES = ["build", "deploy", "run"];
610
+ function filterManagedOpts(opts) {
611
+ return opts.filter((o) => !o.startsWith("--link ") && !o.startsWith("--build-arg "));
612
+ }
613
+ function parsePhaseOpts(raw) {
614
+ if (!raw) return [];
615
+ const opts = raw.match(/--\S+(?:\s+(?!--)\S+)*/g) ?? [];
616
+ return filterManagedOpts(opts);
617
+ }
618
+ function dockerOptsFromReport(report) {
619
+ const result = {};
620
+ for (const phase of PHASES) {
621
+ const opts = parsePhaseOpts(report[phase] ?? "");
622
+ if (opts.length > 0) result[phase] = opts;
623
+ }
624
+ return result;
625
+ }
555
626
  var DockerOptions = {
556
627
  key: "docker_options",
557
- forceApply: true,
558
- read: async () => ({}),
559
- onChange: async (ctx, target, { after }) => {
560
- for (const phase of ["build", "deploy", "run"]) {
561
- const opts = after[phase];
562
- if (!opts || opts.length === 0) continue;
563
- await ctx.run("docker-options:clear", target, phase);
564
- for (const opt of opts) {
565
- await ctx.run("docker-options:add", target, phase, opt);
628
+ async read(ctx, target) {
629
+ const raw = await ctx.query("docker-options:report", target);
630
+ return dockerOptsFromReport(parseReport(raw, "docker-options"));
631
+ },
632
+ async readAll(ctx) {
633
+ const raw = await ctx.query("docker-options:report");
634
+ const bulk = parseBulkReport(raw, "docker-options");
635
+ const result = /* @__PURE__ */ new Map();
636
+ for (const [app, report] of bulk) {
637
+ result.set(app, dockerOptsFromReport(report));
638
+ }
639
+ return result;
640
+ },
641
+ async onChange(ctx, target, { before, after }) {
642
+ for (const phase of PHASES) {
643
+ const prev = new Set(before[phase] ?? []);
644
+ const desired = new Set(after[phase] ?? []);
645
+ for (const opt of desired) {
646
+ if (!prev.has(opt)) await ctx.run("docker-options:add", target, phase, opt);
647
+ }
648
+ for (const opt of prev) {
649
+ if (!desired.has(opt)) await ctx.run("docker-options:remove", target, phase, opt);
566
650
  }
567
651
  }
568
652
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "dokku-compose",
3
- "version": "0.5.2",
3
+ "version": "0.6.1",
4
4
  "description": "Docker Compose for Dokku — declare your entire server in a single YAML file.",
5
5
  "main": "dist/index.js",
6
6
  "exports": "./dist/index.js",