@intentius/chant-lexicon-docker 0.124.97 → 0.124.99

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 +4 -5
  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 -248
  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,38 +0,0 @@
1
- /**
2
- * DKRD018: Relative WORKDIR
3
- *
4
- * A relative WORKDIR resolves against whatever directory the base image
5
- * left, which can change with the image. Use an absolute path, at least for
6
- * the first WORKDIR of a stage.
7
- */
8
-
9
- import type { PostSynthCheck, PostSynthContext, PostSynthDiagnostic } from "@intentius/chant/lint/post-synth";
10
- import { eachDockerfile, stageLabel } from "./docker-helpers";
11
-
12
- export const dkrd018: PostSynthCheck = {
13
- id: "DKRD018",
14
- description: "Relative WORKDIR before any absolute WORKDIR in the stage",
15
-
16
- check(ctx: PostSynthContext): PostSynthDiagnostic[] {
17
- const diagnostics: PostSynthDiagnostic[] = [];
18
-
19
- for (const { fileName, parsed } of eachDockerfile(ctx.outputs)) {
20
- for (const stage of parsed.stages) {
21
- for (const instr of stage.instructions) {
22
- if (instr.instruction !== "WORKDIR") continue;
23
- const dir = instr.value.trim().replace(/^["']|["']$/g, "");
24
- if (dir.startsWith("/") || dir.startsWith("$") || /^[A-Za-z]:[\\/]/.test(dir)) break;
25
- diagnostics.push({
26
- checkId: "DKRD018",
27
- severity: "warning",
28
- message: `${fileName} ${stageLabel(stage)}: WORKDIR ${dir} is relative to the base image's working directory. Use an absolute path.`,
29
- lexicon: "docker",
30
- });
31
- break;
32
- }
33
- }
34
- }
35
-
36
- return diagnostics;
37
- },
38
- };
@@ -1,35 +0,0 @@
1
- /**
2
- * DKRD015: More than one CMD or ENTRYPOINT in a stage
3
- *
4
- * Only the last CMD and the last ENTRYPOINT of a stage take effect; the
5
- * earlier ones are silently ignored.
6
- */
7
-
8
- import type { PostSynthCheck, PostSynthContext, PostSynthDiagnostic } from "@intentius/chant/lint/post-synth";
9
- import { eachDockerfile, instrText, stageLabel } from "./docker-helpers";
10
-
11
- export const dkrd015: PostSynthCheck = {
12
- id: "DKRD015",
13
- description: "More than one CMD or ENTRYPOINT in a stage — only the last one takes effect",
14
-
15
- check(ctx: PostSynthContext): PostSynthDiagnostic[] {
16
- const diagnostics: PostSynthDiagnostic[] = [];
17
-
18
- for (const { fileName, parsed } of eachDockerfile(ctx.outputs)) {
19
- for (const stage of parsed.stages) {
20
- for (const kw of ["CMD", "ENTRYPOINT"]) {
21
- const all = stage.instructions.filter((i) => i.instruction === kw);
22
- if (all.length < 2) continue;
23
- diagnostics.push({
24
- checkId: "DKRD015",
25
- severity: "warning",
26
- message: `${fileName} ${stageLabel(stage)}: ${all.length} ${kw} instructions; only the last (${instrText(all[all.length - 1]!)}) takes effect. Remove the others.`,
27
- lexicon: "docker",
28
- });
29
- }
30
- }
31
- }
32
-
33
- return diagnostics;
34
- },
35
- };
@@ -1,44 +0,0 @@
1
- /**
2
- * DKRD014: Root-only command after a non-root USER
3
- *
4
- * A RUN that installs packages or manages users and ownership (apt-get,
5
- * apk add, useradd, chown, ...) fails or misbehaves after USER switches to
6
- * an unprivileged user. Run root setup first, then switch USER.
7
- */
8
-
9
- import type { PostSynthCheck, PostSynthContext, PostSynthDiagnostic } from "@intentius/chant/lint/post-synth";
10
- import { commandText, eachDockerfile, instrText, isRootUser, stageLabel } from "./docker-helpers";
11
-
12
- const ROOT_ONLY = /(^|[\s;&|(])(apt-get\s+(install|update|upgrade|dist-upgrade|remove|purge)|apt\s+(install|update|upgrade)|apk\s+(add|update|upgrade|del)|yum\s+(install|update)|dnf\s+(install|update|upgrade)|microdnf\s+install|zypper\s+(install|in|refresh)|useradd|adduser|groupadd|addgroup|usermod|chown)\b/;
13
-
14
- export const dkrd014: PostSynthCheck = {
15
- id: "DKRD014",
16
- description: "RUN needs root but comes after USER switched to a non-root user",
17
-
18
- check(ctx: PostSynthContext): PostSynthDiagnostic[] {
19
- const diagnostics: PostSynthDiagnostic[] = [];
20
-
21
- for (const { fileName, parsed } of eachDockerfile(ctx.outputs)) {
22
- for (const stage of parsed.stages) {
23
- let user: string | undefined;
24
- for (const instr of stage.instructions) {
25
- if (instr.instruction === "USER") {
26
- user = instr.value.trim();
27
- continue;
28
- }
29
- if (instr.instruction !== "RUN" || user === undefined || isRootUser(user)) continue;
30
- const cmd = commandText(instr);
31
- if (/\bsudo\b/.test(cmd) || !ROOT_ONLY.test(cmd)) continue;
32
- diagnostics.push({
33
- checkId: "DKRD014",
34
- severity: "warning",
35
- message: `${fileName} ${stageLabel(stage)}: ${instrText(instr)} needs root but runs as USER ${user}. Move it before the USER step, or switch to USER root for it.`,
36
- lexicon: "docker",
37
- });
38
- }
39
- }
40
- }
41
-
42
- return diagnostics;
43
- },
44
- };
@@ -1,68 +0,0 @@
1
- /**
2
- * DKRD003: SSH Port Exposed
3
- *
4
- * Detects services exposing port 22 (SSH) on the host.
5
- * Exposing SSH externally is a security risk.
6
- */
7
-
8
- import type { PostSynthCheck, PostSynthContext, PostSynthDiagnostic } from "@intentius/chant/lint/post-synth";
9
- import { getPrimaryOutput, extractServices } from "./docker-helpers";
10
-
11
- function exposesSshPort(port: string): boolean {
12
- // Formats: "22", "22/tcp", "0.0.0.0:22:22", "127.0.0.1:22:22", "host:container"
13
- const normalized = port.trim();
14
- const parts = normalized.split(":");
15
-
16
- if (parts.length === 1) {
17
- // Just a port number: "22" or "22/tcp"
18
- const portNum = parts[0].split("/")[0];
19
- return portNum === "22";
20
- }
21
-
22
- if (parts.length === 2) {
23
- // "hostPort:containerPort" e.g. "22:22" — no IP binding, accessible on all interfaces
24
- const hostPort = parts[0].split("/")[0];
25
- return hostPort === "22";
26
- }
27
-
28
- if (parts.length >= 3) {
29
- // "ip:hostPort:containerPort" e.g. "127.0.0.1:22:22" or "0.0.0.0:22:22"
30
- const ip = parts[0];
31
- const hostPort = parts[1].split("/")[0];
32
- // Only flag if port is 22 AND not bound to loopback
33
- if (hostPort !== "22") return false;
34
- return ip !== "127.0.0.1" && ip !== "::1" && ip !== "localhost";
35
- }
36
-
37
- return false;
38
- }
39
-
40
- export const dkrd003: PostSynthCheck = {
41
- id: "DKRD003",
42
- description: "Service exposes SSH port (22) externally — this is a security risk",
43
-
44
- check(ctx: PostSynthContext): PostSynthDiagnostic[] {
45
- const diagnostics: PostSynthDiagnostic[] = [];
46
-
47
- for (const [_outputName, output] of ctx.outputs) {
48
- const yaml = getPrimaryOutput(output);
49
- if (!yaml) continue;
50
-
51
- const services = extractServices(yaml);
52
- for (const [name, svc] of services) {
53
- for (const port of svc.ports ?? []) {
54
- if (exposesSshPort(port)) {
55
- diagnostics.push({
56
- checkId: "DKRD003",
57
- severity: "error",
58
- message: `Service "${name}" exposes SSH port 22 externally (port mapping: "${port}"). This is a security risk.`,
59
- lexicon: "docker",
60
- });
61
- }
62
- }
63
- }
64
- }
65
-
66
- return diagnostics;
67
- },
68
- };
@@ -1,38 +0,0 @@
1
- /**
2
- * DKRD017: ARG before FROM that nothing uses
3
- *
4
- * An ARG declared before the first FROM is only visible to FROM lines, and
5
- * to stages that declare it again (`ARG NAME`). One that neither uses does
6
- * nothing.
7
- */
8
-
9
- import type { PostSynthCheck, PostSynthContext, PostSynthDiagnostic } from "@intentius/chant/lint/post-synth";
10
- import { eachDockerfile } from "./docker-helpers";
11
-
12
- export const dkrd017: PostSynthCheck = {
13
- id: "DKRD017",
14
- description: "ARG before the first FROM is not used by any FROM or stage",
15
-
16
- check(ctx: PostSynthContext): PostSynthDiagnostic[] {
17
- const diagnostics: PostSynthDiagnostic[] = [];
18
-
19
- for (const { fileName, content, parsed } of eachDockerfile(ctx.outputs)) {
20
- const fromLines = content.split("\n").filter((l) => /^\s*FROM\s/i.test(l)).join("\n");
21
- for (const arg of parsed.globalArgs) {
22
- const name = arg.value.trim().split("=")[0]!.trim();
23
- if (!name) continue;
24
- const used = new RegExp(`\\$\\{?${name}\\b`).test(fromLines);
25
- const redeclared = parsed.stages.some((s) => s.instructions.some((i) => i.instruction === "ARG" && i.value.trim().split("=")[0]!.trim() === name));
26
- if (used || redeclared) continue;
27
- diagnostics.push({
28
- checkId: "DKRD017",
29
- severity: "warning",
30
- message: `${fileName}: ARG ${name} is declared before FROM but no FROM uses it and no stage declares it again with ARG ${name}. Use it, declare it in the stage that needs it, or remove it.`,
31
- lexicon: "docker",
32
- });
33
- }
34
- }
35
-
36
- return diagnostics;
37
- },
38
- };
@@ -1,49 +0,0 @@
1
- /**
2
- * DKRD002: Unused Named Volume
3
- *
4
- * Detects top-level named volumes that are not mounted by any service.
5
- */
6
-
7
- import type { PostSynthCheck, PostSynthContext, PostSynthDiagnostic } from "@intentius/chant/lint/post-synth";
8
- import { getPrimaryOutput, extractServices, extractNamedVolumes } from "./docker-helpers";
9
-
10
- export const dkrd002: PostSynthCheck = {
11
- id: "DKRD002",
12
- description: "Named volume is declared but not mounted by any service",
13
-
14
- check(ctx: PostSynthContext): PostSynthDiagnostic[] {
15
- const diagnostics: PostSynthDiagnostic[] = [];
16
-
17
- for (const [_outputName, output] of ctx.outputs) {
18
- const yaml = getPrimaryOutput(output);
19
- if (!yaml) continue;
20
-
21
- const namedVolumes = extractNamedVolumes(yaml);
22
- if (namedVolumes.size === 0) continue;
23
-
24
- const services = extractServices(yaml);
25
- const mountedVolumes = new Set<string>();
26
-
27
- for (const svc of services.values()) {
28
- for (const vol of svc.volumes ?? []) {
29
- // Volume mount format: "volname:/container/path" or just "volname"
30
- const volumeName = vol.split(":")[0].trim();
31
- mountedVolumes.add(volumeName);
32
- }
33
- }
34
-
35
- for (const volName of namedVolumes) {
36
- if (!mountedVolumes.has(volName)) {
37
- diagnostics.push({
38
- checkId: "DKRD002",
39
- severity: "warning",
40
- message: `Named volume "${volName}" is declared but not mounted by any service.`,
41
- lexicon: "docker",
42
- });
43
- }
44
- }
45
- }
46
-
47
- return diagnostics;
48
- },
49
- };
@@ -1,28 +0,0 @@
1
- /**
2
- * Known deprecated or EOL Docker base images.
3
- */
4
-
5
- export const DEPRECATED_IMAGES: Array<{ image: string; reason: string; replacement?: string }> = [
6
- {
7
- image: "centos:8",
8
- reason: "CentOS 8 reached EOL on December 31, 2021",
9
- replacement: "rockylinux:8 or almalinux:8",
10
- },
11
- {
12
- image: "centos:latest",
13
- reason: "CentOS Stream is a rolling release; use a specific version",
14
- replacement: "rockylinux:9 or almalinux:9",
15
- },
16
- {
17
- image: "node:lts",
18
- reason: "Use a specific LTS version tag for reproducible builds",
19
- replacement: "node:20-alpine or node:22-alpine",
20
- },
21
- ];
22
-
23
- /**
24
- * Check if an image reference matches a deprecated entry.
25
- */
26
- export function findDeprecatedImage(imageRef: string): (typeof DEPRECATED_IMAGES)[number] | undefined {
27
- return DEPRECATED_IMAGES.find((d) => imageRef === d.image || imageRef.startsWith(d.image + "@"));
28
- }
@@ -1,20 +0,0 @@
1
- /**
2
- * Well-known Docker base images for rule validation.
3
- */
4
-
5
- export const KNOWN_BASE_IMAGES = new Set([
6
- "alpine", "ubuntu", "debian", "centos", "fedora", "amazonlinux",
7
- "node", "python", "ruby", "golang", "rust", "java", "openjdk",
8
- "nginx", "httpd", "caddy", "traefik",
9
- "postgres", "mysql", "mariadb", "mongodb", "redis", "memcached",
10
- "rabbitmq", "kafka", "zookeeper",
11
- "elasticsearch", "kibana", "logstash",
12
- "busybox", "scratch",
13
- ]);
14
-
15
- /**
16
- * Images that are safe to use without a tag (they have meaningful `latest`).
17
- */
18
- export const IMAGES_SAFE_LATEST = new Set([
19
- "scratch",
20
- ]);
@@ -1,6 +0,0 @@
1
- /**
2
- * All imperative lint rules for the Docker lexicon.
3
- */
4
-
5
- export { noLatestTagRule } from "./no-latest-tag";
6
- export { perKindOrderRule } from "./per-kind-order";
@@ -1,63 +0,0 @@
1
- /**
2
- * DKRS001: No Latest Tag
3
- *
4
- * Warns when a Service's image prop is set to a literal string
5
- * ending with `:latest` or has no tag (implies latest).
6
- * Using `:latest` prevents reproducible builds.
7
- */
8
-
9
- import type { LintRule, LintDiagnostic, LintContext } from "@intentius/chant/lint/rule";
10
- import { ts } from "@intentius/chant/lint/typescript";
11
-
12
- function isLatestImage(imageValue: string): boolean {
13
- const trimmed = imageValue.trim();
14
- if (!trimmed || trimmed.startsWith("${")) return false;
15
- // Has :latest tag
16
- if (trimmed.endsWith(":latest")) return true;
17
- // No tag at all (no colon after image name, no @sha256)
18
- const parts = trimmed.split("/");
19
- const lastPart = parts[parts.length - 1];
20
- if (!lastPart.includes(":") && !lastPart.includes("@")) return true;
21
- return false;
22
- }
23
-
24
- export const noLatestTagRule: LintRule = {
25
- id: "DKRS001",
26
- severity: "warning",
27
- category: "correctness",
28
- description: "Avoid :latest or untagged image references — use explicit version tags for reproducible builds",
29
-
30
- check(context: LintContext): LintDiagnostic[] {
31
- const { sourceFile } = context;
32
- const diagnostics: LintDiagnostic[] = [];
33
-
34
- function visit(node: ts.Node): void {
35
- // Look for `image: "..."` in object literals (properties named "image")
36
- if (
37
- ts.isPropertyAssignment(node) &&
38
- ts.isIdentifier(node.name) &&
39
- node.name.text === "image"
40
- ) {
41
- const init = node.initializer;
42
- if (ts.isStringLiteral(init) || ts.isNoSubstitutionTemplateLiteral(init)) {
43
- const text = init.text;
44
- if (isLatestImage(text)) {
45
- const { line, character } = sourceFile.getLineAndCharacterOfPosition(node.getStart());
46
- diagnostics.push({
47
- file: sourceFile.fileName,
48
- line: line + 1,
49
- column: character + 1,
50
- ruleId: "DKRS001",
51
- severity: "warning",
52
- message: `Image "${text}" uses :latest or has no tag. Use an explicit version tag (e.g., "nginx:1.25-alpine") for reproducible builds.`,
53
- });
54
- }
55
- }
56
- }
57
- ts.forEachChild(node, visit);
58
- }
59
-
60
- visit(sourceFile);
61
- return diagnostics;
62
- },
63
- };
@@ -1,130 +0,0 @@
1
- /**
2
- * DKRS002: Per-kind Dockerfile fields written in a different order
3
- *
4
- * A Dockerfile stage without `steps` writes its per-kind fields (`run`,
5
- * `copy`, `user`, ...) in a fixed order: ARG, ENV, WORKDIR, USER, RUN, COPY,
6
- * ADD, EXPOSE, VOLUME, LABEL, ENTRYPOINT, CMD, HEALTHCHECK. When the fields
7
- * are declared in another order (`copy` before `run`, `run` before `user`)
8
- * the generated Dockerfile does not run them in the order they read in.
9
- *
10
- * The fix rewrites the fields as `steps` in the fixed order, so the
11
- * generated Dockerfile stays the same, with a comment to reorder them.
12
- */
13
-
14
- import type { LintRule, LintDiagnostic, LintContext, LintFix } from "@intentius/chant/lint/rule";
15
- import { ts } from "@intentius/chant/lint/typescript";
16
- import { PER_KIND_ORDER, type PerKindField } from "../../dockerfile-order";
17
-
18
- const PER_KIND = new Set<string>(PER_KIND_ORDER);
19
- /** Per-kind fields that take one string; the rest take a list. */
20
- const SINGLE = new Set<string>(["workdir", "user", "entrypoint", "cmd", "healthcheck"]);
21
-
22
- const FIX_NOTE = "// Written by the DKRS002 fix in the fixed order the per-kind fields used, so the output is unchanged. Reorder the steps as the build needs.";
23
-
24
- function propName(p: ts.ObjectLiteralElementLike): string | undefined {
25
- if (!(ts.isPropertyAssignment(p) || ts.isShorthandPropertyAssignment(p))) return undefined;
26
- const n = p.name;
27
- if (ts.isIdentifier(n) || ts.isStringLiteral(n)) return n.text;
28
- return undefined;
29
- }
30
-
31
- function isDockerfileNew(node: ts.Node): node is ts.NewExpression {
32
- if (!ts.isNewExpression(node)) return false;
33
- const e = node.expression;
34
- return (ts.isIdentifier(e) && e.text === "Dockerfile") || (ts.isPropertyAccessExpression(e) && e.name.text === "Dockerfile");
35
- }
36
-
37
- /** The stage-shaped object literals of one `new Dockerfile({...})`. */
38
- function stageLiterals(arg: ts.ObjectLiteralExpression): ts.ObjectLiteralExpression[] {
39
- const stagesProp = arg.properties.find((p) => propName(p) === "stages");
40
- if (!stagesProp) return [arg];
41
- // With stages, the top-level per-kind fields are not written at all.
42
- if (!ts.isPropertyAssignment(stagesProp) || !ts.isArrayLiteralExpression(stagesProp.initializer)) return [];
43
- return stagesProp.initializer.elements.filter(ts.isObjectLiteralExpression);
44
- }
45
-
46
- /** The `{ key: value }` step texts for one per-kind field, or undefined when its value can't be split. */
47
- function stepTexts(sf: ts.SourceFile, key: string, p: ts.ObjectLiteralElementLike): string[] | undefined {
48
- if (!ts.isPropertyAssignment(p)) return undefined;
49
- const init = p.initializer;
50
- if (SINGLE.has(key)) return [`{ ${key}: ${init.getText(sf)} }`];
51
- if (!ts.isArrayLiteralExpression(init)) return undefined;
52
- const out: string[] = [];
53
- for (const el of init.elements) {
54
- if (ts.isSpreadElement(el) || ts.isOmittedExpression(el)) return undefined;
55
- out.push(`{ ${key}: ${el.getText(sf)} }`);
56
- }
57
- return out;
58
- }
59
-
60
- function buildFix(sf: ts.SourceFile, obj: ts.ObjectLiteralExpression, perKind: ts.ObjectLiteralElementLike[]): LintFix | undefined {
61
- const byKey = new Map<string, ts.ObjectLiteralElementLike>();
62
- for (const p of perKind) byKey.set(propName(p)!, p);
63
- const steps: string[] = [];
64
- for (const key of PER_KIND_ORDER) {
65
- const p = byKey.get(key);
66
- if (!p) continue;
67
- const texts = stepTexts(sf, key, p);
68
- if (!texts) return undefined;
69
- steps.push(...texts);
70
- }
71
-
72
- const first = perKind[0]!;
73
- const last = perKind[perKind.length - 1]!;
74
- const start = first.getStart(sf);
75
- const end = last.getEnd();
76
- const lineStart = sf.text.lastIndexOf("\n", start - 1) + 1;
77
- const indent = /^[ \t]*/.exec(sf.text.slice(lineStart, start))![0];
78
- // Other props between the first and last per-kind field (rare) are kept, ahead of steps.
79
- const kept = obj.properties.filter((p) => p.getStart(sf) > start && p.getEnd() < end && !perKind.includes(p)).map((p) => p.getText(sf));
80
- const stepsText = `${FIX_NOTE}\n${indent}steps: [\n${steps.map((s) => `${indent} ${s},`).join("\n")}\n${indent}]`;
81
- return { range: [start, end], replacement: [...kept, stepsText].join(`,\n${indent}`), kind: "replace" };
82
- }
83
-
84
- function check(context: LintContext): LintDiagnostic[] {
85
- const { sourceFile: sf } = context;
86
- const diagnostics: LintDiagnostic[] = [];
87
-
88
- const visit = (node: ts.Node): void => {
89
- if (isDockerfileNew(node)) {
90
- const arg = node.arguments?.[0];
91
- if (arg && ts.isObjectLiteralExpression(arg)) {
92
- for (const obj of stageLiterals(arg)) {
93
- if (obj.properties.some((p) => propName(p) === "steps")) continue;
94
- const perKind = obj.properties.filter((p) => PER_KIND.has(propName(p) ?? ""));
95
- const declared = perKind.map((p) => propName(p)!);
96
- const fixed = [...declared].sort((a, b) => PER_KIND_ORDER.indexOf(a as PerKindField) - PER_KIND_ORDER.indexOf(b as PerKindField));
97
- if (declared.join() === fixed.join()) continue;
98
- const { line, character } = sf.getLineAndCharacterOfPosition(perKind[0]!.getStart(sf));
99
- const fix = buildFix(sf, obj, perKind);
100
- diagnostics.push({
101
- file: sf.fileName,
102
- line: line + 1,
103
- column: character + 1,
104
- ruleId: "DKRS002",
105
- severity: "warning",
106
- message:
107
- `Dockerfile fields declared as ${declared.join(", ")} are written in the fixed order ${fixed.join(", ")}. ` +
108
- `Use steps to write the instructions in the order the build needs${fix ? " (chant lint --fix rewrites them as steps)" : ""}.`,
109
- ...(fix ? { fix } : {}),
110
- });
111
- }
112
- }
113
- }
114
- ts.forEachChild(node, visit);
115
- };
116
-
117
- visit(sf);
118
- return diagnostics;
119
- }
120
-
121
- export const perKindOrderRule: LintRule = {
122
- id: "DKRS002",
123
- severity: "warning",
124
- category: "correctness",
125
- description: "Dockerfile per-kind fields are written in a fixed order that differs from the declared order — use steps",
126
- check,
127
- fix(context: LintContext): LintFix[] {
128
- return check(context).flatMap((d) => (d.fix ? [d.fix] : []));
129
- },
130
- };