@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.
- package/dist/codegen/docs-cli.d.ts +0 -1
- package/dist/codegen/docs.d.ts +0 -1
- package/dist/codegen/generate-cli.d.ts +0 -1
- package/dist/codegen/generate-compose.d.ts +0 -1
- package/dist/codegen/generate-dockerfile.d.ts +0 -1
- package/dist/codegen/generate.d.ts +0 -1
- package/dist/codegen/naming.d.ts +0 -1
- package/dist/codegen/package.d.ts +0 -1
- package/dist/codegen/patches.d.ts +0 -1
- package/dist/codegen/versions.d.ts +0 -1
- package/dist/compose-key.d.ts +0 -1
- package/dist/composites/catalog.d.ts +0 -1
- package/dist/composites/docker-otel-collector.d.ts +0 -1
- package/dist/composites/docker-web-service.d.ts +0 -1
- package/dist/composites/index.d.ts +0 -1
- package/dist/coverage.d.ts +0 -1
- package/dist/default-labels.d.ts +0 -1
- package/dist/detect.d.ts +0 -1
- package/dist/dockerfile-order.d.ts +0 -1
- package/dist/export-resources.d.ts +0 -1
- package/dist/generated/index.d.ts +0 -1
- package/dist/generated/runtime.d.ts +0 -1
- package/dist/import/adapter.d.ts +0 -1
- package/dist/import/adapter.js +4 -2
- package/dist/import/embedded.d.ts +0 -1
- package/dist/import/engine.d.ts +0 -1
- package/dist/import/generator.d.ts +9 -2
- package/dist/import/generator.js +23 -1
- package/dist/import/live-export.d.ts +0 -1
- package/dist/import/parser.d.ts +0 -1
- package/dist/import/testdata/tar.d.ts +0 -1
- package/dist/index.d.ts +0 -1
- package/dist/integrity.json +2 -2
- package/dist/interpolation.d.ts +0 -1
- package/dist/lint/audit-catalog.d.ts +0 -1
- package/dist/lint/audit-lineage.d.ts +0 -1
- package/dist/lint/post-synth/add-url-checksum.d.ts +0 -1
- package/dist/lint/post-synth/apt-no-recommends.d.ts +0 -1
- package/dist/lint/post-synth/apt-update-alone.d.ts +0 -1
- package/dist/lint/post-synth/cache-busting-copy.d.ts +0 -1
- package/dist/lint/post-synth/copy-from-stage.d.ts +0 -1
- package/dist/lint/post-synth/docker-helpers.d.ts +0 -1
- package/dist/lint/post-synth/index.d.ts +0 -1
- package/dist/lint/post-synth/no-latest-image.d.ts +0 -1
- package/dist/lint/post-synth/no-root-user.d.ts +0 -1
- package/dist/lint/post-synth/prefer-copy.d.ts +0 -1
- package/dist/lint/post-synth/relative-workdir.d.ts +0 -1
- package/dist/lint/post-synth/repeated-cmd.d.ts +0 -1
- package/dist/lint/post-synth/root-after-user.d.ts +0 -1
- package/dist/lint/post-synth/ssh-port-exposed.d.ts +0 -1
- package/dist/lint/post-synth/unused-global-arg.d.ts +0 -1
- package/dist/lint/post-synth/unused-volume.d.ts +0 -1
- package/dist/lint/rules/data/deprecated-images.d.ts +0 -1
- package/dist/lint/rules/data/known-base-images.d.ts +0 -1
- package/dist/lint/rules/index.d.ts +0 -1
- package/dist/lint/rules/no-latest-tag.d.ts +0 -1
- package/dist/lint/rules/per-kind-order.d.ts +0 -1
- package/dist/list-artifacts.d.ts +0 -1
- package/dist/lsp/completions.d.ts +0 -1
- package/dist/lsp/hover.d.ts +0 -1
- package/dist/manifest.json +1 -1
- package/dist/package-cli.d.ts +0 -1
- package/dist/plugin.d.ts +0 -1
- package/dist/serializer.d.ts +0 -1
- package/dist/spec/fetch-compose.d.ts +0 -1
- package/dist/spec/fetch-engine.d.ts +0 -1
- package/dist/spec/parse-compose.d.ts +0 -1
- package/dist/spec/parse-engine.d.ts +0 -1
- package/dist/validate-cli.d.ts +0 -1
- package/dist/validate.d.ts +0 -1
- package/dist/variables.d.ts +0 -1
- package/package.json +4 -5
- package/dist/codegen/docs-cli.d.ts.map +0 -1
- package/dist/codegen/docs.d.ts.map +0 -1
- package/dist/codegen/generate-cli.d.ts.map +0 -1
- package/dist/codegen/generate-compose.d.ts.map +0 -1
- package/dist/codegen/generate-dockerfile.d.ts.map +0 -1
- package/dist/codegen/generate.d.ts.map +0 -1
- package/dist/codegen/naming.d.ts.map +0 -1
- package/dist/codegen/package.d.ts.map +0 -1
- package/dist/codegen/patches.d.ts.map +0 -1
- package/dist/codegen/versions.d.ts.map +0 -1
- package/dist/compose-key.d.ts.map +0 -1
- package/dist/composites/catalog.d.ts.map +0 -1
- package/dist/composites/docker-otel-collector.d.ts.map +0 -1
- package/dist/composites/docker-web-service.d.ts.map +0 -1
- package/dist/composites/index.d.ts.map +0 -1
- package/dist/coverage.d.ts.map +0 -1
- package/dist/default-labels.d.ts.map +0 -1
- package/dist/detect.d.ts.map +0 -1
- package/dist/dockerfile-order.d.ts.map +0 -1
- package/dist/export-resources.d.ts.map +0 -1
- package/dist/generated/index.d.ts.map +0 -1
- package/dist/generated/runtime.d.ts.map +0 -1
- package/dist/import/adapter.d.ts.map +0 -1
- package/dist/import/embedded.d.ts.map +0 -1
- package/dist/import/engine.d.ts.map +0 -1
- package/dist/import/generator.d.ts.map +0 -1
- package/dist/import/live-export.d.ts.map +0 -1
- package/dist/import/parser.d.ts.map +0 -1
- package/dist/import/testdata/tar.d.ts.map +0 -1
- package/dist/index.d.ts.map +0 -1
- package/dist/interpolation.d.ts.map +0 -1
- package/dist/lint/audit-catalog.d.ts.map +0 -1
- package/dist/lint/audit-lineage.d.ts.map +0 -1
- package/dist/lint/post-synth/add-url-checksum.d.ts.map +0 -1
- package/dist/lint/post-synth/apt-no-recommends.d.ts.map +0 -1
- package/dist/lint/post-synth/apt-update-alone.d.ts.map +0 -1
- package/dist/lint/post-synth/cache-busting-copy.d.ts.map +0 -1
- package/dist/lint/post-synth/copy-from-stage.d.ts.map +0 -1
- package/dist/lint/post-synth/docker-helpers.d.ts.map +0 -1
- package/dist/lint/post-synth/index.d.ts.map +0 -1
- package/dist/lint/post-synth/no-latest-image.d.ts.map +0 -1
- package/dist/lint/post-synth/no-root-user.d.ts.map +0 -1
- package/dist/lint/post-synth/prefer-copy.d.ts.map +0 -1
- package/dist/lint/post-synth/relative-workdir.d.ts.map +0 -1
- package/dist/lint/post-synth/repeated-cmd.d.ts.map +0 -1
- package/dist/lint/post-synth/root-after-user.d.ts.map +0 -1
- package/dist/lint/post-synth/ssh-port-exposed.d.ts.map +0 -1
- package/dist/lint/post-synth/unused-global-arg.d.ts.map +0 -1
- package/dist/lint/post-synth/unused-volume.d.ts.map +0 -1
- package/dist/lint/rules/data/deprecated-images.d.ts.map +0 -1
- package/dist/lint/rules/data/known-base-images.d.ts.map +0 -1
- package/dist/lint/rules/index.d.ts.map +0 -1
- package/dist/lint/rules/no-latest-tag.d.ts.map +0 -1
- package/dist/lint/rules/per-kind-order.d.ts.map +0 -1
- package/dist/list-artifacts.d.ts.map +0 -1
- package/dist/lsp/completions.d.ts.map +0 -1
- package/dist/lsp/hover.d.ts.map +0 -1
- package/dist/package-cli.d.ts.map +0 -1
- package/dist/plugin.d.ts.map +0 -1
- package/dist/serializer.d.ts.map +0 -1
- package/dist/spec/fetch-compose.d.ts.map +0 -1
- package/dist/spec/fetch-engine.d.ts.map +0 -1
- package/dist/spec/parse-compose.d.ts.map +0 -1
- package/dist/spec/parse-engine.d.ts.map +0 -1
- package/dist/validate-cli.d.ts.map +0 -1
- package/dist/validate.d.ts.map +0 -1
- package/dist/variables.d.ts.map +0 -1
- package/src/codegen/__snapshots__/okf.test.ts.snap +0 -555
- package/src/codegen/docs-cli.ts +0 -10
- package/src/codegen/docs.ts +0 -171
- package/src/codegen/generate-cli.ts +0 -36
- package/src/codegen/generate-compose.ts +0 -21
- package/src/codegen/generate-dockerfile.ts +0 -21
- package/src/codegen/generate.test.ts +0 -115
- package/src/codegen/generate.ts +0 -258
- package/src/codegen/naming.test.ts +0 -81
- package/src/codegen/naming.ts +0 -54
- package/src/codegen/okf.test.ts +0 -36
- package/src/codegen/package.ts +0 -59
- package/src/codegen/patches.ts +0 -42
- package/src/codegen/versions.ts +0 -46
- package/src/compose-key.ts +0 -31
- package/src/composites/catalog.test.ts +0 -39
- package/src/composites/catalog.ts +0 -118
- package/src/composites/docker-otel-collector.ts +0 -83
- package/src/composites/docker-web-service.test.ts +0 -34
- package/src/composites/docker-web-service.ts +0 -75
- package/src/composites/index.ts +0 -9
- package/src/coverage.test.ts +0 -33
- package/src/coverage.ts +0 -54
- package/src/default-labels.test.ts +0 -85
- package/src/default-labels.ts +0 -72
- package/src/detect.ts +0 -7
- package/src/dockerfile-order.ts +0 -20
- package/src/docs-examples.test.ts +0 -141
- package/src/export-resources.ts +0 -90
- package/src/generated/index.d.ts +0 -407
- package/src/generated/index.ts +0 -410
- package/src/generated/runtime.ts +0 -4
- package/src/import/adapter.ts +0 -99
- package/src/import/embedded-live.test.ts +0 -248
- package/src/import/embedded.ts +0 -83
- package/src/import/engine.ts +0 -107
- package/src/import/generator.test.ts +0 -134
- package/src/import/generator.ts +0 -202
- package/src/import/live-export.test.ts +0 -271
- package/src/import/live-export.ts +0 -359
- package/src/import/parser.test.ts +0 -137
- package/src/import/parser.ts +0 -269
- package/src/import/roundtrip.test.ts +0 -257
- package/src/import/testdata/configs-secrets.yaml +0 -15
- package/src/import/testdata/full.yaml +0 -43
- package/src/import/testdata/names-and-fields.yaml +0 -44
- package/src/import/testdata/simple.yaml +0 -9
- package/src/import/testdata/tar.ts +0 -24
- package/src/import/testdata/webapp.yaml +0 -41
- package/src/index.ts +0 -32
- package/src/interpolation.test.ts +0 -41
- package/src/interpolation.ts +0 -76
- package/src/lint/audit-catalog.ts +0 -28
- package/src/lint/audit-lineage.ts +0 -48
- package/src/lint/post-synth/add-url-checksum.ts +0 -38
- package/src/lint/post-synth/apt-no-recommends.ts +0 -43
- package/src/lint/post-synth/apt-update-alone.ts +0 -39
- package/src/lint/post-synth/cache-busting-copy.ts +0 -65
- package/src/lint/post-synth/copy-from-stage.ts +0 -54
- package/src/lint/post-synth/docker-helpers.ts +0 -194
- package/src/lint/post-synth/index.ts +0 -33
- package/src/lint/post-synth/no-latest-image.ts +0 -36
- package/src/lint/post-synth/no-root-user.ts +0 -38
- package/src/lint/post-synth/post-synth.test.ts +0 -330
- package/src/lint/post-synth/prefer-copy.ts +0 -53
- package/src/lint/post-synth/relative-workdir.ts +0 -38
- package/src/lint/post-synth/repeated-cmd.ts +0 -35
- package/src/lint/post-synth/root-after-user.ts +0 -44
- package/src/lint/post-synth/ssh-port-exposed.ts +0 -68
- package/src/lint/post-synth/unused-global-arg.ts +0 -38
- package/src/lint/post-synth/unused-volume.ts +0 -49
- package/src/lint/rules/data/deprecated-images.ts +0 -28
- package/src/lint/rules/data/known-base-images.ts +0 -20
- package/src/lint/rules/index.ts +0 -6
- package/src/lint/rules/no-latest-tag.ts +0 -63
- package/src/lint/rules/per-kind-order.ts +0 -130
- package/src/lint/rules/rules.test.ts +0 -170
- package/src/list-artifacts.test.ts +0 -141
- package/src/list-artifacts.ts +0 -164
- package/src/lsp/completions.test.ts +0 -40
- package/src/lsp/completions.ts +0 -21
- package/src/lsp/hover.test.ts +0 -35
- package/src/lsp/hover.ts +0 -39
- package/src/package-cli.ts +0 -25
- package/src/plugin.test.ts +0 -121
- package/src/plugin.ts +0 -268
- package/src/serializer.test.ts +0 -545
- package/src/serializer.ts +0 -444
- package/src/skills/chant-docker-patterns.md +0 -222
- package/src/skills/chant-docker.md +0 -156
- package/src/spec/fetch-compose.ts +0 -35
- package/src/spec/fetch-engine.ts +0 -25
- package/src/spec/parse-compose.ts +0 -195
- package/src/spec/parse-engine.ts +0 -59
- package/src/typecheck.e2e.test.ts +0 -125
- package/src/typed-props.test.ts +0 -60
- package/src/validate-cli.ts +0 -19
- package/src/validate.test.ts +0 -16
- package/src/validate.ts +0 -44
- package/src/variables.test.ts +0 -32
- package/src/variables.ts +0 -47
- /package/{src → dist}/generated/lexicon-docker.json +0 -0
package/src/import/parser.ts
DELETED
|
@@ -1,269 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Docker Compose + Dockerfile parser — converts existing YAML/Dockerfiles
|
|
3
|
-
* to an intermediate representation (IR) for TypeScript code generation.
|
|
4
|
-
*/
|
|
5
|
-
|
|
6
|
-
import { existsSync, readFileSync } from "node:fs";
|
|
7
|
-
import { dirname, join } from "node:path";
|
|
8
|
-
import { fileURLToPath } from "node:url";
|
|
9
|
-
import { parseYAML } from "@intentius/chant/yaml";
|
|
10
|
-
import type { ParseContext } from "@intentius/chant/import/parser";
|
|
11
|
-
import { delegateEmbedded } from "./embedded";
|
|
12
|
-
|
|
13
|
-
export interface ServiceIR {
|
|
14
|
-
kind: "service";
|
|
15
|
-
name: string;
|
|
16
|
-
props: Record<string, unknown>;
|
|
17
|
-
}
|
|
18
|
-
|
|
19
|
-
export interface VolumeIR {
|
|
20
|
-
kind: "volume";
|
|
21
|
-
name: string;
|
|
22
|
-
props: Record<string, unknown>;
|
|
23
|
-
}
|
|
24
|
-
|
|
25
|
-
export interface NetworkIR {
|
|
26
|
-
kind: "network";
|
|
27
|
-
name: string;
|
|
28
|
-
props: Record<string, unknown>;
|
|
29
|
-
}
|
|
30
|
-
|
|
31
|
-
export interface ConfigIR {
|
|
32
|
-
kind: "config";
|
|
33
|
-
name: string;
|
|
34
|
-
props: Record<string, unknown>;
|
|
35
|
-
}
|
|
36
|
-
|
|
37
|
-
export interface SecretIR {
|
|
38
|
-
kind: "secret";
|
|
39
|
-
name: string;
|
|
40
|
-
props: Record<string, unknown>;
|
|
41
|
-
}
|
|
42
|
-
|
|
43
|
-
export interface DockerfileStage {
|
|
44
|
-
from: string;
|
|
45
|
-
as?: string;
|
|
46
|
-
/**
|
|
47
|
-
* The stage's instructions after FROM, in source order. `instruction` is
|
|
48
|
-
* the upper-case keyword; `value` is the rest of the instruction as
|
|
49
|
-
* written, line continuations and heredoc bodies included.
|
|
50
|
-
*/
|
|
51
|
-
instructions: Array<{ instruction: string; value: string }>;
|
|
52
|
-
}
|
|
53
|
-
|
|
54
|
-
export interface DockerfileIR {
|
|
55
|
-
kind: "dockerfile";
|
|
56
|
-
name: string;
|
|
57
|
-
/** ARG values declared before the first FROM. */
|
|
58
|
-
globalArgs?: string[];
|
|
59
|
-
stages: DockerfileStage[];
|
|
60
|
-
}
|
|
61
|
-
|
|
62
|
-
export type DockerIR = ServiceIR | VolumeIR | NetworkIR | ConfigIR | SecretIR | DockerfileIR;
|
|
63
|
-
|
|
64
|
-
export interface ParseResult {
|
|
65
|
-
entities: DockerIR[];
|
|
66
|
-
warnings: string[];
|
|
67
|
-
}
|
|
68
|
-
|
|
69
|
-
/** The compose sections import reads, with the kind each holds and its entry in the lexicon. */
|
|
70
|
-
const SECTIONS = [
|
|
71
|
-
{ section: "services", kind: "service", entry: "Service" },
|
|
72
|
-
{ section: "volumes", kind: "volume", entry: "Volume" },
|
|
73
|
-
{ section: "networks", kind: "network", entry: "Network" },
|
|
74
|
-
{ section: "configs", kind: "config", entry: "DockerConfig" },
|
|
75
|
-
{ section: "secrets", kind: "secret", entry: "DockerSecret" },
|
|
76
|
-
] as const;
|
|
77
|
-
|
|
78
|
-
type ComposeKind = (typeof SECTIONS)[number]["kind"];
|
|
79
|
-
|
|
80
|
-
let fieldsCache: Map<ComposeKind, Set<string>> | undefined;
|
|
81
|
-
|
|
82
|
-
/**
|
|
83
|
-
* The fields the Compose spec defines for each kind, read from the generated
|
|
84
|
-
* lexicon (`lexicon-docker.json`, or `dist/meta.json` in a package built
|
|
85
|
-
* without it). The props types come from the same spec (#3934), so import
|
|
86
|
-
* keeps exactly what the types accept (#3937).
|
|
87
|
-
*/
|
|
88
|
-
export function composeFields(): Map<ComposeKind, Set<string>> {
|
|
89
|
-
if (fieldsCache) return fieldsCache;
|
|
90
|
-
const here = dirname(fileURLToPath(import.meta.url));
|
|
91
|
-
const candidates = [join(here, "..", "generated", "lexicon-docker.json"), join(here, "..", "..", "dist", "meta.json")];
|
|
92
|
-
const path = candidates.find((c) => existsSync(c));
|
|
93
|
-
if (!path) {
|
|
94
|
-
throw new Error(`docker import: the generated lexicon is missing (tried ${candidates.join(", ")}); run npm run generate in lexicons/docker`);
|
|
95
|
-
}
|
|
96
|
-
const lexicon = JSON.parse(readFileSync(path, "utf-8")) as Record<string, { properties?: Record<string, unknown> }>;
|
|
97
|
-
const fields = new Map<ComposeKind, Set<string>>();
|
|
98
|
-
for (const { kind, entry } of SECTIONS) {
|
|
99
|
-
fields.set(kind, new Set(Object.keys(lexicon[entry]?.properties ?? {})));
|
|
100
|
-
}
|
|
101
|
-
fieldsCache = fields;
|
|
102
|
-
return fields;
|
|
103
|
-
}
|
|
104
|
-
|
|
105
|
-
/**
|
|
106
|
-
* Keep every field the Compose spec defines for the kind, and `x-`
|
|
107
|
-
* extension fields. Anything else is dropped and named in `warnings`.
|
|
108
|
-
*/
|
|
109
|
-
function extractProps(
|
|
110
|
-
raw: unknown,
|
|
111
|
-
allowed: Set<string>,
|
|
112
|
-
where: string,
|
|
113
|
-
kind: string,
|
|
114
|
-
warnings: string[],
|
|
115
|
-
): Record<string, unknown> {
|
|
116
|
-
if (!raw || typeof raw !== "object" || Array.isArray(raw)) return {};
|
|
117
|
-
const props: Record<string, unknown> = {};
|
|
118
|
-
for (const [key, value] of Object.entries(raw as Record<string, unknown>)) {
|
|
119
|
-
if (allowed.has(key) || key.startsWith("x-")) props[key] = value;
|
|
120
|
-
else warnings.push(`${where}: "${key}" is not a Compose ${kind} field and was dropped`);
|
|
121
|
-
}
|
|
122
|
-
return props;
|
|
123
|
-
}
|
|
124
|
-
|
|
125
|
-
/**
|
|
126
|
-
* Parser for docker-compose.yml files.
|
|
127
|
-
* Converts YAML to an IR consumable by the TypeScript generator.
|
|
128
|
-
*/
|
|
129
|
-
export class DockerParser {
|
|
130
|
-
/**
|
|
131
|
-
* With `context.embedded` (`chant import`), a config's `content` another
|
|
132
|
-
* lexicon owns (a collector config) is handed to it (see ./embedded.ts).
|
|
133
|
-
* Without it, every config is kept as written.
|
|
134
|
-
*/
|
|
135
|
-
parse(content: string, context?: ParseContext): ParseResult {
|
|
136
|
-
if (!content.trim()) return { entities: [], warnings: [] };
|
|
137
|
-
return this.parseDocument(parseYAML(content) as Record<string, unknown>, context);
|
|
138
|
-
}
|
|
139
|
-
|
|
140
|
-
/** The same as {@link parse}, over a compose document already read (live export builds one). */
|
|
141
|
-
parseDocument(doc: Record<string, unknown> | undefined, context?: ParseContext): ParseResult {
|
|
142
|
-
const entities: DockerIR[] = [];
|
|
143
|
-
const warnings: string[] = [];
|
|
144
|
-
const fields = composeFields();
|
|
145
|
-
|
|
146
|
-
const known = new Set<string>(SECTIONS.map((s) => s.section));
|
|
147
|
-
for (const key of Object.keys(doc ?? {})) {
|
|
148
|
-
if (!known.has(key)) warnings.push(`"${key}" at the top level is not imported`);
|
|
149
|
-
}
|
|
150
|
-
|
|
151
|
-
for (const { section, kind } of SECTIONS) {
|
|
152
|
-
const entries = doc?.[section];
|
|
153
|
-
if (!entries || typeof entries !== "object" || Array.isArray(entries)) continue;
|
|
154
|
-
for (const [name, raw] of Object.entries(entries as Record<string, unknown>)) {
|
|
155
|
-
entities.push({
|
|
156
|
-
kind,
|
|
157
|
-
name,
|
|
158
|
-
props: extractProps(raw, fields.get(kind)!, `${section}.${name}`, kind, warnings),
|
|
159
|
-
} as DockerIR);
|
|
160
|
-
}
|
|
161
|
-
}
|
|
162
|
-
|
|
163
|
-
if (context?.embedded) {
|
|
164
|
-
const configs = new Map(entities.filter((e): e is ConfigIR => e.kind === "config").map((e) => [e.name, e.props]));
|
|
165
|
-
const services = doc?.services;
|
|
166
|
-
delegateEmbedded(configs, services && typeof services === "object" && !Array.isArray(services) ? (services as Record<string, unknown>) : undefined, context.embedded);
|
|
167
|
-
for (const e of entities) if (e.kind === "config") e.props = configs.get(e.name)!;
|
|
168
|
-
}
|
|
169
|
-
|
|
170
|
-
return { entities, warnings };
|
|
171
|
-
}
|
|
172
|
-
}
|
|
173
|
-
|
|
174
|
-
/** One logical Dockerfile instruction: its upper-case keyword and the rest as written. */
|
|
175
|
-
export interface DockerfileInstruction {
|
|
176
|
-
instruction: string;
|
|
177
|
-
value: string;
|
|
178
|
-
}
|
|
179
|
-
|
|
180
|
-
/**
|
|
181
|
-
* Split Dockerfile content into logical instructions, in order. Comment
|
|
182
|
-
* and blank lines are dropped (also inside a continued instruction, as
|
|
183
|
-
* Docker does). A line ending in a backslash continues onto the next line,
|
|
184
|
-
* and a heredoc (`RUN <<EOF` ... `EOF`) runs to its terminator; both are
|
|
185
|
-
* kept in the value exactly as written, so writing the value back gives
|
|
186
|
-
* the same instruction.
|
|
187
|
-
*/
|
|
188
|
-
export function splitDockerfileInstructions(content: string): DockerfileInstruction[] {
|
|
189
|
-
const out: DockerfileInstruction[] = [];
|
|
190
|
-
const lines = content.replace(/\r\n/g, "\n").split("\n");
|
|
191
|
-
let i = 0;
|
|
192
|
-
while (i < lines.length) {
|
|
193
|
-
const first = lines[i]!;
|
|
194
|
-
i++;
|
|
195
|
-
const trimmed = first.trim();
|
|
196
|
-
if (!trimmed || trimmed.startsWith("#")) continue;
|
|
197
|
-
|
|
198
|
-
const parts = [first.trimStart()];
|
|
199
|
-
let last = first;
|
|
200
|
-
while (/\\\s*$/.test(last) && i < lines.length) {
|
|
201
|
-
const next = lines[i]!;
|
|
202
|
-
i++;
|
|
203
|
-
// Docker skips comment and empty lines inside a continued instruction.
|
|
204
|
-
if (!next.trim() || next.trim().startsWith("#")) continue;
|
|
205
|
-
parts.push(next);
|
|
206
|
-
last = next;
|
|
207
|
-
}
|
|
208
|
-
|
|
209
|
-
// Heredocs: <<EOF, <<-EOF, <<"EOF", <<'EOF' (possibly several).
|
|
210
|
-
const joined = parts.join("\n");
|
|
211
|
-
const terminators = [...joined.matchAll(/<<(-?)(["']?)([A-Za-z_][A-Za-z0-9_]*)\2/g)].map((m) => ({ dash: m[1] === "-", word: m[3]! }));
|
|
212
|
-
for (const t of terminators) {
|
|
213
|
-
while (i < lines.length) {
|
|
214
|
-
const body = lines[i]!;
|
|
215
|
-
i++;
|
|
216
|
-
parts.push(body);
|
|
217
|
-
if ((t.dash ? body.replace(/^\t+/, "") : body) === t.word) break;
|
|
218
|
-
}
|
|
219
|
-
}
|
|
220
|
-
|
|
221
|
-
const text = parts.join("\n").trimEnd();
|
|
222
|
-
const match = text.match(/^([A-Za-z]+)(?:\s+([\s\S]*))?$/);
|
|
223
|
-
if (!match) continue;
|
|
224
|
-
out.push({ instruction: match[1]!.toUpperCase(), value: (match[2] ?? "").trimStart() });
|
|
225
|
-
}
|
|
226
|
-
return out;
|
|
227
|
-
}
|
|
228
|
-
|
|
229
|
-
/**
|
|
230
|
-
* Parser for Dockerfile content.
|
|
231
|
-
*/
|
|
232
|
-
export class DockerfileParser {
|
|
233
|
-
parse(name: string, content: string): DockerfileIR {
|
|
234
|
-
const stages: DockerfileStage[] = [];
|
|
235
|
-
const globalArgs: string[] = [];
|
|
236
|
-
let current: DockerfileStage | null = null;
|
|
237
|
-
|
|
238
|
-
for (const { instruction, value } of splitDockerfileInstructions(content)) {
|
|
239
|
-
if (instruction === "FROM") {
|
|
240
|
-
// Parse "FROM [--platform=...] image AS stagename"
|
|
241
|
-
const asMatch = value.match(/^(.+?)\s+[Aa][Ss]\s+(\S+)$/);
|
|
242
|
-
if (asMatch) {
|
|
243
|
-
current = { from: asMatch[1]!.trim(), as: asMatch[2]!.trim(), instructions: [] };
|
|
244
|
-
} else {
|
|
245
|
-
current = { from: value.trim(), instructions: [] };
|
|
246
|
-
}
|
|
247
|
-
stages.push(current);
|
|
248
|
-
} else if (current) {
|
|
249
|
-
current.instructions.push({ instruction, value });
|
|
250
|
-
} else if (instruction === "ARG") {
|
|
251
|
-
globalArgs.push(value);
|
|
252
|
-
}
|
|
253
|
-
}
|
|
254
|
-
|
|
255
|
-
return { kind: "dockerfile", name, ...(globalArgs.length > 0 ? { globalArgs } : {}), stages };
|
|
256
|
-
}
|
|
257
|
-
}
|
|
258
|
-
|
|
259
|
-
/** Whether content reads as a Dockerfile: its first instruction is FROM or ARG, or it starts with a parser directive. */
|
|
260
|
-
export function looksLikeDockerfile(content: string): boolean {
|
|
261
|
-
for (const line of content.split("\n")) {
|
|
262
|
-
const t = line.trim();
|
|
263
|
-
if (!t) continue;
|
|
264
|
-
if (/^#\s*(syntax|escape|check)\s*=/i.test(t)) return true;
|
|
265
|
-
if (t.startsWith("#")) continue;
|
|
266
|
-
return /^(FROM|ARG)\s/i.test(t);
|
|
267
|
-
}
|
|
268
|
-
return false;
|
|
269
|
-
}
|
|
@@ -1,257 +0,0 @@
|
|
|
1
|
-
import { describe, test, expect } from "vitest";
|
|
2
|
-
import { readFileSync } from "fs";
|
|
3
|
-
import { join } from "path";
|
|
4
|
-
import { DockerParser, DockerfileParser } from "./parser";
|
|
5
|
-
import { DockerGenerator } from "./generator";
|
|
6
|
-
import { DockerTemplateGenerator, DockerTemplateParser } from "./adapter";
|
|
7
|
-
import { Dockerfile } from "../generated/index";
|
|
8
|
-
import { dockerSerializer } from "../serializer";
|
|
9
|
-
import type { Declarable } from "@intentius/chant/declarable";
|
|
10
|
-
import { parseYAML } from "@intentius/chant/yaml";
|
|
11
|
-
import * as lexicon from "../index";
|
|
12
|
-
|
|
13
|
-
/**
|
|
14
|
-
* Dockerfile -> TypeScript -> Dockerfile. The generated source is run (its
|
|
15
|
-
* import line dropped, its exports collected) and the entity it declares is
|
|
16
|
-
* serialized again.
|
|
17
|
-
*/
|
|
18
|
-
function roundTrip(content: string, source?: string): { source: string; dockerfile: string } {
|
|
19
|
-
const src = source ?? new DockerGenerator().generate([new DockerfileParser().parse("app", content)]).source;
|
|
20
|
-
const body = src.replace(/^import .*$/m, "").replace(/export const (\w+) =/g, "out.$1 =");
|
|
21
|
-
const out: Record<string, Declarable> = {};
|
|
22
|
-
new Function("Dockerfile", "out", body)(Dockerfile, out);
|
|
23
|
-
const result = dockerSerializer.serialize(new Map(Object.entries(out))) as { files: Record<string, string> };
|
|
24
|
-
return { source: src, dockerfile: Object.values(result.files)[0]! };
|
|
25
|
-
}
|
|
26
|
-
|
|
27
|
-
const testdata = (file: string) =>
|
|
28
|
-
readFileSync(join(import.meta.dirname, "testdata", file), "utf8");
|
|
29
|
-
|
|
30
|
-
describe("roundtrip: parse → generate", () => {
|
|
31
|
-
test("simple.yaml → Service + Volume constructors", () => {
|
|
32
|
-
const { entities } = new DockerParser().parse(testdata("simple.yaml"));
|
|
33
|
-
const { source } = new DockerGenerator().generate(entities);
|
|
34
|
-
expect(source).toContain("new Service(");
|
|
35
|
-
expect(source).toContain("new Volume(");
|
|
36
|
-
expect(source).toContain("nginx:1.25");
|
|
37
|
-
});
|
|
38
|
-
|
|
39
|
-
test("webapp.yaml → ports / healthcheck / depends_on survive roundtrip", () => {
|
|
40
|
-
const { entities } = new DockerParser().parse(testdata("webapp.yaml"));
|
|
41
|
-
const { source } = new DockerGenerator().generate(entities);
|
|
42
|
-
expect(source).toContain("3000:3000");
|
|
43
|
-
expect(source).toContain("depends_on");
|
|
44
|
-
expect(source).toContain("healthcheck");
|
|
45
|
-
expect(source).toContain("unless-stopped");
|
|
46
|
-
});
|
|
47
|
-
|
|
48
|
-
test("full.yaml → Config / Secret / Network constructors present", () => {
|
|
49
|
-
const { entities } = new DockerParser().parse(testdata("full.yaml"));
|
|
50
|
-
const { source } = new DockerGenerator().generate(entities);
|
|
51
|
-
expect(source).toContain("new DockerConfig(");
|
|
52
|
-
expect(source).toContain("new DockerSecret(");
|
|
53
|
-
expect(source).toContain("new Network(");
|
|
54
|
-
});
|
|
55
|
-
|
|
56
|
-
test("multi-stage Dockerfile inline → stages: in output", () => {
|
|
57
|
-
const content = [
|
|
58
|
-
"FROM node:20-alpine AS builder",
|
|
59
|
-
"RUN npm ci",
|
|
60
|
-
"FROM nginx:1.25 AS runner",
|
|
61
|
-
"COPY --from=builder /app/dist /usr/share/nginx/html",
|
|
62
|
-
].join("\n");
|
|
63
|
-
const entity = new DockerfileParser().parse("app", content);
|
|
64
|
-
const { source } = new DockerGenerator().generate([entity]);
|
|
65
|
-
expect(source).toContain("stages");
|
|
66
|
-
expect(source).toContain("node:20-alpine");
|
|
67
|
-
expect(source).toContain("nginx:1.25");
|
|
68
|
-
});
|
|
69
|
-
|
|
70
|
-
});
|
|
71
|
-
|
|
72
|
-
describe("roundtrip: Dockerfile → TypeScript → Dockerfile keeps the instruction order", () => {
|
|
73
|
-
test("interleaved COPY and RUN", () => {
|
|
74
|
-
const content = [
|
|
75
|
-
"FROM node:20-alpine",
|
|
76
|
-
"WORKDIR /app",
|
|
77
|
-
"COPY package*.json ./",
|
|
78
|
-
"RUN npm ci",
|
|
79
|
-
"COPY . .",
|
|
80
|
-
"RUN npm run build",
|
|
81
|
-
'CMD ["node", "dist/index.js"]',
|
|
82
|
-
"",
|
|
83
|
-
].join("\n");
|
|
84
|
-
const { source, dockerfile } = roundTrip(content);
|
|
85
|
-
expect(source).toContain("steps: [");
|
|
86
|
-
expect(dockerfile).toBe(content);
|
|
87
|
-
});
|
|
88
|
-
|
|
89
|
-
test("USER after RUN stays after it", () => {
|
|
90
|
-
const content = [
|
|
91
|
-
"FROM debian:12-slim",
|
|
92
|
-
"RUN apt-get update && apt-get install -y --no-install-recommends curl",
|
|
93
|
-
"RUN useradd --system app",
|
|
94
|
-
"USER app",
|
|
95
|
-
"RUN whoami",
|
|
96
|
-
"",
|
|
97
|
-
].join("\n");
|
|
98
|
-
expect(roundTrip(content).dockerfile).toBe(content);
|
|
99
|
-
});
|
|
100
|
-
|
|
101
|
-
test("multi-stage, ARG before FROM, SHELL, STOPSIGNAL, ONBUILD and repeated WORKDIR", () => {
|
|
102
|
-
const content = [
|
|
103
|
-
"ARG NODE_VERSION=20",
|
|
104
|
-
"FROM node:${NODE_VERSION}-alpine AS build",
|
|
105
|
-
'SHELL ["/bin/sh", "-c"]',
|
|
106
|
-
"WORKDIR /src",
|
|
107
|
-
"COPY . .",
|
|
108
|
-
"WORKDIR /src/app",
|
|
109
|
-
"RUN npm run build",
|
|
110
|
-
"FROM nginx:1.27-alpine",
|
|
111
|
-
"COPY --from=build /src/app/dist /usr/share/nginx/html",
|
|
112
|
-
"ONBUILD COPY . /usr/share/nginx/html",
|
|
113
|
-
"STOPSIGNAL SIGQUIT",
|
|
114
|
-
"",
|
|
115
|
-
].join("\n");
|
|
116
|
-
const { source, dockerfile } = roundTrip(content);
|
|
117
|
-
expect(source).toContain('globalArgs: ["NODE_VERSION=20"]');
|
|
118
|
-
expect(dockerfile).toBe(content);
|
|
119
|
-
});
|
|
120
|
-
|
|
121
|
-
test("line continuations and heredocs are kept as written", () => {
|
|
122
|
-
const content = [
|
|
123
|
-
"# syntax=docker/dockerfile:1",
|
|
124
|
-
"FROM debian:12-slim",
|
|
125
|
-
"RUN apt-get update \\",
|
|
126
|
-
" # a comment Docker drops",
|
|
127
|
-
" && apt-get install -y --no-install-recommends curl",
|
|
128
|
-
"RUN <<EOF",
|
|
129
|
-
"set -e",
|
|
130
|
-
"echo hello > /hello",
|
|
131
|
-
"EOF",
|
|
132
|
-
"USER nobody",
|
|
133
|
-
"",
|
|
134
|
-
].join("\n");
|
|
135
|
-
const { dockerfile } = roundTrip(content);
|
|
136
|
-
expect(dockerfile).toBe([
|
|
137
|
-
"FROM debian:12-slim",
|
|
138
|
-
"RUN apt-get update \\",
|
|
139
|
-
" && apt-get install -y --no-install-recommends curl",
|
|
140
|
-
"RUN <<EOF",
|
|
141
|
-
"set -e",
|
|
142
|
-
"echo hello > /hello",
|
|
143
|
-
"EOF",
|
|
144
|
-
"USER nobody",
|
|
145
|
-
"",
|
|
146
|
-
].join("\n"));
|
|
147
|
-
});
|
|
148
|
-
|
|
149
|
-
test("chant import of a Dockerfile goes through the template adapter", () => {
|
|
150
|
-
const content = "FROM alpine:3.20\nCOPY run.sh /run.sh\nRUN chmod +x /run.sh\nUSER nobody\n";
|
|
151
|
-
const ir = new DockerTemplateParser().parse(content);
|
|
152
|
-
const [file] = new DockerTemplateGenerator().generate(ir);
|
|
153
|
-
expect(file!.content).toContain("export const app = new Dockerfile({");
|
|
154
|
-
expect(roundTrip(content, file!.content).dockerfile).toBe(content);
|
|
155
|
-
});
|
|
156
|
-
});
|
|
157
|
-
|
|
158
|
-
/** The names the generated source imports from the lexicon package. */
|
|
159
|
-
function importedNames(source: string): string[] {
|
|
160
|
-
const m = source.match(/^import \{ ([^}]+) \} from "@intentius\/chant-lexicon-docker";$/m);
|
|
161
|
-
return m ? m[1]!.split(",").map((n) => n.trim()) : [];
|
|
162
|
-
}
|
|
163
|
-
|
|
164
|
-
/**
|
|
165
|
-
* Run imported source against the lexicon package and serialize what it
|
|
166
|
-
* exports. Each name on its import line is bound from the package's real
|
|
167
|
-
* exports, so a name the package lacks fails here (#3933).
|
|
168
|
-
*/
|
|
169
|
-
function buildImport(source: string): string {
|
|
170
|
-
const names = importedNames(source);
|
|
171
|
-
const body = source.replace(/^import .*$/m, "").replace(/export const (\w+) =/g, "out.$1 =");
|
|
172
|
-
const out: Record<string, Declarable> = {};
|
|
173
|
-
const exports = lexicon as Record<string, unknown>;
|
|
174
|
-
new Function(...names, "out", body)(...names.map((n) => exports[n]), out);
|
|
175
|
-
const result = dockerSerializer.serialize(new Map(Object.entries(out)));
|
|
176
|
-
return typeof result === "string" ? result : result.primary ?? "";
|
|
177
|
-
}
|
|
178
|
-
|
|
179
|
-
describe("roundtrip: compose → TypeScript → compose", () => {
|
|
180
|
-
test("configs and secrets import as DockerConfig and DockerSecret and build the same file", () => {
|
|
181
|
-
const content = testdata("configs-secrets.yaml");
|
|
182
|
-
const { entities } = new DockerParser().parse(content);
|
|
183
|
-
const { source } = new DockerGenerator().generate(entities);
|
|
184
|
-
expect(importedNames(source)).toEqual(["DockerConfig", "DockerSecret", "Service"]);
|
|
185
|
-
expect(source).toContain("new DockerConfig(");
|
|
186
|
-
expect(source).toContain("new DockerSecret(");
|
|
187
|
-
expect(parseYAML(buildImport(source))).toEqual(parseYAML(content));
|
|
188
|
-
});
|
|
189
|
-
|
|
190
|
-
test("full.yaml builds the same file: every field kept, hyphenated keys kept (#3937)", () => {
|
|
191
|
-
const content = testdata("full.yaml");
|
|
192
|
-
const { entities, warnings } = new DockerParser().parse(content);
|
|
193
|
-
expect(warnings).toEqual([]);
|
|
194
|
-
const { source } = new DockerGenerator().generate(entities);
|
|
195
|
-
expect(parseYAML(buildImport(source))).toEqual(parseYAML(content));
|
|
196
|
-
});
|
|
197
|
-
|
|
198
|
-
test("fields outside the old fixed list, x- extensions, and keys that are not identifiers survive (#3937)", () => {
|
|
199
|
-
const content = testdata("names-and-fields.yaml");
|
|
200
|
-
const { entities, warnings } = new DockerParser().parse(content);
|
|
201
|
-
expect(warnings).toEqual([]);
|
|
202
|
-
const { source } = new DockerGenerator().generate(entities);
|
|
203
|
-
expect(parseYAML(buildImport(source))).toEqual(parseYAML(content));
|
|
204
|
-
});
|
|
205
|
-
|
|
206
|
-
test("through the chant import adapter", () => {
|
|
207
|
-
const content = testdata("names-and-fields.yaml");
|
|
208
|
-
const [file] = new DockerTemplateGenerator().generate(new DockerTemplateParser().parse(content));
|
|
209
|
-
expect(parseYAML(buildImport(file!.content))).toEqual(parseYAML(content));
|
|
210
|
-
});
|
|
211
|
-
});
|
|
212
|
-
|
|
213
|
-
describe("compose import warns on what it cannot keep (#3937)", () => {
|
|
214
|
-
test("a field the Compose spec does not define is dropped with a warning", () => {
|
|
215
|
-
const content = "services:\n api:\n image: nginx\n not_a_field: 1\nnetworks:\n n:\n bogus: true\n";
|
|
216
|
-
const { entities, warnings } = new DockerParser().parse(content);
|
|
217
|
-
expect(entities.find((e) => e.name === "api")).toMatchObject({ props: { image: "nginx" } });
|
|
218
|
-
expect(warnings).toEqual([
|
|
219
|
-
'services.api: "not_a_field" is not a Compose service field and was dropped',
|
|
220
|
-
'networks.n: "bogus" is not a Compose network field and was dropped',
|
|
221
|
-
]);
|
|
222
|
-
});
|
|
223
|
-
|
|
224
|
-
test("a top-level section import does not carry is named", () => {
|
|
225
|
-
const { warnings } = new DockerParser().parse("name: proj\nservices:\n a:\n image: x\n");
|
|
226
|
-
expect(warnings).toEqual(['"name" at the top level is not imported']);
|
|
227
|
-
});
|
|
228
|
-
|
|
229
|
-
test("the adapter hands parser warnings to chant import", () => {
|
|
230
|
-
const ir = new DockerTemplateParser().parse("services:\n api:\n image: nginx\n not_a_field: 1\n");
|
|
231
|
-
expect(ir.warnings).toEqual(['services.api: "not_a_field" is not a Compose service field and was dropped']);
|
|
232
|
-
});
|
|
233
|
-
});
|
|
234
|
-
|
|
235
|
-
describe("every name the importers emit is exported by the lexicon", () => {
|
|
236
|
-
test("compose and Dockerfile imports name only exported constructors", () => {
|
|
237
|
-
const entities = [
|
|
238
|
-
...new DockerParser().parse(testdata("full.yaml")).entities,
|
|
239
|
-
new DockerfileParser().parse("app", "FROM alpine:3.20\nRUN true\n"),
|
|
240
|
-
];
|
|
241
|
-
expect(new Set(entities.map((e) => e.kind))).toEqual(new Set(["service", "volume", "network", "config", "secret", "dockerfile"]));
|
|
242
|
-
const names = importedNames(new DockerGenerator().generate(entities).source);
|
|
243
|
-
// The six constructors, and composeKey for full.yaml's hyphenated keys.
|
|
244
|
-
expect(names.length).toBe(7);
|
|
245
|
-
for (const name of names) {
|
|
246
|
-
expect(typeof (lexicon as Record<string, unknown>)[name], name).toBe("function");
|
|
247
|
-
}
|
|
248
|
-
// Through the `chant import` adapter too.
|
|
249
|
-
for (const content of [testdata("full.yaml"), "FROM alpine:3.20\nRUN true\n"]) {
|
|
250
|
-
for (const file of new DockerTemplateGenerator().generate(new DockerTemplateParser().parse(content))) {
|
|
251
|
-
for (const name of importedNames(file.content)) {
|
|
252
|
-
expect(typeof (lexicon as Record<string, unknown>)[name], `${file.path}: ${name}`).toBe("function");
|
|
253
|
-
}
|
|
254
|
-
}
|
|
255
|
-
}
|
|
256
|
-
});
|
|
257
|
-
});
|
|
@@ -1,43 +0,0 @@
|
|
|
1
|
-
services:
|
|
2
|
-
app:
|
|
3
|
-
image: myapp:latest
|
|
4
|
-
ports:
|
|
5
|
-
- "8080:8080"
|
|
6
|
-
environment:
|
|
7
|
-
DB_URL: postgres://db:5432/mydb
|
|
8
|
-
networks:
|
|
9
|
-
- frontend
|
|
10
|
-
- backend
|
|
11
|
-
secrets:
|
|
12
|
-
- db-password
|
|
13
|
-
configs:
|
|
14
|
-
- app-config
|
|
15
|
-
|
|
16
|
-
db:
|
|
17
|
-
image: postgres:16
|
|
18
|
-
networks:
|
|
19
|
-
- backend
|
|
20
|
-
|
|
21
|
-
volumes:
|
|
22
|
-
db-data:
|
|
23
|
-
driver: local
|
|
24
|
-
app-uploads:
|
|
25
|
-
driver: local
|
|
26
|
-
driver_opts:
|
|
27
|
-
type: nfs
|
|
28
|
-
o: addr=10.0.0.1,rw
|
|
29
|
-
|
|
30
|
-
networks:
|
|
31
|
-
frontend:
|
|
32
|
-
driver: bridge
|
|
33
|
-
backend:
|
|
34
|
-
driver: bridge
|
|
35
|
-
internal: true
|
|
36
|
-
|
|
37
|
-
configs:
|
|
38
|
-
app-config:
|
|
39
|
-
file: ./config/app.conf
|
|
40
|
-
|
|
41
|
-
secrets:
|
|
42
|
-
db-password:
|
|
43
|
-
file: ./secrets/db-password.txt
|
|
@@ -1,44 +0,0 @@
|
|
|
1
|
-
services:
|
|
2
|
-
web-app:
|
|
3
|
-
image: myapp:latest
|
|
4
|
-
working_dir: /srv
|
|
5
|
-
user: "1000:1000"
|
|
6
|
-
env_file:
|
|
7
|
-
- .env
|
|
8
|
-
stop_grace_period: 30s
|
|
9
|
-
x-team: platform
|
|
10
|
-
depends_on:
|
|
11
|
-
- db_primary
|
|
12
|
-
volumes:
|
|
13
|
-
- "app-data:/data"
|
|
14
|
-
networks:
|
|
15
|
-
- back-tier
|
|
16
|
-
secrets:
|
|
17
|
-
- db-password
|
|
18
|
-
configs:
|
|
19
|
-
- nginx.conf
|
|
20
|
-
db_primary:
|
|
21
|
-
image: postgres:16
|
|
22
|
-
db:
|
|
23
|
-
image: postgres:16
|
|
24
|
-
volumes:
|
|
25
|
-
- "db:/var/lib/postgresql/data"
|
|
26
|
-
volumes:
|
|
27
|
-
app-data:
|
|
28
|
-
name: shared-app-data
|
|
29
|
-
db:
|
|
30
|
-
networks:
|
|
31
|
-
back-tier:
|
|
32
|
-
internal: true
|
|
33
|
-
driver_opts:
|
|
34
|
-
com.docker.network.bridge.name: br-back
|
|
35
|
-
configs:
|
|
36
|
-
nginx.conf:
|
|
37
|
-
content: |
|
|
38
|
-
server {}
|
|
39
|
-
name: nginx-conf
|
|
40
|
-
labels:
|
|
41
|
-
tier: edge
|
|
42
|
-
secrets:
|
|
43
|
-
db-password:
|
|
44
|
-
environment: DB_PASSWORD
|
|
@@ -1,24 +0,0 @@
|
|
|
1
|
-
/** A ustar archive of regular files and directories, as `GET /containers/{id}/archive` returns one (test fixture). */
|
|
2
|
-
export function tarOf(...entries: Array<[name: string, content: string | null]>): Buffer {
|
|
3
|
-
const blocks: Buffer[] = [];
|
|
4
|
-
for (const [name, content] of entries) {
|
|
5
|
-
const data = content === null ? Buffer.alloc(0) : Buffer.from(content, "utf8");
|
|
6
|
-
const header = Buffer.alloc(512);
|
|
7
|
-
header.write(name, 0, 100, "utf8");
|
|
8
|
-
header.write("0000644\0", 100, 8, "ascii");
|
|
9
|
-
header.write("0000000\0", 108, 8, "ascii");
|
|
10
|
-
header.write("0000000\0", 116, 8, "ascii");
|
|
11
|
-
header.write(`${data.length.toString(8).padStart(11, "0")}\0`, 124, 12, "ascii");
|
|
12
|
-
header.write("00000000000\0", 136, 12, "ascii");
|
|
13
|
-
header.write(content === null ? "5" : "0", 156, 1, "ascii");
|
|
14
|
-
header.write("ustar\0", 257, 6, "ascii");
|
|
15
|
-
header.write("00", 263, 2, "ascii");
|
|
16
|
-
header.fill(" ", 148, 156);
|
|
17
|
-
let sum = 0;
|
|
18
|
-
for (const b of header) sum += b;
|
|
19
|
-
header.write(`${sum.toString(8).padStart(6, "0")}\0 `, 148, 8, "ascii");
|
|
20
|
-
blocks.push(header, data, Buffer.alloc((512 - (data.length % 512)) % 512));
|
|
21
|
-
}
|
|
22
|
-
blocks.push(Buffer.alloc(1024));
|
|
23
|
-
return Buffer.concat(blocks);
|
|
24
|
-
}
|