@intentius/chant-lexicon-docker 0.124.98 → 0.124.100

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 (241) hide show
  1. package/dist/codegen/docs-cli.d.ts +0 -1
  2. package/dist/codegen/docs.d.ts +0 -1
  3. package/dist/codegen/generate-cli.d.ts +0 -1
  4. package/dist/codegen/generate-compose.d.ts +0 -1
  5. package/dist/codegen/generate-dockerfile.d.ts +0 -1
  6. package/dist/codegen/generate.d.ts +0 -1
  7. package/dist/codegen/naming.d.ts +0 -1
  8. package/dist/codegen/package.d.ts +0 -1
  9. package/dist/codegen/patches.d.ts +0 -1
  10. package/dist/codegen/versions.d.ts +0 -1
  11. package/dist/compose-key.d.ts +0 -1
  12. package/dist/composites/catalog.d.ts +0 -1
  13. package/dist/composites/docker-otel-collector.d.ts +0 -1
  14. package/dist/composites/docker-web-service.d.ts +0 -1
  15. package/dist/composites/index.d.ts +0 -1
  16. package/dist/coverage.d.ts +0 -1
  17. package/dist/default-labels.d.ts +0 -1
  18. package/dist/detect.d.ts +0 -1
  19. package/dist/dockerfile-order.d.ts +0 -1
  20. package/dist/export-resources.d.ts +0 -1
  21. package/dist/generated/index.d.ts +0 -1
  22. package/dist/generated/runtime.d.ts +0 -1
  23. package/dist/import/adapter.d.ts +0 -1
  24. package/dist/import/adapter.js +4 -2
  25. package/dist/import/embedded.d.ts +0 -1
  26. package/dist/import/engine.d.ts +0 -1
  27. package/dist/import/generator.d.ts +9 -2
  28. package/dist/import/generator.js +23 -1
  29. package/dist/import/live-export.d.ts +0 -1
  30. package/dist/import/parser.d.ts +0 -1
  31. package/dist/import/testdata/tar.d.ts +0 -1
  32. package/dist/index.d.ts +0 -1
  33. package/dist/integrity.json +2 -2
  34. package/dist/interpolation.d.ts +0 -1
  35. package/dist/lint/audit-catalog.d.ts +0 -1
  36. package/dist/lint/audit-lineage.d.ts +0 -1
  37. package/dist/lint/post-synth/add-url-checksum.d.ts +0 -1
  38. package/dist/lint/post-synth/apt-no-recommends.d.ts +0 -1
  39. package/dist/lint/post-synth/apt-update-alone.d.ts +0 -1
  40. package/dist/lint/post-synth/cache-busting-copy.d.ts +0 -1
  41. package/dist/lint/post-synth/copy-from-stage.d.ts +0 -1
  42. package/dist/lint/post-synth/docker-helpers.d.ts +0 -1
  43. package/dist/lint/post-synth/index.d.ts +0 -1
  44. package/dist/lint/post-synth/no-latest-image.d.ts +0 -1
  45. package/dist/lint/post-synth/no-root-user.d.ts +0 -1
  46. package/dist/lint/post-synth/prefer-copy.d.ts +0 -1
  47. package/dist/lint/post-synth/relative-workdir.d.ts +0 -1
  48. package/dist/lint/post-synth/repeated-cmd.d.ts +0 -1
  49. package/dist/lint/post-synth/root-after-user.d.ts +0 -1
  50. package/dist/lint/post-synth/ssh-port-exposed.d.ts +0 -1
  51. package/dist/lint/post-synth/unused-global-arg.d.ts +0 -1
  52. package/dist/lint/post-synth/unused-volume.d.ts +0 -1
  53. package/dist/lint/rules/data/deprecated-images.d.ts +0 -1
  54. package/dist/lint/rules/data/known-base-images.d.ts +0 -1
  55. package/dist/lint/rules/index.d.ts +0 -1
  56. package/dist/lint/rules/no-latest-tag.d.ts +0 -1
  57. package/dist/lint/rules/per-kind-order.d.ts +0 -1
  58. package/dist/list-artifacts.d.ts +0 -1
  59. package/dist/lsp/completions.d.ts +0 -1
  60. package/dist/lsp/hover.d.ts +0 -1
  61. package/dist/manifest.json +1 -1
  62. package/dist/package-cli.d.ts +0 -1
  63. package/dist/plugin.d.ts +0 -1
  64. package/dist/serializer.d.ts +0 -1
  65. package/dist/spec/fetch-compose.d.ts +0 -1
  66. package/dist/spec/fetch-engine.d.ts +0 -1
  67. package/dist/spec/parse-compose.d.ts +0 -1
  68. package/dist/spec/parse-engine.d.ts +0 -1
  69. package/dist/validate-cli.d.ts +0 -1
  70. package/dist/validate.d.ts +0 -1
  71. package/dist/variables.d.ts +0 -1
  72. package/package.json +8 -9
  73. package/dist/codegen/docs-cli.d.ts.map +0 -1
  74. package/dist/codegen/docs.d.ts.map +0 -1
  75. package/dist/codegen/generate-cli.d.ts.map +0 -1
  76. package/dist/codegen/generate-compose.d.ts.map +0 -1
  77. package/dist/codegen/generate-dockerfile.d.ts.map +0 -1
  78. package/dist/codegen/generate.d.ts.map +0 -1
  79. package/dist/codegen/naming.d.ts.map +0 -1
  80. package/dist/codegen/package.d.ts.map +0 -1
  81. package/dist/codegen/patches.d.ts.map +0 -1
  82. package/dist/codegen/versions.d.ts.map +0 -1
  83. package/dist/compose-key.d.ts.map +0 -1
  84. package/dist/composites/catalog.d.ts.map +0 -1
  85. package/dist/composites/docker-otel-collector.d.ts.map +0 -1
  86. package/dist/composites/docker-web-service.d.ts.map +0 -1
  87. package/dist/composites/index.d.ts.map +0 -1
  88. package/dist/coverage.d.ts.map +0 -1
  89. package/dist/default-labels.d.ts.map +0 -1
  90. package/dist/detect.d.ts.map +0 -1
  91. package/dist/dockerfile-order.d.ts.map +0 -1
  92. package/dist/export-resources.d.ts.map +0 -1
  93. package/dist/generated/index.d.ts.map +0 -1
  94. package/dist/generated/runtime.d.ts.map +0 -1
  95. package/dist/import/adapter.d.ts.map +0 -1
  96. package/dist/import/embedded.d.ts.map +0 -1
  97. package/dist/import/engine.d.ts.map +0 -1
  98. package/dist/import/generator.d.ts.map +0 -1
  99. package/dist/import/live-export.d.ts.map +0 -1
  100. package/dist/import/parser.d.ts.map +0 -1
  101. package/dist/import/testdata/tar.d.ts.map +0 -1
  102. package/dist/index.d.ts.map +0 -1
  103. package/dist/interpolation.d.ts.map +0 -1
  104. package/dist/lint/audit-catalog.d.ts.map +0 -1
  105. package/dist/lint/audit-lineage.d.ts.map +0 -1
  106. package/dist/lint/post-synth/add-url-checksum.d.ts.map +0 -1
  107. package/dist/lint/post-synth/apt-no-recommends.d.ts.map +0 -1
  108. package/dist/lint/post-synth/apt-update-alone.d.ts.map +0 -1
  109. package/dist/lint/post-synth/cache-busting-copy.d.ts.map +0 -1
  110. package/dist/lint/post-synth/copy-from-stage.d.ts.map +0 -1
  111. package/dist/lint/post-synth/docker-helpers.d.ts.map +0 -1
  112. package/dist/lint/post-synth/index.d.ts.map +0 -1
  113. package/dist/lint/post-synth/no-latest-image.d.ts.map +0 -1
  114. package/dist/lint/post-synth/no-root-user.d.ts.map +0 -1
  115. package/dist/lint/post-synth/prefer-copy.d.ts.map +0 -1
  116. package/dist/lint/post-synth/relative-workdir.d.ts.map +0 -1
  117. package/dist/lint/post-synth/repeated-cmd.d.ts.map +0 -1
  118. package/dist/lint/post-synth/root-after-user.d.ts.map +0 -1
  119. package/dist/lint/post-synth/ssh-port-exposed.d.ts.map +0 -1
  120. package/dist/lint/post-synth/unused-global-arg.d.ts.map +0 -1
  121. package/dist/lint/post-synth/unused-volume.d.ts.map +0 -1
  122. package/dist/lint/rules/data/deprecated-images.d.ts.map +0 -1
  123. package/dist/lint/rules/data/known-base-images.d.ts.map +0 -1
  124. package/dist/lint/rules/index.d.ts.map +0 -1
  125. package/dist/lint/rules/no-latest-tag.d.ts.map +0 -1
  126. package/dist/lint/rules/per-kind-order.d.ts.map +0 -1
  127. package/dist/list-artifacts.d.ts.map +0 -1
  128. package/dist/lsp/completions.d.ts.map +0 -1
  129. package/dist/lsp/hover.d.ts.map +0 -1
  130. package/dist/package-cli.d.ts.map +0 -1
  131. package/dist/plugin.d.ts.map +0 -1
  132. package/dist/serializer.d.ts.map +0 -1
  133. package/dist/spec/fetch-compose.d.ts.map +0 -1
  134. package/dist/spec/fetch-engine.d.ts.map +0 -1
  135. package/dist/spec/parse-compose.d.ts.map +0 -1
  136. package/dist/spec/parse-engine.d.ts.map +0 -1
  137. package/dist/validate-cli.d.ts.map +0 -1
  138. package/dist/validate.d.ts.map +0 -1
  139. package/dist/variables.d.ts.map +0 -1
  140. package/src/codegen/__snapshots__/okf.test.ts.snap +0 -555
  141. package/src/codegen/docs-cli.ts +0 -10
  142. package/src/codegen/docs.ts +0 -171
  143. package/src/codegen/generate-cli.ts +0 -36
  144. package/src/codegen/generate-compose.ts +0 -21
  145. package/src/codegen/generate-dockerfile.ts +0 -21
  146. package/src/codegen/generate.test.ts +0 -115
  147. package/src/codegen/generate.ts +0 -258
  148. package/src/codegen/naming.test.ts +0 -81
  149. package/src/codegen/naming.ts +0 -54
  150. package/src/codegen/okf.test.ts +0 -36
  151. package/src/codegen/package.ts +0 -59
  152. package/src/codegen/patches.ts +0 -42
  153. package/src/codegen/versions.ts +0 -46
  154. package/src/compose-key.ts +0 -31
  155. package/src/composites/catalog.test.ts +0 -39
  156. package/src/composites/catalog.ts +0 -118
  157. package/src/composites/docker-otel-collector.ts +0 -83
  158. package/src/composites/docker-web-service.test.ts +0 -34
  159. package/src/composites/docker-web-service.ts +0 -75
  160. package/src/composites/index.ts +0 -9
  161. package/src/coverage.test.ts +0 -33
  162. package/src/coverage.ts +0 -54
  163. package/src/default-labels.test.ts +0 -85
  164. package/src/default-labels.ts +0 -72
  165. package/src/detect.ts +0 -7
  166. package/src/dockerfile-order.ts +0 -20
  167. package/src/docs-examples.test.ts +0 -141
  168. package/src/export-resources.ts +0 -90
  169. package/src/generated/index.d.ts +0 -407
  170. package/src/generated/index.ts +0 -410
  171. package/src/generated/runtime.ts +0 -4
  172. package/src/import/adapter.ts +0 -99
  173. package/src/import/embedded-live.test.ts +0 -250
  174. package/src/import/embedded.ts +0 -83
  175. package/src/import/engine.ts +0 -107
  176. package/src/import/generator.test.ts +0 -134
  177. package/src/import/generator.ts +0 -202
  178. package/src/import/live-export.test.ts +0 -271
  179. package/src/import/live-export.ts +0 -359
  180. package/src/import/parser.test.ts +0 -137
  181. package/src/import/parser.ts +0 -269
  182. package/src/import/roundtrip.test.ts +0 -257
  183. package/src/import/testdata/configs-secrets.yaml +0 -15
  184. package/src/import/testdata/full.yaml +0 -43
  185. package/src/import/testdata/names-and-fields.yaml +0 -44
  186. package/src/import/testdata/simple.yaml +0 -9
  187. package/src/import/testdata/tar.ts +0 -24
  188. package/src/import/testdata/webapp.yaml +0 -41
  189. package/src/index.ts +0 -32
  190. package/src/interpolation.test.ts +0 -41
  191. package/src/interpolation.ts +0 -76
  192. package/src/lint/audit-catalog.ts +0 -28
  193. package/src/lint/audit-lineage.ts +0 -48
  194. package/src/lint/post-synth/add-url-checksum.ts +0 -38
  195. package/src/lint/post-synth/apt-no-recommends.ts +0 -43
  196. package/src/lint/post-synth/apt-update-alone.ts +0 -39
  197. package/src/lint/post-synth/cache-busting-copy.ts +0 -65
  198. package/src/lint/post-synth/copy-from-stage.ts +0 -54
  199. package/src/lint/post-synth/docker-helpers.ts +0 -194
  200. package/src/lint/post-synth/index.ts +0 -33
  201. package/src/lint/post-synth/no-latest-image.ts +0 -36
  202. package/src/lint/post-synth/no-root-user.ts +0 -38
  203. package/src/lint/post-synth/post-synth.test.ts +0 -330
  204. package/src/lint/post-synth/prefer-copy.ts +0 -53
  205. package/src/lint/post-synth/relative-workdir.ts +0 -38
  206. package/src/lint/post-synth/repeated-cmd.ts +0 -35
  207. package/src/lint/post-synth/root-after-user.ts +0 -44
  208. package/src/lint/post-synth/ssh-port-exposed.ts +0 -68
  209. package/src/lint/post-synth/unused-global-arg.ts +0 -38
  210. package/src/lint/post-synth/unused-volume.ts +0 -49
  211. package/src/lint/rules/data/deprecated-images.ts +0 -28
  212. package/src/lint/rules/data/known-base-images.ts +0 -20
  213. package/src/lint/rules/index.ts +0 -6
  214. package/src/lint/rules/no-latest-tag.ts +0 -63
  215. package/src/lint/rules/per-kind-order.ts +0 -130
  216. package/src/lint/rules/rules.test.ts +0 -170
  217. package/src/list-artifacts.test.ts +0 -141
  218. package/src/list-artifacts.ts +0 -164
  219. package/src/lsp/completions.test.ts +0 -40
  220. package/src/lsp/completions.ts +0 -21
  221. package/src/lsp/hover.test.ts +0 -35
  222. package/src/lsp/hover.ts +0 -39
  223. package/src/package-cli.ts +0 -25
  224. package/src/plugin.test.ts +0 -121
  225. package/src/plugin.ts +0 -268
  226. package/src/serializer.test.ts +0 -545
  227. package/src/serializer.ts +0 -444
  228. package/src/skills/chant-docker-patterns.md +0 -222
  229. package/src/skills/chant-docker.md +0 -156
  230. package/src/spec/fetch-compose.ts +0 -35
  231. package/src/spec/fetch-engine.ts +0 -25
  232. package/src/spec/parse-compose.ts +0 -195
  233. package/src/spec/parse-engine.ts +0 -59
  234. package/src/typecheck.e2e.test.ts +0 -125
  235. package/src/typed-props.test.ts +0 -60
  236. package/src/validate-cli.ts +0 -19
  237. package/src/validate.test.ts +0 -16
  238. package/src/validate.ts +0 -44
  239. package/src/variables.test.ts +0 -32
  240. package/src/variables.ts +0 -47
  241. /package/{src → dist}/generated/lexicon-docker.json +0 -0
