auryn-docker 0.8.2__py3-none-any.whl
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.
- auryn/ingestors/docker/__init__.py +0 -0
- auryn/ingestors/docker/build.py +128 -0
- auryn/ingestors/docker/enrichment.py +14 -0
- auryn/ingestors/docker/file_parser.py +162 -0
- auryn/ingestors/docker/git_sync.py +108 -0
- auryn/ingestors/docker/ids.py +34 -0
- auryn/ingestors/docker/image_ref.py +22 -0
- auryn/ingestors/docker/model.py +42 -0
- auryn/ingestors/docker/plugin.py +38 -0
- auryn/ingestors/docker/schema.py +36 -0
- auryn/ingestors/docker/stitch.py +187 -0
- auryn_docker-0.8.2.dist-info/METADATA +27 -0
- auryn_docker-0.8.2.dist-info/RECORD +16 -0
- auryn_docker-0.8.2.dist-info/WHEEL +4 -0
- auryn_docker-0.8.2.dist-info/entry_points.txt +5 -0
- auryn_docker-0.8.2.dist-info/licenses/LICENSE +21 -0
|
File without changes
|
|
@@ -0,0 +1,128 @@
|
|
|
1
|
+
"""Turn parsed Dockerfiles into the deployment-tier graph (ADR 0007): File -> BuildStage, each stage
|
|
2
|
+
BASED_ON its base Image (or an earlier stage) and COPIES_FROM earlier stages. Emits the shared
|
|
3
|
+
`Image` hub nodes for every base reference as `resolved:false` placeholders -- the `deploy` stitch
|
|
4
|
+
later recomputes `resolved` (an image is resolved once something BUILDS_IMAGE it) and GCs orphans.
|
|
5
|
+
|
|
6
|
+
Does NOT emit the Project node (git_sync owns it, like the other ingestors) nor any cross-artifact
|
|
7
|
+
edge (`BUILDS_IMAGE`/`PACKAGES`/`SHIPS` are the stitch's -- the producer never reaches outside its
|
|
8
|
+
own files; ADR 0007 §7)."""
|
|
9
|
+
|
|
10
|
+
from __future__ import annotations
|
|
11
|
+
|
|
12
|
+
import posixpath
|
|
13
|
+
import re
|
|
14
|
+
from collections.abc import Iterator
|
|
15
|
+
|
|
16
|
+
from auryn.core.graph_model import GraphEdge, GraphNode
|
|
17
|
+
from auryn.ingestors.docker import ids
|
|
18
|
+
from auryn.ingestors.docker.image_ref import SCRATCH, image_id, parse_image_ref
|
|
19
|
+
from auryn.ingestors.docker.model import ParsedDockerfile, Stage
|
|
20
|
+
|
|
21
|
+
# A whole `${...}` brace expression OR a bare `$NAME`. The brace form is matched as ONE unit so a
|
|
22
|
+
# modifier expression (`${BASE:-$FALLBACK}`, `${NAME-x}`, `${NAME+x}`, `${NAME?x}`) is consumed whole
|
|
23
|
+
# and left verbatim -- never partially substituted via its inner `$FALLBACK`.
|
|
24
|
+
_VAR = re.compile(r"\$\{[^}]*\}|\$[A-Za-z_][A-Za-z0-9_]*")
|
|
25
|
+
_PLAIN_NAME = re.compile(r"[A-Za-z_][A-Za-z0-9_]*")
|
|
26
|
+
|
|
27
|
+
|
|
28
|
+
def _resolve_base(base: str, args: dict[str, str]) -> str:
|
|
29
|
+
"""Best-effort `${ARG}`/`$ARG` substitution from the file's global ARGs so `FROM ${BASE}:${TAG}`
|
|
30
|
+
normalizes when those ARGs have NON-EMPTY defaults. A missing ARG, an empty-valued ARG (`ARG BASE`
|
|
31
|
+
with no default), or a modifier form (`${BASE:-default}`) is left as the raw `${...}`/`$NAME` text
|
|
32
|
+
-- so the base stays flagged `unresolved` (keeping a real Image placeholder) instead of collapsing
|
|
33
|
+
to an empty/garbage ref or being half-substituted."""
|
|
34
|
+
if "$" not in base:
|
|
35
|
+
return base
|
|
36
|
+
|
|
37
|
+
def _sub(m: re.Match) -> str:
|
|
38
|
+
tok = m.group(0)
|
|
39
|
+
if tok.startswith("${"):
|
|
40
|
+
inner = tok[2:-1]
|
|
41
|
+
if not _PLAIN_NAME.fullmatch(inner):
|
|
42
|
+
return tok # a modifier/default form -> leave the WHOLE `${...}` verbatim
|
|
43
|
+
name = inner
|
|
44
|
+
else:
|
|
45
|
+
name = tok[1:]
|
|
46
|
+
val = args.get(name)
|
|
47
|
+
return val if val else tok # missing or empty -> keep the raw text
|
|
48
|
+
|
|
49
|
+
return _VAR.sub(_sub, base)
|
|
50
|
+
|
|
51
|
+
|
|
52
|
+
def _stage_key(stage: Stage) -> str:
|
|
53
|
+
return stage.name if stage.name else str(stage.index)
|
|
54
|
+
|
|
55
|
+
|
|
56
|
+
def build_graph(files: list[tuple[str, ParsedDockerfile]], proj_id: str) -> Iterator[GraphNode | GraphEdge]:
|
|
57
|
+
for rel_path, parsed in files:
|
|
58
|
+
fid = ids.file_id(proj_id, rel_path)
|
|
59
|
+
yield GraphNode("File", {"id": fid}, {"path": rel_path, "name": posixpath.basename(rel_path)})
|
|
60
|
+
yield GraphEdge("HAS_FILE", "Project", {"id": proj_id}, "File", {"id": fid})
|
|
61
|
+
|
|
62
|
+
# Resolve intra-file stage references (base + `COPY --from`) by name AND by index.
|
|
63
|
+
stage_ids = {_stage_key(s): ids.stage_id(fid, _stage_key(s)) for s in parsed.stages}
|
|
64
|
+
for s in parsed.stages:
|
|
65
|
+
stage_ids.setdefault(str(s.index), ids.stage_id(fid, _stage_key(s)))
|
|
66
|
+
|
|
67
|
+
for stage in parsed.stages:
|
|
68
|
+
yield from _emit_stage(stage, parsed, fid, stage_ids)
|
|
69
|
+
|
|
70
|
+
|
|
71
|
+
def _emit_stage(stage: Stage, parsed: ParsedDockerfile, fid: str, stage_ids: dict[str, str]) -> Iterator[GraphNode | GraphEdge]:
|
|
72
|
+
sid = ids.stage_id(fid, _stage_key(stage))
|
|
73
|
+
# Host-context COPY sources (those WITHOUT --from) drive the code seam -- stored for the stitch.
|
|
74
|
+
copy_sources = [src for c in stage.copies if c.from_stage is None for src in c.sources]
|
|
75
|
+
yield GraphNode(
|
|
76
|
+
"BuildStage",
|
|
77
|
+
{"id": sid},
|
|
78
|
+
{
|
|
79
|
+
"name": stage.name or "",
|
|
80
|
+
"stage": _stage_key(stage),
|
|
81
|
+
"index": stage.index,
|
|
82
|
+
"base_ref": stage.base,
|
|
83
|
+
"dockerfile": posixpath.basename(fid.split("/file/", 1)[-1]) if "/file/" in fid else fid,
|
|
84
|
+
"context": posixpath.dirname(fid.split("/file/", 1)[-1]) if "/file/" in fid else "",
|
|
85
|
+
"copy_sources": copy_sources,
|
|
86
|
+
"exposed_ports": list(stage.exposed_ports),
|
|
87
|
+
"entrypoint": stage.entrypoint,
|
|
88
|
+
"cmd": stage.cmd,
|
|
89
|
+
"workdir": stage.workdir,
|
|
90
|
+
},
|
|
91
|
+
)
|
|
92
|
+
yield GraphEdge("HAS_STAGE", "File", {"id": fid}, "BuildStage", {"id": sid})
|
|
93
|
+
|
|
94
|
+
# BASED_ON: an earlier stage in this file, or an external base Image (`scratch` has neither).
|
|
95
|
+
base = _resolve_base(stage.base, parsed.args)
|
|
96
|
+
if base in stage_ids and stage_ids[base] != sid:
|
|
97
|
+
yield GraphEdge("BASED_ON", "BuildStage", {"id": sid}, "BuildStage", {"id": stage_ids[base]},
|
|
98
|
+
{"resolution": "declared"})
|
|
99
|
+
elif base and base != SCRATCH:
|
|
100
|
+
yield from _emit_base_image(base)
|
|
101
|
+
yield GraphEdge("BASED_ON", "BuildStage", {"id": sid}, "Image", {"id": image_id(base)},
|
|
102
|
+
{"resolution": "declared"})
|
|
103
|
+
|
|
104
|
+
# COPIES_FROM: multi-stage `COPY --from=<earlier stage>` (intra-file only in v1).
|
|
105
|
+
for c in stage.copies:
|
|
106
|
+
if c.from_stage and c.from_stage in stage_ids and stage_ids[c.from_stage] != sid:
|
|
107
|
+
yield GraphEdge("COPIES_FROM", "BuildStage", {"id": sid}, "BuildStage", {"id": stage_ids[c.from_stage]})
|
|
108
|
+
|
|
109
|
+
|
|
110
|
+
def _emit_base_image(ref: str) -> Iterator[GraphNode]:
|
|
111
|
+
"""A base `Image` as a shared, project-independent node (`image://<normalized>`), emitted
|
|
112
|
+
`resolved:false` -- the stitch flips it true iff something BUILDS_IMAGE it. MERGE-dedup means the
|
|
113
|
+
same base used by many Dockerfiles across repos is ONE node (the shared-base signal)."""
|
|
114
|
+
r = parse_image_ref(ref)
|
|
115
|
+
yield GraphNode(
|
|
116
|
+
"Image",
|
|
117
|
+
{"id": image_id(ref)},
|
|
118
|
+
{
|
|
119
|
+
"ref": r.normalized,
|
|
120
|
+
"registry": r.registry,
|
|
121
|
+
"repository": r.repository,
|
|
122
|
+
"tag": r.tag,
|
|
123
|
+
"digest": r.digest,
|
|
124
|
+
"resolved": False,
|
|
125
|
+
"origin": "registry", # an external pull until a BUILDS_IMAGE proves it internal
|
|
126
|
+
**({"raw": r.raw} if r.unresolved else {}),
|
|
127
|
+
},
|
|
128
|
+
)
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
"""The `deploy` stitch registration -- the `auryn.enrichments` entry-point target (ADR 0007 §7).
|
|
2
|
+
|
|
3
|
+
Kept separate from plugin.py (the GitLanguage) so the two roles register independently, and
|
|
4
|
+
import-light: `stitch` pulls in only core graph helpers (no parser), so enrichment discovery never
|
|
5
|
+
imports the Dockerfile engine."""
|
|
6
|
+
|
|
7
|
+
from __future__ import annotations
|
|
8
|
+
|
|
9
|
+
from auryn.core.registry import GraphEnrichment, register_graph_enrichment
|
|
10
|
+
from auryn.ingestors.docker.stitch import run as _run
|
|
11
|
+
|
|
12
|
+
register_graph_enrichment(GraphEnrichment(name="deploy", run=_run))
|
|
13
|
+
|
|
14
|
+
__all__ = ["_run"]
|
|
@@ -0,0 +1,162 @@
|
|
|
1
|
+
"""Hand-rolled Dockerfile parser -> `ParsedDockerfile` (no native dependency).
|
|
2
|
+
|
|
3
|
+
Dockerfile syntax is small enough that a line tokenizer is faithful and keeps the plugin
|
|
4
|
+
dependency-free and its tests hermetic; the two genuinely fiddly bits -- line continuations (`\\`)
|
|
5
|
+
and whole-line comments -- are handled explicitly below. ADR 0007 §7 notes a `tree-sitter-dockerfile`
|
|
6
|
+
engine can replace this behind the same `parse_source` seam (for heredocs / parser directives /
|
|
7
|
+
alternate `escape`) without any change to `build.py`.
|
|
8
|
+
|
|
9
|
+
Scope (v1): the instructions the deployment graph needs -- FROM (+ `AS`, multi-stage bases),
|
|
10
|
+
COPY/ADD (+ `--from`), EXPOSE, ENTRYPOINT, CMD, WORKDIR, and pre-FROM ARG. Other instructions (RUN,
|
|
11
|
+
ENV, LABEL, USER, ...) are recognized and skipped; ENV->ConfigValue is a later arm (ADR 0007)."""
|
|
12
|
+
|
|
13
|
+
from __future__ import annotations
|
|
14
|
+
|
|
15
|
+
import json
|
|
16
|
+
import re
|
|
17
|
+
|
|
18
|
+
from auryn.ingestors.docker.model import Copy, ParsedDockerfile, Stage
|
|
19
|
+
|
|
20
|
+
_CONTINUATION = "\\"
|
|
21
|
+
_LEADING_FLAGS = re.compile(r"(?:--\S+\s+)*") # `--from=x --chown=y ` before the operands
|
|
22
|
+
|
|
23
|
+
|
|
24
|
+
def _logical_lines(text: str) -> list[str]:
|
|
25
|
+
"""Collapse the physical lines into logical instructions: drop whole-line comments and blank
|
|
26
|
+
lines, then join any line ending in a backslash with the next (Dockerfile line continuation)."""
|
|
27
|
+
out: list[str] = []
|
|
28
|
+
buf = ""
|
|
29
|
+
for raw in text.splitlines():
|
|
30
|
+
stripped = raw.strip()
|
|
31
|
+
if not stripped or stripped.startswith("#"):
|
|
32
|
+
continue # blank line or whole-line comment / parser directive -- dropped even mid-continuation
|
|
33
|
+
line = raw.rstrip()
|
|
34
|
+
if line.endswith(_CONTINUATION):
|
|
35
|
+
buf += line[: -len(_CONTINUATION)] + " "
|
|
36
|
+
continue
|
|
37
|
+
out.append((buf + line).strip())
|
|
38
|
+
buf = ""
|
|
39
|
+
if buf.strip():
|
|
40
|
+
out.append(buf.strip())
|
|
41
|
+
return out
|
|
42
|
+
|
|
43
|
+
|
|
44
|
+
def _split_instruction(line: str) -> tuple[str, str]:
|
|
45
|
+
"""`COPY --from=build /a /b` -> ("COPY", "--from=build /a /b"). Instruction keyword is
|
|
46
|
+
case-insensitive; splits on the first whitespace RUN so a tab after the keyword (`FROM\\talpine`)
|
|
47
|
+
is accepted, not silently dropped."""
|
|
48
|
+
parts = line.split(None, 1)
|
|
49
|
+
return parts[0].upper(), (parts[1].strip() if len(parts) > 1 else "")
|
|
50
|
+
|
|
51
|
+
|
|
52
|
+
def _tokens(rest: str) -> list[str]:
|
|
53
|
+
return rest.split()
|
|
54
|
+
|
|
55
|
+
|
|
56
|
+
def _parse_from(rest: str) -> tuple[str, str | None]:
|
|
57
|
+
"""`[--platform=...] <image|stage> [AS <name>]` -> (base, stage_name)."""
|
|
58
|
+
toks = [t for t in _tokens(rest) if not t.startswith("--")]
|
|
59
|
+
if not toks:
|
|
60
|
+
return "", None
|
|
61
|
+
base = toks[0]
|
|
62
|
+
name = None
|
|
63
|
+
for i, t in enumerate(toks):
|
|
64
|
+
if t.lower() == "as" and i + 1 < len(toks):
|
|
65
|
+
name = toks[i + 1]
|
|
66
|
+
break
|
|
67
|
+
return base, name
|
|
68
|
+
|
|
69
|
+
|
|
70
|
+
def _parse_copy(rest: str) -> Copy | None:
|
|
71
|
+
"""`[--from=X] [--chown=...] src... dest`. Leading `--` flags are peeled off the ORIGINAL string
|
|
72
|
+
first (so both forms accept them), then the remainder is parsed as either the JSON exec form
|
|
73
|
+
(`["src", "dest"]` — decoded from the untouched substring so whitespace inside a path survives) or
|
|
74
|
+
the shell form (whitespace-separated). A `[`-prefixed operand that is NOT valid JSON (a shell-form
|
|
75
|
+
`[ab].py` char-class glob) falls through to shell parsing rather than dropping the copy."""
|
|
76
|
+
flags = _LEADING_FLAGS.match(rest)
|
|
77
|
+
operands_str = rest[flags.end():].strip()
|
|
78
|
+
from_stage = None
|
|
79
|
+
for f in flags.group(0).split():
|
|
80
|
+
if f.startswith("--from="):
|
|
81
|
+
from_stage = f.split("=", 1)[1]
|
|
82
|
+
if not operands_str:
|
|
83
|
+
return None
|
|
84
|
+
|
|
85
|
+
if operands_str.startswith("["):
|
|
86
|
+
try:
|
|
87
|
+
arr = json.loads(operands_str)
|
|
88
|
+
except ValueError:
|
|
89
|
+
arr = None # not JSON (e.g. a `[ab]` char class) -> fall through to shell parsing
|
|
90
|
+
if isinstance(arr, list) and len(arr) >= 2:
|
|
91
|
+
return Copy(sources=tuple(str(x) for x in arr[:-1]), dest=str(arr[-1]), from_stage=from_stage)
|
|
92
|
+
if arr is not None:
|
|
93
|
+
return None # valid JSON but not a 2+ element array -> malformed, not a copy
|
|
94
|
+
|
|
95
|
+
paths = operands_str.split()
|
|
96
|
+
if len(paths) < 2:
|
|
97
|
+
return None
|
|
98
|
+
return Copy(sources=tuple(paths[:-1]), dest=paths[-1], from_stage=from_stage)
|
|
99
|
+
|
|
100
|
+
|
|
101
|
+
def parse_source(data: str | bytes) -> ParsedDockerfile:
|
|
102
|
+
if isinstance(data, bytes):
|
|
103
|
+
data = data.decode("utf-8", errors="replace")
|
|
104
|
+
|
|
105
|
+
args: dict[str, str] = {}
|
|
106
|
+
stages: list[Stage] = []
|
|
107
|
+
|
|
108
|
+
# Mutable accumulators for the stage currently being built (flushed on the next FROM / at EOF).
|
|
109
|
+
cur: dict | None = None
|
|
110
|
+
|
|
111
|
+
def flush() -> None:
|
|
112
|
+
if cur is None:
|
|
113
|
+
return
|
|
114
|
+
stages.append(
|
|
115
|
+
Stage(
|
|
116
|
+
index=cur["index"],
|
|
117
|
+
base=cur["base"],
|
|
118
|
+
name=cur["name"],
|
|
119
|
+
copies=tuple(cur["copies"]),
|
|
120
|
+
exposed_ports=tuple(cur["ports"]),
|
|
121
|
+
entrypoint=cur["entrypoint"],
|
|
122
|
+
cmd=cur["cmd"],
|
|
123
|
+
workdir=cur["workdir"],
|
|
124
|
+
)
|
|
125
|
+
)
|
|
126
|
+
|
|
127
|
+
for line in _logical_lines(data):
|
|
128
|
+
instr, rest = _split_instruction(line)
|
|
129
|
+
if instr == "FROM":
|
|
130
|
+
flush()
|
|
131
|
+
base, name = _parse_from(rest)
|
|
132
|
+
cur = {
|
|
133
|
+
"index": len(stages),
|
|
134
|
+
"base": base,
|
|
135
|
+
"name": name,
|
|
136
|
+
"copies": [],
|
|
137
|
+
"ports": [],
|
|
138
|
+
"entrypoint": None,
|
|
139
|
+
"cmd": None,
|
|
140
|
+
"workdir": None,
|
|
141
|
+
}
|
|
142
|
+
elif cur is None:
|
|
143
|
+
# Pre-FROM preamble: only global ARGs matter (they can parameterize a `FROM ${ARG}`).
|
|
144
|
+
if instr == "ARG" and rest:
|
|
145
|
+
k, _, v = rest.partition("=")
|
|
146
|
+
args[k.strip()] = v.strip()
|
|
147
|
+
elif instr in ("COPY", "ADD"):
|
|
148
|
+
c = _parse_copy(rest)
|
|
149
|
+
if c is not None:
|
|
150
|
+
cur["copies"].append(c)
|
|
151
|
+
elif instr == "EXPOSE":
|
|
152
|
+
cur["ports"].extend(_tokens(rest))
|
|
153
|
+
elif instr == "ENTRYPOINT":
|
|
154
|
+
cur["entrypoint"] = rest
|
|
155
|
+
elif instr == "CMD":
|
|
156
|
+
cur["cmd"] = rest
|
|
157
|
+
elif instr == "WORKDIR":
|
|
158
|
+
cur["workdir"] = rest.strip()
|
|
159
|
+
# every other instruction (RUN, ENV, LABEL, USER, ...) is intentionally ignored in v1
|
|
160
|
+
|
|
161
|
+
flush()
|
|
162
|
+
return ParsedDockerfile(stages=tuple(stages), args=args)
|
|
@@ -0,0 +1,108 @@
|
|
|
1
|
+
"""Git-tracked (and directory) Dockerfile ingestion: fully recompute the project's Docker subgraph
|
|
2
|
+
at `target_sha` and diff it onto the graph (graph_sync.stream_apply) -- the same recompute-and-delta
|
|
3
|
+
model every file-based ingestor uses. v1 is full-recompute only (Dockerfiles are few and tiny, so
|
|
4
|
+
parsing is cheap and parallelism/incremental routing is unnecessary); an incremental path like the
|
|
5
|
+
shared `route_incremental` engine would slot in here exactly as the language ingestors do.
|
|
6
|
+
|
|
7
|
+
Registered as the `docker` GitLanguage by the import-light plugin.py, so this module (the parser) is
|
|
8
|
+
imported only when a source actually contains Dockerfiles."""
|
|
9
|
+
|
|
10
|
+
from __future__ import annotations
|
|
11
|
+
|
|
12
|
+
import itertools
|
|
13
|
+
import logging
|
|
14
|
+
import time
|
|
15
|
+
from dataclasses import dataclass
|
|
16
|
+
|
|
17
|
+
from auryn.core.graph_model import GraphNode
|
|
18
|
+
from auryn.core.graph_sync import stream_apply
|
|
19
|
+
from auryn.core.registry import LanguageIngestResult
|
|
20
|
+
from auryn.ingestors.docker.build import build_graph
|
|
21
|
+
from auryn.ingestors.docker.file_parser import parse_source
|
|
22
|
+
from auryn.ingestors.docker.ids import project_id
|
|
23
|
+
from auryn.ingestors.docker.plugin import EXCLUDED_DIR_NAMES as _EXCLUDED_DIR_NAMES
|
|
24
|
+
from auryn.ingestors.docker.plugin import FILE_SUFFIXES as _FILE_SUFFIXES
|
|
25
|
+
from auryn.ingestors.docker.schema import NODE_SCHEMAS, OWNED_LABELS
|
|
26
|
+
|
|
27
|
+
logger = logging.getLogger(__name__)
|
|
28
|
+
|
|
29
|
+
|
|
30
|
+
@dataclass
|
|
31
|
+
class SyncStats:
|
|
32
|
+
nodes_added: int = 0
|
|
33
|
+
nodes_updated: int = 0
|
|
34
|
+
nodes_removed: int = 0
|
|
35
|
+
edges_added: int = 0
|
|
36
|
+
edges_updated: int = 0
|
|
37
|
+
edges_removed: int = 0
|
|
38
|
+
commit_sha: str = ""
|
|
39
|
+
elapsed_seconds: float = 0.0
|
|
40
|
+
files_parsed: int = 0
|
|
41
|
+
files_cached: int = 0
|
|
42
|
+
|
|
43
|
+
|
|
44
|
+
def sync_at(writer, source, target_sha: str, *, project_name: str, repo_uri: str, ref: str | None) -> SyncStats:
|
|
45
|
+
"""Recompute the whole Docker subgraph at `target_sha` and delta it. `source` is duck-typed
|
|
46
|
+
(GitRepoCache or LocalDirectorySource): only list_files/read_blob are used."""
|
|
47
|
+
started = time.monotonic()
|
|
48
|
+
proj_id = project_id(project_name)
|
|
49
|
+
|
|
50
|
+
writer.setup_schema(NODE_SCHEMAS) # brings the graph key + indexes into existence
|
|
51
|
+
if writer.get_property("Project", {"id": proj_id}, "commit_sha") == target_sha:
|
|
52
|
+
return SyncStats(commit_sha=target_sha, elapsed_seconds=time.monotonic() - started)
|
|
53
|
+
|
|
54
|
+
seen: dict[str, str] = {} # path -> blob_sha (dedup across suffixes)
|
|
55
|
+
for suffix in _FILE_SUFFIXES:
|
|
56
|
+
for path, blob_sha in source.list_files(target_sha, suffix, set(_EXCLUDED_DIR_NAMES)):
|
|
57
|
+
seen.setdefault(path, blob_sha)
|
|
58
|
+
|
|
59
|
+
files = []
|
|
60
|
+
for path, blob_sha in sorted(seen.items()):
|
|
61
|
+
try:
|
|
62
|
+
files.append((path, parse_source(source.read_blob(blob_sha))))
|
|
63
|
+
except Exception:
|
|
64
|
+
# A single malformed Dockerfile never fails the whole ingest. KNOWN LIMITATION (tracked
|
|
65
|
+
# follow-up): a parse/read failure drops the file from the recomputed target, so this
|
|
66
|
+
# sync REMOVES its prior nodes -- it does not keep last-good like the tree-sitter
|
|
67
|
+
# ingestors' `broken_files` path. Adopting that keep-last-good behavior here is deferred.
|
|
68
|
+
logger.warning("failed to parse Dockerfile %s (its graph nodes are removed this sync)", path, exc_info=True)
|
|
69
|
+
|
|
70
|
+
project_node = GraphNode(
|
|
71
|
+
"Project", {"id": proj_id},
|
|
72
|
+
{"name": project_name, "repo_uri": repo_uri, "commit_sha": target_sha, "ref": ref},
|
|
73
|
+
)
|
|
74
|
+
|
|
75
|
+
def make_target(): # re-iterable: stream_apply runs it once for nodes, once for edges
|
|
76
|
+
return itertools.chain([project_node], build_graph(files, proj_id))
|
|
77
|
+
|
|
78
|
+
stats, _reals, _placeholders = stream_apply(writer, proj_id, OWNED_LABELS, make_target)
|
|
79
|
+
elapsed = time.monotonic() - started
|
|
80
|
+
logger.info("docker: %d Dockerfile(s), +%dn/%de in %.2fs",
|
|
81
|
+
len(files), stats.nodes_added, stats.edges_added, elapsed)
|
|
82
|
+
return SyncStats(
|
|
83
|
+
nodes_added=stats.nodes_added, nodes_updated=stats.nodes_updated, nodes_removed=stats.nodes_removed,
|
|
84
|
+
edges_added=stats.edges_added, edges_updated=stats.edges_updated, edges_removed=stats.edges_removed,
|
|
85
|
+
commit_sha=target_sha, elapsed_seconds=elapsed, files_parsed=len(files),
|
|
86
|
+
)
|
|
87
|
+
|
|
88
|
+
|
|
89
|
+
def _git_language_sync(
|
|
90
|
+
writer,
|
|
91
|
+
source,
|
|
92
|
+
target_sha: str,
|
|
93
|
+
*,
|
|
94
|
+
repo_uri: str,
|
|
95
|
+
project_name: str,
|
|
96
|
+
solution_name: str | None,
|
|
97
|
+
ref: str | None,
|
|
98
|
+
cache_root=None,
|
|
99
|
+
) -> LanguageIngestResult:
|
|
100
|
+
"""GitLanguage adapter for the multi-language endpoint (Docker has no solution/cache knobs --
|
|
101
|
+
accepted for the shared interface and ignored)."""
|
|
102
|
+
s = sync_at(writer, source, target_sha, project_name=project_name, repo_uri=repo_uri, ref=ref)
|
|
103
|
+
return LanguageIngestResult(
|
|
104
|
+
nodes_added=s.nodes_added, nodes_updated=s.nodes_updated, nodes_removed=s.nodes_removed,
|
|
105
|
+
edges_added=s.edges_added, edges_updated=s.edges_updated, edges_removed=s.edges_removed,
|
|
106
|
+
files_parsed=s.files_parsed, files_cached=s.files_cached,
|
|
107
|
+
commit_sha=s.commit_sha, elapsed_seconds=s.elapsed_seconds,
|
|
108
|
+
)
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
"""Canonical id scheme for the Dockerfile graph (ADR 0007 §2), mirroring the other ingestors'
|
|
2
|
+
shape (`<lang>://<project>/...`) so one graph holds every source with interchangeable ids.
|
|
3
|
+
|
|
4
|
+
Docker-specific choices:
|
|
5
|
+
- A `BuildStage` is keyed off the *file* that declares it plus its stage name (or index when the
|
|
6
|
+
stage is unnamed) -- `docker://<project>/file/<path>#<stage>`.
|
|
7
|
+
- An `Image` is keyed by its project-INDEPENDENT normalized reference (`image://<ref>`, see
|
|
8
|
+
`image_ref.image_id`): it is the hub node a build and a run converge on across repos, so -- like a
|
|
9
|
+
cross-repo `extern://` placeholder -- it must NOT be scoped to one project.
|
|
10
|
+
"""
|
|
11
|
+
|
|
12
|
+
from __future__ import annotations
|
|
13
|
+
|
|
14
|
+
from auryn.ingestors.docker.image_ref import image_id # re-exported: the Image id lives in one place
|
|
15
|
+
|
|
16
|
+
__all__ = ["project_id", "file_id", "stage_id", "image_id"]
|
|
17
|
+
|
|
18
|
+
|
|
19
|
+
def project_id(project_name: str) -> str:
|
|
20
|
+
return f"docker://{project_name}"
|
|
21
|
+
|
|
22
|
+
|
|
23
|
+
def file_id(proj_id: str, rel_path: str) -> str:
|
|
24
|
+
# Only an exact leading `./` is stripped -- NOT every leading dot/slash (`.lstrip('./')` would turn
|
|
25
|
+
# `.github/Dockerfile` into `github/Dockerfile`, colliding ids and breaking the derived context).
|
|
26
|
+
rel = rel_path.replace(chr(92), "/")
|
|
27
|
+
while rel.startswith("./"):
|
|
28
|
+
rel = rel[2:]
|
|
29
|
+
return f"{proj_id}/file/{rel}"
|
|
30
|
+
|
|
31
|
+
|
|
32
|
+
def stage_id(file_id_: str, stage_key: str) -> str:
|
|
33
|
+
"""`stage_key` is the `AS` name, or the stringified 0-based index for an unnamed stage."""
|
|
34
|
+
return f"{file_id_}#{stage_key}"
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
"""Image-reference normalization now lives in `auryn.core.image_ref` -- shared by every deployment-tier
|
|
2
|
+
producer so their `image://` ids are identical (ADR 0007 §7, migrated when the compose producer
|
|
3
|
+
landed). This module re-exports it for back-compat so existing
|
|
4
|
+
`auryn.ingestors.docker.image_ref` imports keep working."""
|
|
5
|
+
|
|
6
|
+
from __future__ import annotations
|
|
7
|
+
|
|
8
|
+
from auryn.core.image_ref import ( # noqa: F401
|
|
9
|
+
DEFAULT_REGISTRY,
|
|
10
|
+
DEFAULT_TAG,
|
|
11
|
+
OFFICIAL_NAMESPACE,
|
|
12
|
+
SCRATCH,
|
|
13
|
+
ImageRef,
|
|
14
|
+
image_id,
|
|
15
|
+
normalize_image_ref,
|
|
16
|
+
parse_image_ref,
|
|
17
|
+
)
|
|
18
|
+
|
|
19
|
+
__all__ = [
|
|
20
|
+
"DEFAULT_REGISTRY", "DEFAULT_TAG", "OFFICIAL_NAMESPACE", "SCRATCH",
|
|
21
|
+
"ImageRef", "parse_image_ref", "normalize_image_ref", "image_id",
|
|
22
|
+
]
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
"""The parsed-Dockerfile data model (engine-agnostic). `file_parser.parse_source` produces these;
|
|
2
|
+
`build.build_graph` turns them into graph nodes/edges. Keeping this a plain dataclass tree (not
|
|
3
|
+
graph objects) means a future tree-sitter-dockerfile engine can swap in behind `parse_source`
|
|
4
|
+
without touching `build.py`."""
|
|
5
|
+
|
|
6
|
+
from __future__ import annotations
|
|
7
|
+
|
|
8
|
+
from dataclasses import dataclass, field
|
|
9
|
+
|
|
10
|
+
|
|
11
|
+
@dataclass(frozen=True)
|
|
12
|
+
class Copy:
|
|
13
|
+
"""A `COPY`/`ADD` instruction. `from_stage` is the `--from=` source (another build stage or an
|
|
14
|
+
external image) when present -- such a copy pulls from that stage/image, NOT from the host build
|
|
15
|
+
context, so it becomes a `COPIES_FROM` edge rather than a host-file `PACKAGES` join."""
|
|
16
|
+
|
|
17
|
+
sources: tuple[str, ...]
|
|
18
|
+
dest: str
|
|
19
|
+
from_stage: str | None = None
|
|
20
|
+
|
|
21
|
+
|
|
22
|
+
@dataclass(frozen=True)
|
|
23
|
+
class Stage:
|
|
24
|
+
"""One `FROM ... [AS name]` build stage and the instructions that follow it, up to the next
|
|
25
|
+
`FROM`. `base` is the raw `FROM` argument -- an image reference OR the name/index of an earlier
|
|
26
|
+
stage in the same file (multi-stage build)."""
|
|
27
|
+
|
|
28
|
+
index: int
|
|
29
|
+
base: str
|
|
30
|
+
name: str | None = None
|
|
31
|
+
copies: tuple[Copy, ...] = ()
|
|
32
|
+
exposed_ports: tuple[str, ...] = ()
|
|
33
|
+
entrypoint: str | None = None
|
|
34
|
+
cmd: str | None = None
|
|
35
|
+
workdir: str | None = None
|
|
36
|
+
|
|
37
|
+
|
|
38
|
+
@dataclass(frozen=True)
|
|
39
|
+
class ParsedDockerfile:
|
|
40
|
+
stages: tuple[Stage, ...] = ()
|
|
41
|
+
# Global `ARG`s declared before the first `FROM` (they can parameterize a `FROM ${ARG}` base).
|
|
42
|
+
args: dict[str, str] = field(default_factory=dict)
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
"""Import-light Docker language registration -- the `auryn.languages` entry-point target.
|
|
2
|
+
|
|
3
|
+
Importing this module registers the Docker GitLanguage without importing the parser: the
|
|
4
|
+
GitLanguage's `sync` is a lazy thunk that imports auryn.ingestors.docker.git_sync only when a source
|
|
5
|
+
actually contains Dockerfiles. Single-phase (declarative -- no deep pass).
|
|
6
|
+
|
|
7
|
+
Detection uses suffix matching (`path.endswith`), which catches `Dockerfile`, `web.Dockerfile`, and
|
|
8
|
+
`*.dockerfile`. Two KNOWN gaps, both resolved by the optional `GitLanguage.filename_matches` predicate
|
|
9
|
+
proposed in ADR 0007 §7 (every IaC producer needs basename matching), deferred until that lands:
|
|
10
|
+
- the `Dockerfile.prod` / `Dockerfile.dev` basename-variant family isn't matched by a pure suffix;
|
|
11
|
+
- an extensionless `Dockerfile` has an empty `Path.suffix`, so the save-watcher's suffix-based
|
|
12
|
+
`note_change` won't trigger an incremental resync on edit (a full `index`/commit resync still
|
|
13
|
+
picks it up). Both want basename-aware detection, not a suffix."""
|
|
14
|
+
|
|
15
|
+
from __future__ import annotations
|
|
16
|
+
|
|
17
|
+
from auryn.core.registry import GitLanguage, register_git_language
|
|
18
|
+
|
|
19
|
+
LANGUAGE = "docker"
|
|
20
|
+
FILE_SUFFIXES = ("Dockerfile", ".dockerfile")
|
|
21
|
+
EXCLUDED_DIR_NAMES = frozenset({".git", "node_modules", "vendor", "dist", ".idea", ".vscode"})
|
|
22
|
+
|
|
23
|
+
|
|
24
|
+
def _sync(*args, **kwargs):
|
|
25
|
+
"""Deferred until a source has Dockerfiles -- imports the parser engine."""
|
|
26
|
+
from auryn.ingestors.docker.git_sync import _git_language_sync
|
|
27
|
+
|
|
28
|
+
return _git_language_sync(*args, **kwargs)
|
|
29
|
+
|
|
30
|
+
|
|
31
|
+
register_git_language(
|
|
32
|
+
GitLanguage(
|
|
33
|
+
language=LANGUAGE,
|
|
34
|
+
file_suffixes=FILE_SUFFIXES,
|
|
35
|
+
excluded_dir_names=EXCLUDED_DIR_NAMES,
|
|
36
|
+
sync=_sync,
|
|
37
|
+
)
|
|
38
|
+
)
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
"""Graph schema the Dockerfile producer writes (ADR 0007). The deployment-tier contract: a
|
|
2
|
+
Dockerfile `File` owns its `BuildStage`s (HAS_STAGE); a stage is BASED_ON its base `Image` (or an
|
|
3
|
+
earlier stage) and COPIES_FROM earlier stages in a multi-stage build. `Image` is the shared hub
|
|
4
|
+
node, keyed by normalized reference and indexed on `ref` so the `deploy` stitch's cross-artifact
|
|
5
|
+
joins (and future Compose/k8s `RUNS_IMAGE`) are index seeks.
|
|
6
|
+
|
|
7
|
+
`Project`/`File`/`HAS_FILE` match the other ingestors verbatim (shared backbone). The code seam
|
|
8
|
+
(`PACKAGES`) is synthesized by the `deploy` enrichment (stitch.py), not the producer -- it MERGEs the
|
|
9
|
+
edge directly against the existing indexes, so it declares no `EdgeSchema` of its own. `BUILDS_IMAGE`
|
|
10
|
+
and the derived `SHIPS` edge are FUTURE contract outputs (the Compose/k8s/Terraform arms, ADR 0007):
|
|
11
|
+
the stitch already pre-clears them each run for forward-compat but does not create them yet. All three
|
|
12
|
+
are intentionally absent from this producer contract."""
|
|
13
|
+
|
|
14
|
+
from __future__ import annotations
|
|
15
|
+
|
|
16
|
+
from auryn.core.graph_model import EdgeSchema, NodeSchema
|
|
17
|
+
|
|
18
|
+
NODE_SCHEMAS = [
|
|
19
|
+
NodeSchema(label="Project", indexed_properties=("name",)),
|
|
20
|
+
NodeSchema(label="File", indexed_properties=("path",)),
|
|
21
|
+
NodeSchema(label="BuildStage", indexed_properties=("name",)),
|
|
22
|
+
NodeSchema(label="Image", indexed_properties=("ref",)), # the hub node; `ref` = normalized reference
|
|
23
|
+
]
|
|
24
|
+
|
|
25
|
+
# Labels this producer OWNS under its `docker://<project>` prefix and diffs on resync. `Image` is
|
|
26
|
+
# deliberately excluded: image nodes are shared/project-independent (`image://...`), MERGE-only here,
|
|
27
|
+
# and GC'd by the `deploy` stitch -- a single project's resync must never delete an image another
|
|
28
|
+
# repo still references (the shared-node lifecycle, ADR 0007 §6).
|
|
29
|
+
OWNED_LABELS = ["Project", "File", "BuildStage"]
|
|
30
|
+
|
|
31
|
+
EDGE_SCHEMAS = [
|
|
32
|
+
EdgeSchema(rel_type="HAS_FILE"), # Project -> File
|
|
33
|
+
EdgeSchema(rel_type="HAS_STAGE"), # File -> BuildStage
|
|
34
|
+
EdgeSchema(rel_type="BASED_ON"), # BuildStage -> Image | BuildStage (the FROM chain)
|
|
35
|
+
EdgeSchema(rel_type="COPIES_FROM"), # BuildStage -> BuildStage (multi-stage COPY --from)
|
|
36
|
+
]
|
|
@@ -0,0 +1,187 @@
|
|
|
1
|
+
"""The `deploy` stitch -- the deployment tier's cross-artifact join (ADR 0007 §4-§6).
|
|
2
|
+
|
|
3
|
+
v1 implements the Docker arm: the **code seam** `PACKAGES`. A Dockerfile build stage copies host
|
|
4
|
+
files from its build context; this pass resolves those `COPY` paths to the actual code `File` nodes a
|
|
5
|
+
language ingestor produced and links them, so the golden path reads:
|
|
6
|
+
|
|
7
|
+
code File <-PACKAGES- BuildStage -HAS_STAGE<- Dockerfile File
|
|
8
|
+
|
|
9
|
+
i.e. a query can go from a function/file to *which container image ships it* -- the code->container
|
|
10
|
+
connection, the mirror of the HTTP (ADR 0006) and ORM seams. It also keeps the shared `Image` hub
|
|
11
|
+
honest: `resolved` is recomputed (true iff something BUILDS_IMAGE the image) and orphan image nodes
|
|
12
|
+
(no builder, no runner, no base reference) are GC'd.
|
|
13
|
+
|
|
14
|
+
Graph-only + idempotent + order-independent: it owns its layer (the `deploy-stitch`-provenanced
|
|
15
|
+
edges + the image `resolved` flag), rebuilt from the current graph each run, so Dockerfile-first vs
|
|
16
|
+
code-first ingestion converge and a resync self-corrects. The other arms (`BUILDS_IMAGE` from a
|
|
17
|
+
Compose `build:`, `RUNS_IMAGE`/`SERVES`/`CONNECTS_TO`/`SHIPS`) land with the Compose/k8s/Terraform
|
|
18
|
+
producers -- their clears are already wired here so they compose into this one pass."""
|
|
19
|
+
|
|
20
|
+
from __future__ import annotations
|
|
21
|
+
|
|
22
|
+
import logging
|
|
23
|
+
import posixpath
|
|
24
|
+
import re
|
|
25
|
+
|
|
26
|
+
from auryn.core import deploy
|
|
27
|
+
from auryn.core.graph_client import GraphWriter
|
|
28
|
+
from auryn.core.graph_model import GraphEdge
|
|
29
|
+
|
|
30
|
+
logger = logging.getLogger("auryn.deploy")
|
|
31
|
+
|
|
32
|
+
_GLOB_CHARS = set("*?[")
|
|
33
|
+
|
|
34
|
+
|
|
35
|
+
def run(writer: GraphWriter, repo, target_sha: str) -> dict | None:
|
|
36
|
+
"""GraphEnrichment entrypoint. `repo`/`target_sha` are unused -- the stitch reads only the
|
|
37
|
+
finished graph. Returns None when there's nothing to do (no build stages / no join)."""
|
|
38
|
+
return stitch(writer)
|
|
39
|
+
|
|
40
|
+
|
|
41
|
+
def stitch(writer: GraphWriter) -> dict | None:
|
|
42
|
+
try:
|
|
43
|
+
has_stage = bool(writer.ro_query("MATCH (s:BuildStage) RETURN s.id LIMIT 1").result_set)
|
|
44
|
+
except Exception:
|
|
45
|
+
return None # empty graph key ("operation on empty key") -> nothing to stitch
|
|
46
|
+
|
|
47
|
+
_clear_prior_layer(writer)
|
|
48
|
+
|
|
49
|
+
edges: list[GraphEdge] = []
|
|
50
|
+
if has_stage:
|
|
51
|
+
edges = _packages_edges(writer)
|
|
52
|
+
if edges:
|
|
53
|
+
writer.merge_edges(edges)
|
|
54
|
+
|
|
55
|
+
deploy.recompute_image_resolved(writer)
|
|
56
|
+
orphans = deploy.gc_orphan_images(writer)
|
|
57
|
+
|
|
58
|
+
if not edges and not orphans:
|
|
59
|
+
return None
|
|
60
|
+
report = {"packages_edges": len(edges), "orphans_removed": orphans}
|
|
61
|
+
logger.info("deploy stitch: %d PACKAGES edge(s), %d orphan image(s) GC'd", len(edges), orphans)
|
|
62
|
+
return report
|
|
63
|
+
|
|
64
|
+
|
|
65
|
+
def _clear_prior_layer(writer: GraphWriter) -> None:
|
|
66
|
+
"""Drop this hook's own edges so a re-run rebuilds its layer from scratch (idempotent +
|
|
67
|
+
order-independent). Only `deploy-stitch`-provenanced edges are touched; a producer's declared
|
|
68
|
+
edges (BASED_ON/HAS_STAGE/...) are never this hook's and survive."""
|
|
69
|
+
for rel in ("PACKAGES", "BUILDS_IMAGE", "SHIPS"):
|
|
70
|
+
writer.query(f"MATCH ()-[r:{rel}]->() WHERE r.provenance = 'deploy-stitch' DELETE r")
|
|
71
|
+
|
|
72
|
+
|
|
73
|
+
# How each code ingestor exposes a source file's repo-relative path. Most languages emit a `File`
|
|
74
|
+
# node with `path`; Python models a source as a `Module` with `file_path` (no `File` node). The seam
|
|
75
|
+
# resolves code against every such convention so PACKAGES reaches whatever language built the graph --
|
|
76
|
+
# add a (label, path_property) pair here when a new ingestor uses a different code-source node.
|
|
77
|
+
_CODE_SOURCE_NODES = (("File", "path"), ("Module", "file_path"))
|
|
78
|
+
|
|
79
|
+
|
|
80
|
+
def _project_of(node_id: str) -> str:
|
|
81
|
+
"""The `<project>` component of a graph id (`<scheme>://<project>/...`), or "" if unparseable.
|
|
82
|
+
A Dockerfile and the code it ships, ingested from one repo, share it (`docker://demo`,
|
|
83
|
+
`python://demo`) -- so it scopes the PACKAGES join to the stage's OWN repo and never links an
|
|
84
|
+
image to another co-located repo's files that merely share a relative path."""
|
|
85
|
+
if "://" not in node_id:
|
|
86
|
+
return ""
|
|
87
|
+
return node_id.split("://", 1)[1].split("/", 1)[0]
|
|
88
|
+
|
|
89
|
+
|
|
90
|
+
def _packages_edges(writer: GraphWriter) -> list[GraphEdge]:
|
|
91
|
+
"""For each BuildStage, resolve its host-context `COPY` sources to the code source nodes a
|
|
92
|
+
language ingestor produced (File/Module, by path) and emit `BuildStage -PACKAGES-> <code node>`.
|
|
93
|
+
Matching is scoped to the stage's own project (a shared graph holds many repos). Two reads per
|
|
94
|
+
convention, matched in memory -- O(stages x copies x files), not a query per copy."""
|
|
95
|
+
stages = writer.ro_query(
|
|
96
|
+
"MATCH (s:BuildStage) RETURN s.id, s.context, s.copy_sources"
|
|
97
|
+
).result_set
|
|
98
|
+
# Every code source node EXCEPT the Dockerfiles this tier emits (those are keyed `docker://`).
|
|
99
|
+
code_nodes: list[tuple[str, str, str, str]] = [] # (id, path, label, project)
|
|
100
|
+
for label, prop in _CODE_SOURCE_NODES:
|
|
101
|
+
rows = writer.ro_query(
|
|
102
|
+
f"MATCH (n:{label}) WHERE n.{prop} IS NOT NULL AND NOT n.id STARTS WITH 'docker://' "
|
|
103
|
+
f"RETURN n.id, n.{prop}"
|
|
104
|
+
).result_set
|
|
105
|
+
code_nodes.extend((str(nid), str(path), label, _project_of(str(nid))) for nid, path in rows)
|
|
106
|
+
if not code_nodes:
|
|
107
|
+
return []
|
|
108
|
+
|
|
109
|
+
edges: list[GraphEdge] = []
|
|
110
|
+
for sid, context, copy_sources in stages:
|
|
111
|
+
if not copy_sources:
|
|
112
|
+
continue
|
|
113
|
+
stage_proj = _project_of(str(sid)) # PACKAGES only reaches THIS Dockerfile's own repo
|
|
114
|
+
context = str(context or "")
|
|
115
|
+
targets = [_target_path(context, str(src)) for src in copy_sources]
|
|
116
|
+
matched: set[str] = set()
|
|
117
|
+
for nid, path, label, proj in code_nodes:
|
|
118
|
+
if nid in matched or proj != stage_proj:
|
|
119
|
+
continue
|
|
120
|
+
if any(_path_under(path, t) for t in targets):
|
|
121
|
+
matched.add(nid)
|
|
122
|
+
edges.append(GraphEdge("PACKAGES", "BuildStage", {"id": str(sid)}, label, {"id": nid},
|
|
123
|
+
{"provenance": "deploy-stitch"}))
|
|
124
|
+
return edges
|
|
125
|
+
|
|
126
|
+
|
|
127
|
+
def _target_path(context: str, src: str) -> str:
|
|
128
|
+
"""The repo-relative path (or glob PATTERN) a `COPY <src>` resolves to, relative to the build
|
|
129
|
+
`context`. `.`/`""` means the whole context (returned as the context dir, `""` = repo root). A
|
|
130
|
+
glob is kept VERBATIM so `_path_under` matches the pattern per segment, not every sibling."""
|
|
131
|
+
src = src.strip()
|
|
132
|
+
if src.startswith("./"):
|
|
133
|
+
src = src[2:]
|
|
134
|
+
if src in (".", "", "/"):
|
|
135
|
+
return context
|
|
136
|
+
# Docker resolves COPY sources from the build-context ROOT: a leading `/` is dropped (not an
|
|
137
|
+
# absolute host path, so `COPY /app` means `<context>/app`), and `..` that would escape the context
|
|
138
|
+
# is removed (BuildKit forbids it) -- otherwise `COPY /../app` would normalize ABOVE the context and
|
|
139
|
+
# mis-link a sibling repo's file.
|
|
140
|
+
src = src.lstrip("/").rstrip("/")
|
|
141
|
+
while src.startswith("../"):
|
|
142
|
+
src = src[3:]
|
|
143
|
+
if src in ("..", ""):
|
|
144
|
+
return context
|
|
145
|
+
joined = posixpath.join(context, src) if context else src
|
|
146
|
+
norm = posixpath.normpath(joined) if joined else ""
|
|
147
|
+
return "" if norm == "." else norm
|
|
148
|
+
|
|
149
|
+
|
|
150
|
+
def _glob_to_regex(pattern: str) -> re.Pattern:
|
|
151
|
+
"""Translate a Docker COPY glob to a regex with Go `filepath.Match` semantics: `*` and `?` do NOT
|
|
152
|
+
cross `/` (unlike `fnmatch`), so `src/*.py` matches `src/app.py` but not `src/sub/app.py`. `[...]`
|
|
153
|
+
character classes pass through; every other char is literal."""
|
|
154
|
+
out, i = [], 0
|
|
155
|
+
while i < len(pattern):
|
|
156
|
+
c = pattern[i]
|
|
157
|
+
if c == "*":
|
|
158
|
+
out.append("[^/]*")
|
|
159
|
+
elif c == "?":
|
|
160
|
+
out.append("[^/]")
|
|
161
|
+
elif c == "[":
|
|
162
|
+
j = pattern.find("]", i + 1)
|
|
163
|
+
if j == -1:
|
|
164
|
+
out.append(re.escape(c))
|
|
165
|
+
else:
|
|
166
|
+
out.append(pattern[i : j + 1]) # a literal char class, valid regex as-is
|
|
167
|
+
i = j
|
|
168
|
+
else:
|
|
169
|
+
out.append(re.escape(c))
|
|
170
|
+
i += 1
|
|
171
|
+
return re.compile("^" + "".join(out) + "$")
|
|
172
|
+
|
|
173
|
+
|
|
174
|
+
def _path_under(path: str, target: str) -> bool:
|
|
175
|
+
"""A code file `path` is packaged by a copy resolving to `target` iff: the target is the whole
|
|
176
|
+
context root (`""`); the target is a glob and the path matches it per segment (`COPY src/*.py`
|
|
177
|
+
links `src/app.py`, not `src/README` nor nested `src/sub/app.py`); or the path IS that file or
|
|
178
|
+
lives under that directory."""
|
|
179
|
+
if target == "":
|
|
180
|
+
return True
|
|
181
|
+
if any(ch in target for ch in _GLOB_CHARS):
|
|
182
|
+
return _glob_to_regex(target).match(path) is not None
|
|
183
|
+
return path == target or path.startswith(target + "/")
|
|
184
|
+
|
|
185
|
+
|
|
186
|
+
# Image `resolved`-recompute and orphan GC now live in `auryn.core.deploy` (shared with the compose
|
|
187
|
+
# and future k8s/terraform arms so the semantics can't diverge) -- see stitch()'s calls above.
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
Metadata-Version: 2.5
|
|
2
|
+
Name: auryn-docker
|
|
3
|
+
Version: 0.8.2
|
|
4
|
+
Summary: Dockerfile plugin for Auryn and the first producer of the deployment & infrastructure tier (ADR 0007). A dependency-free Dockerfile parser emits BuildStage nodes, the shared image-keyed `Image` hub (the FROM chain, as resolved:false placeholders) and multi-stage COPY --from edges; a `deploy` enrichment links build stages to the code they package (PACKAGES), recomputes image `resolved` and GCs orphan images. Compose/k8s/Helm/Terraform producers join onto the hub. Depends only on auryn-core.
|
|
5
|
+
Author-email: Roi Lipman <roi.lipman@falkordb.com>
|
|
6
|
+
License: MIT
|
|
7
|
+
License-File: LICENSE
|
|
8
|
+
Requires-Python: >=3.12
|
|
9
|
+
Requires-Dist: auryn-core
|
|
10
|
+
Description-Content-Type: text/markdown
|
|
11
|
+
|
|
12
|
+
# auryn-docker
|
|
13
|
+
|
|
14
|
+
Dockerfile plugin for Auryn and the first producer of the deployment & infrastructure tier (ADR 0007). A dependency-free Dockerfile parser emits BuildStage nodes, the shared image-keyed `Image` hub (the FROM chain, as resolved:false placeholders) and multi-stage COPY --from edges; a `deploy` enrichment links build stages to the code they package (PACKAGES), recomputes image `resolved` and GCs orphan images. Compose/k8s/Helm/Terraform producers join onto the hub. Depends only on auryn-core.
|
|
15
|
+
|
|
16
|
+
Part of [Auryn](https://github.com/FalkorDB/Auryn), which turns a codebase into a queryable knowledge graph for AI agents.
|
|
17
|
+
|
|
18
|
+
## Install
|
|
19
|
+
|
|
20
|
+
```bash
|
|
21
|
+
pip install falkordb-auryn # Auryn with every plugin
|
|
22
|
+
pip install "auryn-core[docker]" # Auryn with only this plugin
|
|
23
|
+
```
|
|
24
|
+
|
|
25
|
+
## License
|
|
26
|
+
|
|
27
|
+
MIT. See the [LICENSE](https://github.com/FalkorDB/Auryn/blob/main/packages/docker/LICENSE).
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
auryn/ingestors/docker/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
|
2
|
+
auryn/ingestors/docker/build.py,sha256=jSsSThCVwuUM6TvIXi41kqK7Q5ZEAYC6eeZXrGmqPro,6092
|
|
3
|
+
auryn/ingestors/docker/enrichment.py,sha256=oZ3lJ8IuPf5exwX4VoDIBiAHLjjG-gRDGypGqlwY3PM,579
|
|
4
|
+
auryn/ingestors/docker/file_parser.py,sha256=xo-dXCSFymEitpmbiaNrQZEtMIh-qwirBsdHjgdSl88,6295
|
|
5
|
+
auryn/ingestors/docker/git_sync.py,sha256=ZBAEcL_UkH89wSSrs6hSjQnczySD6b44wtU3dxHiSE4,4979
|
|
6
|
+
auryn/ingestors/docker/ids.py,sha256=MEl2jbaK-lhvneXqZpGFuXG42pbJkC__9DPnqPtsySw,1504
|
|
7
|
+
auryn/ingestors/docker/image_ref.py,sha256=A8guTui7bkCog82sqhizck6_UC3QzvDuaqh86BOP-ks,719
|
|
8
|
+
auryn/ingestors/docker/model.py,sha256=ChBGe8BwOqOooUKflLUkTKQUAhTzevgG4-C9o0Cz5WE,1555
|
|
9
|
+
auryn/ingestors/docker/plugin.py,sha256=u4tbyVH4xybU_y7e5-IVG9XhNvvCYqN6WVy_JlKh3aM,1697
|
|
10
|
+
auryn/ingestors/docker/schema.py,sha256=ceO4gg55ActlwP_HNMaOUxcNZrAN7mHTHfiJvADuujw,2162
|
|
11
|
+
auryn/ingestors/docker/stitch.py,sha256=K3c7Avv1Z4hMRkTpO8HWVccEu6vlyKCD-d066WFpEJc,8718
|
|
12
|
+
auryn_docker-0.8.2.dist-info/METADATA,sha256=D74Iq9Ah0vn22SsGFSvDvhZNr0Ojh-HEoyDjMEF7R40,1647
|
|
13
|
+
auryn_docker-0.8.2.dist-info/WHEEL,sha256=2iZrJkDIkeDh0k9SikKMqFuRP-ua6mb4Ir1AsER4BEw,87
|
|
14
|
+
auryn_docker-0.8.2.dist-info/entry_points.txt,sha256=PdjLXMA5qF5RLzFt0dWFbrpBT1wRJpicKFEcKN6SYoI,121
|
|
15
|
+
auryn_docker-0.8.2.dist-info/licenses/LICENSE,sha256=MuKfC8-ZgDZVoySTMklxyndvd1_og68pI2gS94re3RI,1065
|
|
16
|
+
auryn_docker-0.8.2.dist-info/RECORD,,
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 FalkorDB
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|