auryn-compose 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.
File without changes
@@ -0,0 +1,82 @@
1
+ """Turn parsed compose files into the deployment-tier graph (ADR 0007): File -> Service, each service
2
+ RUNS_IMAGE the shared `Image` hub (from its `image:`) and DEPENDS_ON the services it waits on. A
3
+ service that builds stores the repo-relative Dockerfile path the `deploy-compose` stitch resolves to a
4
+ `BuildStage` (for `BUILDS_IMAGE`).
5
+
6
+ Emits the `Image` hub nodes `resolved:false` -- the stitch flips an image to `resolved:true` once a
7
+ `BUILDS_IMAGE` proves it internal. Emits no cross-artifact edge (the producer never reaches outside its
8
+ own files)."""
9
+
10
+ from __future__ import annotations
11
+
12
+ import posixpath
13
+ from collections.abc import Iterator
14
+
15
+ from auryn.core.graph_model import GraphEdge, GraphNode
16
+ from auryn.core.image_ref import image_id, parse_image_ref
17
+ from auryn.ingestors.compose import ids
18
+ from auryn.ingestors.compose.model import ParsedCompose, Service
19
+
20
+
21
+ def _dockerfile_path(compose_dir: str, svc: Service) -> str | None:
22
+ """The repo-relative path of the Dockerfile a service builds, or None if it doesn't build. `build:`
23
+ context is relative to the COMPOSE FILE's directory; the Dockerfile defaults to `Dockerfile` inside
24
+ that context."""
25
+ if svc.build_context is None:
26
+ return None
27
+ ctx = svc.build_context.strip()
28
+ ctx = ctx[2:] if ctx.startswith("./") else ctx
29
+ dockerfile = (svc.build_dockerfile or "Dockerfile").strip()
30
+ rel = posixpath.join(ctx, dockerfile)
31
+ joined = posixpath.join(compose_dir, rel) if compose_dir else rel
32
+ return posixpath.normpath(joined)
33
+
34
+
35
+ def build_graph(files: list[tuple[str, ParsedCompose]], proj_id: str) -> Iterator[GraphNode | GraphEdge]:
36
+ for rel_path, parsed in files:
37
+ fid = ids.file_id(proj_id, rel_path)
38
+ compose_dir = posixpath.dirname(rel_path)
39
+ yield GraphNode("File", {"id": fid}, {"path": rel_path, "name": posixpath.basename(rel_path)})
40
+ yield GraphEdge("HAS_FILE", "Project", {"id": proj_id}, "File", {"id": fid})
41
+
42
+ svc_ids = {s.name: ids.service_id(fid, s.name) for s in parsed.services}
43
+ for svc in parsed.services:
44
+ sid = svc_ids[svc.name]
45
+ dockerfile = _dockerfile_path(compose_dir, svc)
46
+ props: dict[str, object] = {
47
+ "name": svc.name,
48
+ "ports": list(svc.ports),
49
+ # Always written (empty when the service doesn't build) so a resync that DROPS `build:`
50
+ # overwrites the old value -- a MERGE's `SET n += ...` never clears a now-absent key, so
51
+ # omitting it would leave a stale path and a false BUILDS_IMAGE.
52
+ "build_dockerfile": dockerfile or "",
53
+ "build_target": svc.build_target or "",
54
+ }
55
+ yield GraphNode("Service", {"id": sid}, props)
56
+ yield GraphEdge("HAS_SERVICE", "File", {"id": fid}, "Service", {"id": sid})
57
+
58
+ if svc.image:
59
+ yield from _emit_image(svc.image)
60
+ yield GraphEdge("RUNS_IMAGE", "Service", {"id": sid}, "Image", {"id": image_id(svc.image)})
61
+
62
+ for dep in svc.depends_on:
63
+ if dep in svc_ids and svc_ids[dep] != sid:
64
+ yield GraphEdge("DEPENDS_ON", "Service", {"id": sid}, "Service", {"id": svc_ids[dep]})
65
+
66
+
67
+ def _emit_image(ref: str) -> Iterator[GraphNode]:
68
+ r = parse_image_ref(ref)
69
+ yield GraphNode(
70
+ "Image",
71
+ {"id": image_id(ref)},
72
+ {
73
+ "ref": r.normalized,
74
+ "registry": r.registry,
75
+ "repository": r.repository,
76
+ "tag": r.tag,
77
+ "digest": r.digest,
78
+ "resolved": False, # the deploy-compose stitch flips this true once a BUILDS_IMAGE appears
79
+ "origin": "registry",
80
+ **({"raw": r.raw} if r.unresolved else {}),
81
+ },
82
+ )
@@ -0,0 +1,13 @@
1
+ """The `deploy-compose` stitch registration -- the `auryn.enrichments` entry-point target (ADR 0007).
2
+ Import-light: `stitch` pulls in only core graph helpers (no PyYAML)."""
3
+
4
+ from __future__ import annotations
5
+
6
+ from auryn.core.registry import GraphEnrichment, register_graph_enrichment
7
+ from auryn.ingestors.compose.stitch import run as _run
8
+
9
+ # order 110 > the docker `deploy` hook's default 100, so BUILDS_IMAGE is emitted (and `resolved`
10
+ # recomputed) AFTER docker's PACKAGES/GC pass -- the final `resolved` reflects the builder this adds.
11
+ register_graph_enrichment(GraphEnrichment(name="deploy-compose", run=_run, order=110))
12
+
13
+ __all__ = ["_run"]
@@ -0,0 +1,86 @@
1
+ """Parse a docker-compose file -> `ParsedCompose` (PyYAML). Only the fields the deployment graph needs
2
+ -- services, their `image:`, `build:`, `depends_on:`, `ports:`. A YAML document without a top-level
3
+ `services:` map is not a compose file and yields nothing (the suffix match is broad, so this guard
4
+ keeps a stray `*.compose.yml` from producing junk)."""
5
+
6
+ from __future__ import annotations
7
+
8
+ import yaml
9
+
10
+ from auryn.ingestors.compose.model import ParsedCompose, Service
11
+
12
+
13
+ def _as_str(v) -> str | None:
14
+ return str(v) if v is not None else None
15
+
16
+
17
+ def _depends_names(depends) -> tuple[str, ...]:
18
+ """`depends_on` is a list (`[db, queue]`) or the long-form map (`{db: {condition: ...}}`)."""
19
+ if isinstance(depends, list):
20
+ return tuple(str(d) for d in depends)
21
+ if isinstance(depends, dict):
22
+ return tuple(str(k) for k in depends)
23
+ return ()
24
+
25
+
26
+ def _ports(ports) -> tuple[str, ...]:
27
+ """`ports` is a list of `"8080:8080"` strings/ints, or long-form `{target, published, protocol,
28
+ host_ip}` maps -- normalized so the long form carries the same host/protocol detail the short form
29
+ does (so `{target:53, published:53, protocol:udp}` isn't confused with the TCP port)."""
30
+ out: list[str] = []
31
+ if isinstance(ports, list):
32
+ for p in ports:
33
+ if isinstance(p, dict):
34
+ tgt, pub, proto, host = p.get("target"), p.get("published"), p.get("protocol"), p.get("host_ip")
35
+ s = f"{pub}:{tgt}" if pub is not None else str(tgt)
36
+ if host:
37
+ s = f"{host}:{s}"
38
+ if proto:
39
+ s = f"{s}/{proto}"
40
+ out.append(s)
41
+ else:
42
+ out.append(str(p))
43
+ return tuple(out)
44
+
45
+
46
+ def _build(spec) -> tuple[str | None, str | None, str | None]:
47
+ """`build:` is a context string (`./api`) or a map (`{context, dockerfile, target}`). A map defaults
48
+ its context to `.` (Compose's own default) -- except a `dockerfile_inline` build, which has no file
49
+ on disk to resolve, so it stays unbuilt here."""
50
+ build = spec.get("build")
51
+ if isinstance(build, str):
52
+ return build, None, None
53
+ if isinstance(build, dict):
54
+ if build.get("dockerfile_inline") is not None:
55
+ return None, None, None
56
+ return _as_str(build.get("context", ".")), _as_str(build.get("dockerfile")), _as_str(build.get("target"))
57
+ return None, None, None
58
+
59
+
60
+ def parse_source(data: str | bytes) -> ParsedCompose:
61
+ if isinstance(data, bytes):
62
+ data = data.decode("utf-8", errors="replace")
63
+ try:
64
+ doc = yaml.safe_load(data)
65
+ except yaml.YAMLError:
66
+ return ParsedCompose()
67
+ if not isinstance(doc, dict) or not isinstance(doc.get("services"), dict):
68
+ return ParsedCompose() # not a compose file
69
+
70
+ services: list[Service] = []
71
+ for name, spec in doc["services"].items():
72
+ if not isinstance(spec, dict):
73
+ spec = {}
74
+ ctx, dockerfile, target = _build(spec)
75
+ services.append(
76
+ Service(
77
+ name=str(name),
78
+ image=_as_str(spec.get("image")),
79
+ build_context=ctx,
80
+ build_dockerfile=dockerfile,
81
+ build_target=target,
82
+ depends_on=_depends_names(spec.get("depends_on")),
83
+ ports=_ports(spec.get("ports")),
84
+ )
85
+ )
86
+ return ParsedCompose(tuple(services))
@@ -0,0 +1,94 @@
1
+ """Git-tracked (and directory) docker-compose ingestion: fully recompute the project's Compose
2
+ subgraph at `target_sha` and diff it onto the graph (graph_sync.stream_apply) -- the same
3
+ recompute-and-delta model every file-based ingestor uses. v1 is full-recompute only (compose files
4
+ are few and tiny). Registered as the `compose` GitLanguage by the import-light plugin.py."""
5
+
6
+ from __future__ import annotations
7
+
8
+ import itertools
9
+ import logging
10
+ import time
11
+ from dataclasses import dataclass
12
+
13
+ from auryn.core.graph_model import GraphNode
14
+ from auryn.core.graph_sync import stream_apply
15
+ from auryn.core.registry import LanguageIngestResult
16
+ from auryn.ingestors.compose.build import build_graph
17
+ from auryn.ingestors.compose.file_parser import parse_source
18
+ from auryn.ingestors.compose.ids import project_id
19
+ from auryn.ingestors.compose.plugin import EXCLUDED_DIR_NAMES as _EXCLUDED_DIR_NAMES
20
+ from auryn.ingestors.compose.plugin import FILE_SUFFIXES as _FILE_SUFFIXES
21
+ from auryn.ingestors.compose.schema import NODE_SCHEMAS, OWNED_LABELS
22
+
23
+ logger = logging.getLogger(__name__)
24
+
25
+
26
+ @dataclass
27
+ class SyncStats:
28
+ nodes_added: int = 0
29
+ nodes_updated: int = 0
30
+ nodes_removed: int = 0
31
+ edges_added: int = 0
32
+ edges_updated: int = 0
33
+ edges_removed: int = 0
34
+ commit_sha: str = ""
35
+ elapsed_seconds: float = 0.0
36
+ files_parsed: int = 0
37
+ files_cached: int = 0
38
+
39
+
40
+ def sync_at(writer, source, target_sha: str, *, project_name: str, repo_uri: str, ref: str | None) -> SyncStats:
41
+ started = time.monotonic()
42
+ proj_id = project_id(project_name)
43
+
44
+ writer.setup_schema(NODE_SCHEMAS)
45
+ if writer.get_property("Project", {"id": proj_id}, "commit_sha") == target_sha:
46
+ return SyncStats(commit_sha=target_sha, elapsed_seconds=time.monotonic() - started)
47
+
48
+ seen: dict[str, str] = {}
49
+ for suffix in _FILE_SUFFIXES:
50
+ for path, blob_sha in source.list_files(target_sha, suffix, set(_EXCLUDED_DIR_NAMES)):
51
+ seen.setdefault(path, blob_sha)
52
+
53
+ files = []
54
+ for path, blob_sha in sorted(seen.items()):
55
+ try:
56
+ files.append((path, parse_source(source.read_blob(blob_sha))))
57
+ except Exception:
58
+ logger.warning("failed to read compose file %s (its nodes are removed this sync)", path, exc_info=True)
59
+ # KNOWN LIMITATION (tracked follow-up, tier-wide with docker): a malformed compose edit parses to an
60
+ # empty document, so the recompute REMOVES that file's prior services/edges until it's fixed -- it
61
+ # does not keep last-good like the tree-sitter ingestors' `broken_files` path. Deferred.
62
+
63
+ project_node = GraphNode(
64
+ "Project", {"id": proj_id},
65
+ {"name": project_name, "repo_uri": repo_uri, "commit_sha": target_sha, "ref": ref},
66
+ )
67
+
68
+ def make_target():
69
+ # Project node LAST: its `commit_sha` is written after the File/Service nodes, so a sync that
70
+ # fails mid-write won't leave a commit-stamped partial graph that the next run short-circuits.
71
+ # (stream_apply writes ALL nodes before ANY edge, so HAS_FILE still finds its Project.)
72
+ return itertools.chain(build_graph(files, proj_id), [project_node])
73
+
74
+ stats, _r, _p = stream_apply(writer, proj_id, OWNED_LABELS, make_target)
75
+ elapsed = time.monotonic() - started
76
+ logger.info("compose: %d file(s), +%dn/%de in %.2fs", len(files), stats.nodes_added, stats.edges_added, elapsed)
77
+ return SyncStats(
78
+ nodes_added=stats.nodes_added, nodes_updated=stats.nodes_updated, nodes_removed=stats.nodes_removed,
79
+ edges_added=stats.edges_added, edges_updated=stats.edges_updated, edges_removed=stats.edges_removed,
80
+ commit_sha=target_sha, elapsed_seconds=elapsed, files_parsed=len(files),
81
+ )
82
+
83
+
84
+ def _git_language_sync(
85
+ writer, source, target_sha: str, *, repo_uri: str, project_name: str,
86
+ solution_name: str | None, ref: str | None, cache_root=None,
87
+ ) -> LanguageIngestResult:
88
+ s = sync_at(writer, source, target_sha, project_name=project_name, repo_uri=repo_uri, ref=ref)
89
+ return LanguageIngestResult(
90
+ nodes_added=s.nodes_added, nodes_updated=s.nodes_updated, nodes_removed=s.nodes_removed,
91
+ edges_added=s.edges_added, edges_updated=s.edges_updated, edges_removed=s.edges_removed,
92
+ files_parsed=s.files_parsed, files_cached=s.files_cached,
93
+ commit_sha=s.commit_sha, elapsed_seconds=s.elapsed_seconds,
94
+ )
@@ -0,0 +1,26 @@
1
+ """Canonical id scheme for the Compose graph (ADR 0007 §2), mirroring the other producers
2
+ (`<source>://<project>/...`). A `Service` is keyed off the compose *file* that declares it plus its
3
+ service name -- `compose://<project>/file/<path>#<service>` -- so two compose files in one repo keep
4
+ their same-named services distinct. The shared `Image` hub keys via `core.image_ref.image_id`, the
5
+ same normalization every deployment-tier producer uses."""
6
+
7
+ from __future__ import annotations
8
+
9
+ from auryn.core.image_ref import image_id # re-exported: the Image id lives in one place
10
+
11
+ __all__ = ["project_id", "file_id", "service_id", "image_id"]
12
+
13
+
14
+ def project_id(project_name: str) -> str:
15
+ return f"compose://{project_name}"
16
+
17
+
18
+ def file_id(proj_id: str, rel_path: str) -> str:
19
+ rel = rel_path.replace(chr(92), "/")
20
+ while rel.startswith("./"):
21
+ rel = rel[2:]
22
+ return f"{proj_id}/file/{rel}"
23
+
24
+
25
+ def service_id(file_id_: str, name: str) -> str:
26
+ return f"{file_id_}#{name}"
@@ -0,0 +1,26 @@
1
+ """Parsed docker-compose data model (engine-agnostic). `file_parser.parse_source` produces these;
2
+ `build.build_graph` turns them into graph nodes/edges."""
3
+
4
+ from __future__ import annotations
5
+
6
+ from dataclasses import dataclass
7
+
8
+
9
+ @dataclass(frozen=True)
10
+ class Service:
11
+ """One compose service. `image` is the ref it runs; `build_context`/`build_dockerfile` (when the
12
+ service builds) let the stitch resolve the Dockerfile that PRODUCES that image. `depends_on` is the
13
+ service names it waits on."""
14
+
15
+ name: str
16
+ image: str | None = None
17
+ build_context: str | None = None
18
+ build_dockerfile: str | None = None # relative to the context; defaults to "Dockerfile"
19
+ build_target: str | None = None # `build.target` -- the stage that produces the image
20
+ depends_on: tuple[str, ...] = ()
21
+ ports: tuple[str, ...] = ()
22
+
23
+
24
+ @dataclass(frozen=True)
25
+ class ParsedCompose:
26
+ services: tuple[Service, ...] = ()
@@ -0,0 +1,35 @@
1
+ """Import-light Compose language registration -- the `auryn.languages` entry-point target.
2
+
3
+ Importing this registers the Compose GitLanguage without importing PyYAML: the lazy `sync` thunk
4
+ imports the engine only when a source actually contains a compose file.
5
+
6
+ Detection by suffix: `compose.yml`/`compose.yaml` matches the four canonical names -- `compose.yml`,
7
+ `compose.yaml`, `docker-compose.yml`, `docker-compose.yaml` (the `docker-` prefix is covered because
8
+ those paths still END with `compose.yml`/`compose.yaml`). The parser guards on a top-level `services:`
9
+ map, so a stray non-compose `*.compose.yml` that slips through produces nothing. A non-standard name
10
+ (`docker-compose.prod.yml`) is NOT matched -- the same basename-variant gap as Docker, resolved by the
11
+ `GitLanguage.filename_matches` follow-up (ADR 0007 §7)."""
12
+
13
+ from __future__ import annotations
14
+
15
+ from auryn.core.registry import GitLanguage, register_git_language
16
+
17
+ LANGUAGE = "compose"
18
+ FILE_SUFFIXES = ("compose.yml", "compose.yaml")
19
+ EXCLUDED_DIR_NAMES = frozenset({".git", "node_modules", "vendor", "dist", ".idea", ".vscode"})
20
+
21
+
22
+ def _sync(*args, **kwargs):
23
+ from auryn.ingestors.compose.git_sync import _git_language_sync
24
+
25
+ return _git_language_sync(*args, **kwargs)
26
+
27
+
28
+ register_git_language(
29
+ GitLanguage(
30
+ language=LANGUAGE,
31
+ file_suffixes=FILE_SUFFIXES,
32
+ excluded_dir_names=EXCLUDED_DIR_NAMES,
33
+ sync=_sync,
34
+ )
35
+ )
@@ -0,0 +1,29 @@
1
+ """Graph schema the Compose producer writes (ADR 0007). A compose `File` owns the `Service`s it
2
+ declares (HAS_SERVICE); a service RUNS_IMAGE the shared `Image` hub and DEPENDS_ON other services.
3
+
4
+ `Project`/`File`/`HAS_FILE` and `Image`/`DEPENDS_ON` match the rest of the tier verbatim (shared
5
+ contract). The `BUILDS_IMAGE` edge that closes the build->run loop is synthesized by the
6
+ `deploy-compose` enrichment (stitch.py), not the producer -- it joins a service's `build:` to the
7
+ Dockerfile's `BuildStage`, so it's declared there, not here."""
8
+
9
+ from __future__ import annotations
10
+
11
+ from auryn.core.graph_model import EdgeSchema, NodeSchema
12
+
13
+ NODE_SCHEMAS = [
14
+ NodeSchema(label="Project", indexed_properties=("name",)),
15
+ NodeSchema(label="File", indexed_properties=("path",)),
16
+ NodeSchema(label="Service", indexed_properties=("name",)),
17
+ NodeSchema(label="Image", indexed_properties=("ref",)), # the shared hub; `ref` = normalized reference
18
+ ]
19
+
20
+ # Labels this producer OWNS under its `compose://<project>` prefix and diffs on resync. `Image` is
21
+ # excluded (shared/project-independent `image://...`, MERGE-only; GC'd by the deploy stitch).
22
+ OWNED_LABELS = ["Project", "File", "Service"]
23
+
24
+ EDGE_SCHEMAS = [
25
+ EdgeSchema(rel_type="HAS_FILE"), # Project -> File
26
+ EdgeSchema(rel_type="HAS_SERVICE"), # File -> Service
27
+ EdgeSchema(rel_type="RUNS_IMAGE"), # Service -> Image (the `image:` it runs)
28
+ EdgeSchema(rel_type="DEPENDS_ON"), # Service -> Service (`depends_on`)
29
+ ]
@@ -0,0 +1,107 @@
1
+ """The `deploy-compose` stitch -- closes the build->run loop (ADR 0007 §4).
2
+
3
+ A compose service that both `build:`s a Dockerfile and runs an `image:` tells us that Dockerfile
4
+ PRODUCES that image. This pass resolves the service's Dockerfile path to the right `BuildStage` (the
5
+ docker producer's nodes, matched by path -- no package dependency) and links them:
6
+
7
+ api#final (BuildStage) -BUILDS_IMAGE-> shop/api:1.0 (Image) <-RUNS_IMAGE- Service api
8
+
9
+ Now the image has a builder, so it flips `resolved:true`/`origin:internal` -- the hub becomes a real
10
+ join between the code a Dockerfile packages and the service that runs it.
11
+
12
+ Graph-only + idempotent + order-independent: it owns its layer (the `compose-stitch` BUILDS_IMAGE
13
+ edges), rebuilt each run, then recomputes image `resolved` and GCs orphan images via the shared
14
+ `core.deploy` helpers (so cleanup happens even when docker's `deploy` hook is disabled). Scoped
15
+ per-project so a service only matches a Dockerfile in its OWN repo."""
16
+
17
+ from __future__ import annotations
18
+
19
+ import logging
20
+
21
+ from auryn.core import deploy
22
+ from auryn.core.graph_client import GraphWriter
23
+ from auryn.core.graph_model import GraphEdge
24
+
25
+ logger = logging.getLogger("auryn.deploy-compose")
26
+
27
+
28
+ def run(writer: GraphWriter, repo, target_sha: str) -> dict | None:
29
+ """GraphEnrichment entrypoint. Reads only the finished graph."""
30
+ return stitch(writer)
31
+
32
+
33
+ def _project_of(node_id: str) -> str:
34
+ if "://" not in node_id:
35
+ return ""
36
+ return node_id.split("://", 1)[1].split("/", 1)[0]
37
+
38
+
39
+ def _is_empty_graph(exc: Exception) -> bool:
40
+ """A query over a graph key that doesn't exist yet raises an 'operation on empty key' error -- the
41
+ one condition we swallow (nothing to stitch). Any other error propagates so the runner records it."""
42
+ return "empty key" in str(exc).lower()
43
+
44
+
45
+ def stitch(writer: GraphWriter) -> dict | None:
46
+ try:
47
+ services = writer.ro_query(
48
+ "MATCH (s:Service)-[:RUNS_IMAGE]->(img:Image) WHERE coalesce(s.build_dockerfile, '') <> '' "
49
+ "RETURN s.id, s.build_dockerfile, s.build_target, img.id"
50
+ ).result_set
51
+ except Exception as e:
52
+ if _is_empty_graph(e):
53
+ return None
54
+ raise
55
+
56
+ _clear_prior_layer(writer)
57
+ edges = _builds_image_edges(writer, services)
58
+ if edges:
59
+ writer.merge_edges(edges)
60
+ deploy.recompute_image_resolved(writer)
61
+ orphans = deploy.gc_orphan_images(writer)
62
+
63
+ if not edges and not orphans:
64
+ return None
65
+ report = {"builds_image_edges": len(edges), "orphans_removed": orphans}
66
+ logger.info("deploy-compose: %d BUILDS_IMAGE edge(s), %d orphan image(s) GC'd", len(edges), orphans)
67
+ return report
68
+
69
+
70
+ def _clear_prior_layer(writer: GraphWriter) -> None:
71
+ """Drop this hook's own BUILDS_IMAGE edges so a re-run rebuilds its layer (idempotent). Only
72
+ `compose-stitch`-provenanced edges are touched -- never a declared edge or another layer's."""
73
+ writer.query("MATCH ()-[r:BUILDS_IMAGE]->() WHERE r.provenance = 'compose-stitch' DELETE r")
74
+
75
+
76
+ def _builds_image_edges(writer: GraphWriter, services) -> list[GraphEdge]:
77
+ """For each building service, resolve the BuildStage its image comes from and link it. The stage is
78
+ the one named by `build.target` when set, else the Dockerfile's FINAL stage (highest index) -- a
79
+ `target: test` service must build the `test` stage, not production, or blast-radius runs through the
80
+ wrong code."""
81
+ edges: list[GraphEdge] = []
82
+ for sid, dockerfile, target, img_id in services:
83
+ proj = _project_of(str(sid))
84
+ stage_id = _resolve_stage(writer, proj, str(dockerfile), str(target or ""))
85
+ if stage_id:
86
+ edges.append(GraphEdge("BUILDS_IMAGE", "BuildStage", {"id": stage_id},
87
+ "Image", {"id": str(img_id)}, {"provenance": "compose-stitch"}))
88
+ return edges
89
+
90
+
91
+ def _resolve_stage(writer: GraphWriter, proj: str, dockerfile: str, target: str) -> str | None:
92
+ """The BuildStage id a service's image comes from, scoped to its own project. With `target`, match
93
+ that stage BY NAME (no fallback -- a missing target must NOT mislink to the final stage); otherwise
94
+ the final stage (highest index)."""
95
+ if target:
96
+ rows = writer.ro_query(
97
+ "MATCH (f:File)-[:HAS_STAGE]->(st:BuildStage) "
98
+ "WHERE f.path = $p AND f.id STARTS WITH $pfx AND st.stage = $t RETURN st.id LIMIT 1",
99
+ {"p": dockerfile, "pfx": f"docker://{proj}/", "t": target},
100
+ ).result_set
101
+ else:
102
+ rows = writer.ro_query(
103
+ "MATCH (f:File)-[:HAS_STAGE]->(st:BuildStage) WHERE f.path = $p AND f.id STARTS WITH $pfx "
104
+ "RETURN st.id ORDER BY st.index DESC LIMIT 1",
105
+ {"p": dockerfile, "pfx": f"docker://{proj}/"},
106
+ ).result_set
107
+ return str(rows[0][0]) if rows else None
@@ -0,0 +1,29 @@
1
+ Metadata-Version: 2.5
2
+ Name: auryn-compose
3
+ Version: 0.8.2
4
+ Summary: Docker Compose plugin for Auryn (deployment & infrastructure tier, ADR 0007). Parses docker-compose files into Service nodes (RUNS_IMAGE the shared Image hub, DEPENDS_ON other services). A `deploy-compose` enrichment links each service that has both `build:` and `image:` to the Dockerfile stage it builds (`build.target`, else the final stage) with BUILDS_IMAGE, marking the image resolved/internal; the stages come from auryn-docker, so install both. Depends on auryn-core and PyYAML.
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
+ Requires-Dist: pyyaml>=6.0
11
+ Description-Content-Type: text/markdown
12
+
13
+ # auryn-compose
14
+
15
+ Docker Compose plugin for Auryn (deployment & infrastructure tier, ADR 0007). Parses docker-compose files into Service nodes (RUNS_IMAGE the shared Image hub, DEPENDS_ON other services). A `deploy-compose` enrichment links each service that has both `build:` and `image:` to the Dockerfile stage it builds (`build.target`, else the final stage) with BUILDS_IMAGE, marking the image resolved/internal; the stages come from auryn-docker, so install both. Depends on auryn-core and PyYAML.
16
+
17
+ Part of [Auryn](https://github.com/FalkorDB/Auryn), which turns a codebase into a queryable knowledge graph for AI agents.
18
+
19
+ ## Install
20
+
21
+ ```bash
22
+ pip install falkordb-auryn # Auryn with every plugin
23
+ pip install "auryn-core[compose]" # Auryn with only this plugin
24
+ pip install "auryn-core[compose,docker]" # + auryn-docker, for the build -> image links
25
+ ```
26
+
27
+ ## License
28
+
29
+ MIT. See the [LICENSE](https://github.com/FalkorDB/Auryn/blob/main/packages/compose/LICENSE).
@@ -0,0 +1,15 @@
1
+ auryn/ingestors/compose/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
2
+ auryn/ingestors/compose/build.py,sha256=xMo6YYKuETDdT5kq_Ypmv_AA69cVvoD55NPx00pfUvU,3770
3
+ auryn/ingestors/compose/enrichment.py,sha256=Jxk1aloU7b_t1qhBAFo2D5anv_HfL4MvY7kWIwRES44,648
4
+ auryn/ingestors/compose/file_parser.py,sha256=qCSv-UMpk2c2OP0a6n0kA5BH-dxI6CcKar02ptYCVr4,3415
5
+ auryn/ingestors/compose/git_sync.py,sha256=kkd4j-X1t6qpDRYkiVAC1elQrZFCUsNEjHadA42Bccc,4356
6
+ auryn/ingestors/compose/ids.py,sha256=fEsEjgpaOKyWqg_3BkNHzXnu37ovkAOGg303dDbKWCg,987
7
+ auryn/ingestors/compose/model.py,sha256=vKXNWvQjjte41hT48uzsyEkC0M9VjR7fZRDCEvhVLcU,931
8
+ auryn/ingestors/compose/plugin.py,sha256=bjjacsX5TMnlIpScdQuUsidRvcvL7uHv-KQPaGmjJPI,1427
9
+ auryn/ingestors/compose/schema.py,sha256=7Goet7YFO1VdALHT_6o02sjl1Pvar5XEoS8QPEJa1pA,1495
10
+ auryn/ingestors/compose/stitch.py,sha256=dU2GNLMDvZnaGexy9jzef-mx9rR0nxOt7iYOCGFbMpA,4837
11
+ auryn_compose-0.8.2.dist-info/METADATA,sha256=dgAHRet4joG4iKDY1OnZct6N3oa_AFRcCFsl-KgwRoo,1752
12
+ auryn_compose-0.8.2.dist-info/WHEEL,sha256=2iZrJkDIkeDh0k9SikKMqFuRP-ua6mb4Ir1AsER4BEw,87
13
+ auryn_compose-0.8.2.dist-info/entry_points.txt,sha256=lkVmc0x9k3VeVirZkhneCMQM6tGojs76rI1II0kjouE,132
14
+ auryn_compose-0.8.2.dist-info/licenses/LICENSE,sha256=MuKfC8-ZgDZVoySTMklxyndvd1_og68pI2gS94re3RI,1065
15
+ auryn_compose-0.8.2.dist-info/RECORD,,
@@ -0,0 +1,4 @@
1
+ Wheel-Version: 1.0
2
+ Generator: hatchling 1.33.0
3
+ Root-Is-Purelib: true
4
+ Tag: py3-none-any
@@ -0,0 +1,5 @@
1
+ [auryn.enrichments]
2
+ deploy-compose = auryn.ingestors.compose.enrichment
3
+
4
+ [auryn.languages]
5
+ compose = auryn.ingestors.compose.plugin
@@ -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.