@@ -1,75 +0,0 @@
1
- /**
2
- * DockerWebService composite: one HTTP service as a Compose service, built
3
- * from a Dockerfile or run from an image, listening on one port, with a
4
- * health check on an HTTP path.
5
- *
6
- * It is the shape a single web app takes when Compose runs it, and the kind a
7
- * component names in its contract's `composites` when it deploys one
8
- * (#2662), so `chant workspace graph --composites` can offer that component
9
- * for the instance.
10
- */
11
-
12
- import { Composite, mergeDefaults } from "@intentius/chant";
13
- import { Service } from "../generated/index";
14
-
15
- export interface DockerWebServiceProps {
16
- /** Build the image from a Dockerfile: the context, and the Dockerfile's path in it (default: "Dockerfile"). */
17
- build?: { context: string; dockerfile?: string };
18
- /** The image to run, or the tag to give the built one. One of `build` and `image` is required. */
19
- image?: string;
20
- /** The port the app listens on in the container. It is also passed to the app as `PORT`. */
21
- port: number;
22
- /** The port published on the host (default: `port`). */
23
- hostPort?: number;
24
- /** More environment variables. A `PORT` here overrides the one from `port`. */
25
- environment?: Record<string, string>;
26
- /** An HTTP path the health check fetches with `wget` inside the container (default: no health check). */
27
- healthPath?: string;
28
- /** Restart policy (default: "unless-stopped"). */
29
- restart?: string;
30
- /** Per-member defaults for fine-grained overrides. */
31
- defaults?: {
32
- service?: Partial<Record<string, unknown>>;
33
- };
34
- }
35
-
36
- /**
37
- * One HTTP service as a Compose service, with a published port and an HTTP
38
- * health check. Returns the service, keyed by the export name plus `Service`.
39
- *
40
- * @example
41
- * ```ts
42
- * import { DockerWebService } from "@intentius/chant-lexicon-docker";
43
- *
44
- * export const app = DockerWebService({
45
- * build: { context: "../app" },
46
- * image: "app:local",
47
- * port: 8080,
48
- * healthPath: "/healthz",
49
- * });
50
- * ```
51
- */
52
- export const DockerWebService = Composite((props: DockerWebServiceProps) => {
53
- const { build, image, port, hostPort = port, environment, healthPath, restart = "unless-stopped", defaults: defs } = props;
54
- if (!build && !image) throw new Error("DockerWebService: give `build`, `image`, or both");
55
-
56
- const service = new Service(mergeDefaults({
57
- ...(build ? { build: { context: build.context, dockerfile: build.dockerfile ?? "Dockerfile" } } : {}),
58
- ...(image ? { image } : {}),
59
- ports: [`${hostPort}:${port}`],
60
- environment: { PORT: String(port), ...environment },
61
- restart,
62
- ...(healthPath
63
- ? {
64
- healthcheck: {
65
- test: ["CMD", "wget", "-qO-", `http://127.0.0.1:${port}${healthPath}`],
66
- interval: "30s",
67
- timeout: "5s",
68
- retries: 3,
69
- },
70
- }
71
- : {}),
72
- }, defs?.service));
73
-
74
- return { service };
75
- }, "DockerWebService");
@@ -1,9 +0,0 @@
1
- /**
2
- * Docker lexicon composites: factory functions that return pre-configured
3
- * multi-resource bundles.
4
- */
5
-
6
- export { DockerOtelCollector } from "./docker-otel-collector";
7
- export type { DockerOtelCollectorProps } from "./docker-otel-collector";
8
- export { DockerWebService } from "./docker-web-service";
9
- export type { DockerWebServiceProps } from "./docker-web-service";
@@ -1,33 +0,0 @@
1
- import { describe, test, expect } from "vitest";
2
- import { analyzeDockerCoverage, computeCoverage } from "./coverage";
3
-
4
- describe("analyzeDockerCoverage", () => {
5
- test("is an async function", () => {
6
- expect(typeof analyzeDockerCoverage).toBe("function");
7
- });
8
-
9
- test("throws when generated dir does not exist", async () => {
10
- await expect(
11
- analyzeDockerCoverage({ basePath: "/tmp/nonexistent-docker-lexicon-test" }),
12
- ).rejects.toThrow();
13
- });
14
- });
15
-
16
- describe("computeCoverage", () => {
17
- test("is a function", () => {
18
- expect(typeof computeCoverage).toBe("function");
19
- });
20
-
21
- test("handles a minimal lexicon JSON", () => {
22
- const minimal = JSON.stringify({
23
- Service: {
24
- resourceType: "Docker::Compose::Service",
25
- kind: "resource",
26
- description: "A service",
27
- properties: {},
28
- },
29
- });
30
- const report = computeCoverage(minimal);
31
- expect(report).toBeDefined();
32
- });
33
- });
package/src/coverage.ts DELETED
@@ -1,54 +0,0 @@
1
- /**
2
- * Coverage analysis for Docker lexicon.
3
- */
4
-
5
- import { existsSync, readFileSync } from "fs";
6
- import { join, dirname } from "path";
7
- import { fileURLToPath } from "url";
8
- import {
9
- computeCoverage,
10
- overallPct,
11
- formatSummary,
12
- formatVerbose,
13
- checkThresholds,
14
- type CoverageReport,
15
- type CoverageThresholds,
16
- } from "@intentius/chant/codegen/coverage";
17
-
18
- export type { CoverageReport, CoverageThresholds };
19
- export { computeCoverage, overallPct, formatSummary, formatVerbose, checkThresholds };
20
-
21
- /**
22
- * Run coverage analysis for the Docker lexicon.
23
- */
24
- export async function analyzeDockerCoverage(opts?: {
25
- basePath?: string;
26
- verbose?: boolean;
27
- minOverall?: number;
28
- }): Promise<CoverageReport> {
29
- const basePath = opts?.basePath ?? dirname(dirname(fileURLToPath(import.meta.url)));
30
- const lexiconPath = join(basePath, "src", "generated", "lexicon-docker.json");
31
-
32
- if (!existsSync(lexiconPath)) {
33
- throw new Error(`Generated lexicon not found at ${lexiconPath}. Run "chant dev generate" first.`);
34
- }
35
-
36
- const content = readFileSync(lexiconPath, "utf-8");
37
- const report = computeCoverage(content);
38
-
39
- if (opts?.verbose) {
40
- console.error(formatVerbose(report));
41
- } else {
42
- console.error(formatSummary(report));
43
- }
44
-
45
- if (typeof opts?.minOverall === "number") {
46
- const result = checkThresholds(report, { minOverallPct: opts.minOverall });
47
- if (!result.ok) {
48
- for (const v of result.violations) console.error(` FAIL: ${v}`);
49
- throw new Error("Coverage below threshold");
50
- }
51
- }
52
-
53
- return report;
54
- }
@@ -1,85 +0,0 @@
1
- import { describe, test, expect } from "vitest";
2
- import {
3
- DEFAULT_LABELS_MARKER,
4
- DEFAULT_ANNOTATIONS_MARKER,
5
- defaultLabels,
6
- defaultAnnotations,
7
- isDefaultLabels,
8
- isDefaultAnnotations,
9
- } from "./default-labels";
10
-
11
- describe("DEFAULT_LABELS_MARKER", () => {
12
- test("is a well-known symbol", () => {
13
- expect(typeof DEFAULT_LABELS_MARKER).toBe("symbol");
14
- expect(DEFAULT_LABELS_MARKER.toString()).toContain("docker.defaultLabels");
15
- });
16
- });
17
-
18
- describe("DEFAULT_ANNOTATIONS_MARKER", () => {
19
- test("is a well-known symbol", () => {
20
- expect(typeof DEFAULT_ANNOTATIONS_MARKER).toBe("symbol");
21
- expect(DEFAULT_ANNOTATIONS_MARKER.toString()).toContain("docker.defaultAnnotations");
22
- });
23
- });
24
-
25
- describe("defaultLabels", () => {
26
- test("creates a DefaultLabels entity", () => {
27
- const labels = { "app.team": "platform", "app.managed-by": "chant" };
28
- const entity = defaultLabels(labels);
29
-
30
- expect(entity.lexicon).toBe("docker");
31
- expect(entity.entityType).toBe("Docker::DefaultLabels");
32
- expect(entity.props.labels).toEqual(labels);
33
- });
34
-
35
- test("has DEFAULT_LABELS_MARKER", () => {
36
- const entity = defaultLabels({ "x": "y" });
37
- expect(DEFAULT_LABELS_MARKER in entity).toBe(true);
38
- });
39
- });
40
-
41
- describe("defaultAnnotations", () => {
42
- test("creates a DefaultAnnotations entity", () => {
43
- const annotations = { "app.version": "1.0.0" };
44
- const entity = defaultAnnotations(annotations);
45
-
46
- expect(entity.lexicon).toBe("docker");
47
- expect(entity.entityType).toBe("Docker::DefaultAnnotations");
48
- expect(entity.props.annotations).toEqual(annotations);
49
- });
50
-
51
- test("has DEFAULT_ANNOTATIONS_MARKER", () => {
52
- const entity = defaultAnnotations({ "x": "y" });
53
- expect(DEFAULT_ANNOTATIONS_MARKER in entity).toBe(true);
54
- });
55
- });
56
-
57
- describe("isDefaultLabels", () => {
58
- test("returns true for defaultLabels entity", () => {
59
- const entity = defaultLabels({ "x": "y" });
60
- expect(isDefaultLabels(entity)).toBe(true);
61
- });
62
-
63
- test("returns false for plain objects", () => {
64
- expect(isDefaultLabels({})).toBe(false);
65
- expect(isDefaultLabels(null)).toBe(false);
66
- expect(isDefaultLabels("string")).toBe(false);
67
- });
68
- });
69
-
70
- describe("isDefaultAnnotations", () => {
71
- test("returns true for defaultAnnotations entity", () => {
72
- const entity = defaultAnnotations({ "x": "y" });
73
- expect(isDefaultAnnotations(entity)).toBe(true);
74
- });
75
-
76
- test("returns false for defaultLabels", () => {
77
- const entity = defaultLabels({ "x": "y" });
78
- expect(isDefaultAnnotations(entity)).toBe(false);
79
- });
80
-
81
- test("returns false for plain objects", () => {
82
- expect(isDefaultAnnotations({})).toBe(false);
83
- expect(isDefaultAnnotations(null)).toBe(false);
84
- });
85
- });
@@ -1,72 +0,0 @@
1
- /**
2
- * Default labels for Docker Compose services.
3
- *
4
- * Follows the K8s lexicon pattern for defaultLabels/defaultAnnotations.
5
- * The serializer merges these into every Compose service's labels map.
6
- */
7
-
8
- import { DECLARABLE_MARKER, type Declarable } from "@intentius/chant/declarable";
9
-
10
- export const DEFAULT_LABELS_MARKER = Symbol.for("docker.defaultLabels");
11
- export const DEFAULT_ANNOTATIONS_MARKER = Symbol.for("docker.defaultAnnotations");
12
-
13
- export interface DefaultLabels extends Declarable {
14
- readonly [DEFAULT_LABELS_MARKER]: true;
15
- readonly props: { labels: Record<string, string> };
16
- }
17
-
18
- export interface DefaultAnnotations extends Declarable {
19
- readonly [DEFAULT_ANNOTATIONS_MARKER]: true;
20
- readonly props: { annotations: Record<string, string> };
21
- }
22
-
23
- export function isDefaultLabels(value: unknown): value is DefaultLabels {
24
- return (
25
- typeof value === "object" &&
26
- value !== null &&
27
- DEFAULT_LABELS_MARKER in value
28
- );
29
- }
30
-
31
- export function isDefaultAnnotations(value: unknown): value is DefaultAnnotations {
32
- return (
33
- typeof value === "object" &&
34
- value !== null &&
35
- DEFAULT_ANNOTATIONS_MARKER in value
36
- );
37
- }
38
-
39
- /**
40
- * Create a DefaultLabels entity that the serializer will merge into all services.
41
- *
42
- * @example
43
- * export const labels = defaultLabels({
44
- * "com.example.team": "platform",
45
- * "com.example.managed-by": "chant",
46
- * });
47
- */
48
- export function defaultLabels(labels: Record<string, string>): DefaultLabels {
49
- return {
50
- [DECLARABLE_MARKER]: true,
51
- [DEFAULT_LABELS_MARKER]: true,
52
- lexicon: "docker",
53
- entityType: "Docker::DefaultLabels",
54
- kind: "resource",
55
- props: { labels },
56
- };
57
- }
58
-
59
- /**
60
- * Create a DefaultAnnotations entity.
61
- * (Not used by Compose directly, but useful for Dockerfile LABEL instructions.)
62
- */
63
- export function defaultAnnotations(annotations: Record<string, string>): DefaultAnnotations {
64
- return {
65
- [DECLARABLE_MARKER]: true,
66
- [DEFAULT_ANNOTATIONS_MARKER]: true,
67
- lexicon: "docker",
68
- entityType: "Docker::DefaultAnnotations",
69
- kind: "resource",
70
- props: { annotations },
71
- };
72
- }
package/src/detect.ts DELETED
@@ -1,7 +0,0 @@
1
- /** Edge-safe template detection for docker (Compose) — see #426. */
2
- export function detectTemplate(data: unknown): boolean {
3
- if (typeof data !== "object" || data === null) return false;
4
- const obj = data as Record<string, unknown>;
5
- // Docker Compose files have a services: key
6
- return "services" in obj;
7
- }
@@ -1,20 +0,0 @@
1
- /**
2
- * The order a Dockerfile stage's per-kind fields (`run`, `copy`, `user`, ...)
3
- * are written in when the stage has no `steps`. It never changes, so a
4
- * Dockerfile declared with per-kind fields builds the same output it always
5
- * has; `steps` is how a stage controls its own order.
6
- */
7
- export const PER_KIND_ORDER = [
8
- "arg", "env", "workdir", "user", "run", "copy", "add",
9
- "expose", "volume", "label", "entrypoint", "cmd", "healthcheck",
10
- ] as const;
11
-
12
- export type PerKindField = (typeof PER_KIND_ORDER)[number];
13
-
14
- /** The step keys whose array value is written in JSON exec form. */
15
- export const EXEC_FORM_STEPS: ReadonlySet<string> = new Set(["run", "cmd", "entrypoint", "shell"]);
16
-
17
- /** Every instruction a step can name. FROM is the stage's own field. */
18
- export const STEP_INSTRUCTIONS: ReadonlySet<string> = new Set([
19
- ...PER_KIND_ORDER, "shell", "stopsignal", "onbuild",
20
- ]);
@@ -1,141 +0,0 @@
1
- /**
2
- * The Dockerfile examples in the docs and skills build, and build what the
3
- * page says they do.
4
- *
5
- * - A ```typescript block with no title that declares a Dockerfile is run
6
- * and serialized. When the next code block is an untitled ```dockerfile
7
- * block, the built file must equal it.
8
- * - A titled ```typescript block (`title="src/web.ts"`) must equal that file
9
- * in examples/dockerfile-sharing, and a titled ```dockerfile block
10
- * (`title="Dockerfile.web"`) must equal that file from building the
11
- * example.
12
- * - In importing.mdx, importing the ```dockerfile block titled "Dockerfile"
13
- * must give the ```typescript block that follows it.
14
- */
15
-
16
- import { describe, test, expect } from "vitest";
17
- import { readFileSync } from "fs";
18
- import { join } from "path";
19
- import * as ts from "typescript";
20
- import { build } from "@intentius/chant/build";
21
- import * as chant from "@intentius/chant";
22
- import type { Declarable } from "@intentius/chant/declarable";
23
- import * as lexicon from "./index";
24
- import { dockerSerializer } from "./serializer";
25
- import { DockerTemplateGenerator, DockerTemplateParser } from "./import/adapter";
26
-
27
- const root = join(import.meta.dirname, "..");
28
- const sharingExample = join(root, "examples", "dockerfile-sharing");
29
-
30
- interface Block {
31
- lang: string;
32
- title?: string;
33
- code: string;
34
- /** The prose between the previous code block and this one. */
35
- before: string;
36
- }
37
-
38
- function blocks(file: string): Block[] {
39
- const text = readFileSync(join(root, file), "utf8");
40
- const out: Block[] = [];
41
- let last = 0;
42
- for (const m of text.matchAll(/^```(\w+)([^\n]*)\n([\s\S]*?)^```$/gm)) {
43
- const title = m[2]!.match(/title="([^"]+)"/)?.[1];
44
- out.push({ lang: m[1]!, ...(title ? { title } : {}), code: m[3]!, before: text.slice(last, m.index) });
45
- last = m.index! + m[0].length;
46
- }
47
- return out;
48
- }
49
-
50
- /**
51
- * Run one TypeScript block as a module and serialize the Dockerfiles it
52
- * exports. A block whose first line is a path comment (`// src/web.ts`) is
53
- * one module of a multi-file example: `modules` holds the exports of the
54
- * page's earlier modules, by path, for its relative imports.
55
- */
56
- function buildBlock(code: string, pageModules: Map<string, Record<string, unknown>> = new Map()): Record<string, string> {
57
- const js = ts.transpileModule(code, { compilerOptions: { module: ts.ModuleKind.CommonJS, target: ts.ScriptTarget.ES2022 } }).outputText;
58
- const modules: Record<string, unknown> = { "@intentius/chant-lexicon-docker": lexicon, "@intentius/chant": chant };
59
- const path = code.match(/^\/\/ (src\/\S+)\.ts\s*$/m)?.[1];
60
- const req = (name: string): unknown => {
61
- if (name.startsWith("./") && path) {
62
- const target = join(path, "..", name).replace(/\\/g, "/");
63
- const found = pageModules.get(target);
64
- if (found) return found;
65
- }
66
- if (!(name in modules)) throw new Error(`docs example imports ${name}, which this test does not provide`);
67
- return modules[name];
68
- };
69
- const mod = { exports: {} as Record<string, unknown> };
70
- // Snippets that leave out the import line still see the lexicon's exports.
71
- const globals = Object.keys(lexicon).filter((k) => /^[A-Za-z_$][\w$]*$/.test(k));
72
- new Function("require", "module", "exports", ...globals, js)(req, mod, mod.exports, ...globals.map((k) => (lexicon as Record<string, unknown>)[k]));
73
- if (path) pageModules.set(path, mod.exports);
74
- const entities = new Map<string, Declarable>();
75
- for (const [name, value] of Object.entries(mod.exports)) {
76
- if (value && typeof value === "object" && "entityType" in value) entities.set(name, value as Declarable);
77
- }
78
- const result = dockerSerializer.serialize(entities);
79
- return typeof result === "string" ? {} : (result.files ?? {});
80
- }
81
-
82
- const PAGES = [
83
- "docs/pages/dockerfiles.mdx",
84
- "docs/pages/examples.mdx",
85
- "docs/pages/lint-rules.mdx",
86
- "src/skills/chant-docker.md",
87
- "src/skills/chant-docker-patterns.md",
88
- ];
89
-
90
- describe("docs Dockerfile examples", () => {
91
- for (const page of PAGES) {
92
- test(`${page}: every Dockerfile example builds what the page shows`, () => {
93
- const list = blocks(page);
94
- const pageModules = new Map<string, Record<string, unknown>>();
95
- let checked = 0;
96
- list.forEach((b, i) => {
97
- if (b.lang !== "typescript" || b.title) return;
98
- const isModule = /^\/\/ src\/\S+\.ts\s*$/m.test(b.code);
99
- if (!b.code.includes("new Dockerfile(") && !isModule) return;
100
- const files = buildBlock(b.code, pageModules);
101
- if (!b.code.includes("new Dockerfile(")) return;
102
- expect(Object.keys(files).length, `${page} block ${i + 1} declares a Dockerfile`).toBeGreaterThan(0);
103
- checked++;
104
- // The output shown right after it, under a "`Dockerfile.name`:" line.
105
- const next = list[i + 1];
106
- if (next && next.lang === "dockerfile" && !next.title && /^\s*`Dockerfile\.\w+`:\s*$/.test(next.before)) {
107
- expect(Object.values(files).join("---\n"), `${page} block ${i + 1}`).toBe(next.code);
108
- }
109
- });
110
- expect(checked, `${page} has Dockerfile examples`).toBeGreaterThan(0);
111
- });
112
- }
113
-
114
- test("dockerfiles.mdx sharing section matches the dockerfile-sharing example and its build", async () => {
115
- const titled = blocks("docs/pages/dockerfiles.mdx").filter((b) => b.title);
116
- const sources = titled.filter((b) => b.lang === "typescript");
117
- const outputs = titled.filter((b) => b.lang === "dockerfile");
118
- expect(sources.map((b) => b.title)).toEqual(["src/shared/node.ts", "src/web.ts", "src/worker.ts", "src/shared/node-image.ts", "src/api.ts"]);
119
- for (const b of sources) {
120
- expect(b.code, b.title).toBe(readFileSync(join(sharingExample, b.title!), "utf8"));
121
- }
122
-
123
- const result = await build(join(sharingExample, "src"), [dockerSerializer]);
124
- expect(result.errors).toEqual([]);
125
- const files = (result.outputs.get("docker") as unknown as { files: Record<string, string> }).files;
126
- expect(outputs.map((b) => b.title).sort()).toEqual(Object.keys(files).sort());
127
- for (const b of outputs) {
128
- expect(b.code, b.title).toBe(files[b.title!]);
129
- }
130
- });
131
-
132
- test("importing.mdx shows what importing its Dockerfile produces", () => {
133
- const list = blocks("docs/pages/importing.mdx");
134
- const at = list.findIndex((b) => b.lang === "dockerfile" && b.title === "Dockerfile");
135
- expect(at).toBeGreaterThan(-1);
136
- const [file] = new DockerTemplateGenerator().generate(new DockerTemplateParser().parse(list[at]!.code));
137
- expect(list[at + 1]!.code).toBe(file!.content.endsWith("\n") ? file!.content : `${file!.content}\n`);
138
- // And building the import gives the Dockerfile back.
139
- expect(Object.values(buildBlock(list[at + 1]!.code))[0]).toBe(list[at]!.code.replace(/^#.*\n/gm, ""));
140
- });
141
- });
@@ -1,90 +0,0 @@
1
- /**
2
- * Live export for the docker lexicon (#4388): implements
3
- * `LexiconPlugin.exportResources()` so `chant import --from <env>` regenerates
4
- * a compose project's services, and the configs they read, as chant
5
- * TypeScript.
6
- *
7
- * Which project: `COMPOSE_PROJECT_NAME` when set, else the environment name.
8
- * The containers are found by compose's `com.docker.compose.project` label.
9
- * All Engine I/O lives here; mapping is pure in `./import/live-export`.
10
- */
11
-
12
- import type { ExportedTemplate, ResourceSelector } from "@intentius/chant/lexicon";
13
- import { defaultDockerEngine, singleFileText, type DockerEngine } from "./import/engine";
14
- import {
15
- buildExportFromProject,
16
- configCandidates,
17
- isChantOwned,
18
- PROJECT_LABEL,
19
- serviceContainers,
20
- type ContainerInspect,
21
- type ImageInspect,
22
- type LiveService,
23
- } from "./import/live-export";
24
-
25
- function json<T>(body: Buffer): T | undefined {
26
- try {
27
- return JSON.parse(body.toString("utf8")) as T;
28
- } catch {
29
- return undefined;
30
- }
31
- }
32
-
33
- /** The compose project an environment exports. */
34
- export function projectFor(environment: string): string {
35
- return process.env.COMPOSE_PROJECT_NAME || environment;
36
- }
37
-
38
- export async function exportResources(
39
- options: {
40
- environment: string;
41
- selector?: ResourceSelector;
42
- owned?: boolean;
43
- verbatim?: boolean;
44
- },
45
- engine: DockerEngine = defaultDockerEngine(),
46
- signal?: AbortSignal,
47
- ): Promise<ExportedTemplate> {
48
- const project = projectFor(options.environment);
49
- const filters = encodeURIComponent(JSON.stringify({ label: [`${PROJECT_LABEL}=${project}`] }));
50
- const list = await engine(`/containers/json?all=1&filters=${filters}`, signal);
51
- if (list.status !== 200) {
52
- throw new Error(`docker live export: listing the containers of compose project ${project} failed (${list.status}): ${list.body.toString("utf8").trim()}`);
53
- }
54
- const containers = serviceContainers(project, json<Array<{ Id?: string; Labels?: Record<string, string> }>>(list.body) ?? []);
55
-
56
- const services: LiveService[] = [];
57
- const images = new Map<string, ImageInspect | undefined>();
58
- for (const [name, id] of containers) {
59
- const res = await engine(`/containers/${encodeURIComponent(id)}/json`, signal);
60
- const container = res.status === 200 ? json<ContainerInspect>(res.body) : undefined;
61
- if (!container) continue;
62
-
63
- const ref = container.Config?.Image;
64
- if (ref && !images.has(ref)) {
65
- const img = await engine(`/images/${encodeURIComponent(ref)}/json`, signal);
66
- images.set(ref, img.status === 200 ? json<ImageInspect>(img.body) : undefined);
67
- }
68
-
69
- // Config files are read only for the services that are exported.
70
- const files: Record<string, string> = {};
71
- if (!options.owned || isChantOwned(container)) {
72
- for (const path of configCandidates(container)) {
73
- const res = await engine(`/containers/${encodeURIComponent(id)}/archive?path=${encodeURIComponent(path)}`, signal);
74
- if (res.status !== 200) continue;
75
- const text = singleFileText(res.body);
76
- if (text !== undefined) files[path] = text;
77
- }
78
- }
79
-
80
- services.push({ name, container, image: ref ? images.get(ref) : undefined, files });
81
- }
82
-
83
- if (options.owned) {
84
- console.warn(
85
- "[docker] the docker serializer stamps no ownership marker; under --owned only services labelled app.kubernetes.io/managed-by=chant (defaultLabels) are exported",
86
- );
87
- }
88
-
89
- return buildExportFromProject(project, services, options);
90
- }