boatyard 0.8.1.dev240__tar.gz → 0.8.2.dev243__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (85) hide show
  1. {boatyard-0.8.1.dev240 → boatyard-0.8.2.dev243}/AGENTS.md +15 -7
  2. {boatyard-0.8.1.dev240 → boatyard-0.8.2.dev243}/PKG-INFO +1 -1
  3. {boatyard-0.8.1.dev240 → boatyard-0.8.2.dev243}/pyproject.toml +1 -1
  4. {boatyard-0.8.1.dev240 → boatyard-0.8.2.dev243}/src/boatyard/lock.py +13 -5
  5. {boatyard-0.8.1.dev240 → boatyard-0.8.2.dev243}/src/boatyard/models/lock_file.py +2 -0
  6. {boatyard-0.8.1.dev240 → boatyard-0.8.2.dev243}/src/boatyard/models/workload.py +1 -0
  7. {boatyard-0.8.1.dev240 → boatyard-0.8.2.dev243}/src/boatyard/resolve.py +10 -0
  8. boatyard-0.8.2.dev243/src/boatyard/temp.py +17 -0
  9. {boatyard-0.8.1.dev240 → boatyard-0.8.2.dev243}/src/boatyard/verbs/down.py +6 -9
  10. {boatyard-0.8.1.dev240 → boatyard-0.8.2.dev243}/src/boatyard/verbs/up.py +71 -76
  11. {boatyard-0.8.1.dev240 → boatyard-0.8.2.dev243}/tests/test_assembly.py +101 -12
  12. {boatyard-0.8.1.dev240 → boatyard-0.8.2.dev243}/tests/test_compose.py +125 -12
  13. {boatyard-0.8.1.dev240 → boatyard-0.8.2.dev243}/tests/test_lock.py +17 -0
  14. {boatyard-0.8.1.dev240 → boatyard-0.8.2.dev243}/uv.lock +1 -1
  15. boatyard-0.8.1.dev240/src/boatyard/compose.py +0 -38
  16. boatyard-0.8.1.dev240/src/boatyard/temp.py +0 -7
  17. {boatyard-0.8.1.dev240 → boatyard-0.8.2.dev243}/.gitattributes +0 -0
  18. {boatyard-0.8.1.dev240 → boatyard-0.8.2.dev243}/.github/workflows/cleanup-pr-releases.yml +0 -0
  19. {boatyard-0.8.1.dev240 → boatyard-0.8.2.dev243}/.github/workflows/integrate.yml +0 -0
  20. {boatyard-0.8.1.dev240 → boatyard-0.8.2.dev243}/.github/workflows/merge-gate.yml +0 -0
  21. {boatyard-0.8.1.dev240 → boatyard-0.8.2.dev243}/.github/workflows/release.yml +0 -0
  22. {boatyard-0.8.1.dev240 → boatyard-0.8.2.dev243}/.gitignore +0 -0
  23. {boatyard-0.8.1.dev240 → boatyard-0.8.2.dev243}/.python-version +0 -0
  24. {boatyard-0.8.1.dev240 → boatyard-0.8.2.dev243}/CLAUDE.md +0 -0
  25. {boatyard-0.8.1.dev240 → boatyard-0.8.2.dev243}/LICENSE +0 -0
  26. {boatyard-0.8.1.dev240 → boatyard-0.8.2.dev243}/NOTICE +0 -0
  27. {boatyard-0.8.1.dev240 → boatyard-0.8.2.dev243}/README.md +0 -0
  28. {boatyard-0.8.1.dev240 → boatyard-0.8.2.dev243}/design/AGENTS.md +0 -0
  29. {boatyard-0.8.1.dev240 → boatyard-0.8.2.dev243}/design/CLAUDE.md +0 -0
  30. {boatyard-0.8.1.dev240 → boatyard-0.8.2.dev243}/design/apt-hermeticity.md +0 -0
  31. {boatyard-0.8.1.dev240 → boatyard-0.8.2.dev243}/design/mirror-digest-retention.md +0 -0
  32. {boatyard-0.8.1.dev240 → boatyard-0.8.2.dev243}/design/precision-attribution.md +0 -0
  33. {boatyard-0.8.1.dev240 → boatyard-0.8.2.dev243}/design/semver-image-bundle-lines.md +0 -0
  34. {boatyard-0.8.1.dev240 → boatyard-0.8.2.dev243}/publish.yml +0 -0
  35. {boatyard-0.8.1.dev240 → boatyard-0.8.2.dev243}/ruff.base.toml +0 -0
  36. {boatyard-0.8.1.dev240 → boatyard-0.8.2.dev243}/ruff.toml +0 -0
  37. {boatyard-0.8.1.dev240 → boatyard-0.8.2.dev243}/scripts/preflight.py +0 -0
  38. {boatyard-0.8.1.dev240 → boatyard-0.8.2.dev243}/src/boatyard/__init__.py +0 -0
  39. {boatyard-0.8.1.dev240 → boatyard-0.8.2.dev243}/src/boatyard/build.py +0 -0
  40. {boatyard-0.8.1.dev240 → boatyard-0.8.2.dev243}/src/boatyard/cli.py +0 -0
  41. {boatyard-0.8.1.dev240 → boatyard-0.8.2.dev243}/src/boatyard/crane.py +0 -0
  42. {boatyard-0.8.1.dev240 → boatyard-0.8.2.dev243}/src/boatyard/markers.py +0 -0
  43. {boatyard-0.8.1.dev240 → boatyard-0.8.2.dev243}/src/boatyard/models/__init__.py +0 -0
  44. {boatyard-0.8.1.dev240 → boatyard-0.8.2.dev243}/src/boatyard/models/config_file.py +0 -0
  45. {boatyard-0.8.1.dev240 → boatyard-0.8.2.dev243}/src/boatyard/models/image.py +0 -0
  46. {boatyard-0.8.1.dev240 → boatyard-0.8.2.dev243}/src/boatyard/models/k8s_pins.py +0 -0
  47. {boatyard-0.8.1.dev240 → boatyard-0.8.2.dev243}/src/boatyard/models/pyproject.py +0 -0
  48. {boatyard-0.8.1.dev240 → boatyard-0.8.2.dev243}/src/boatyard/models/values_file.py +0 -0
  49. {boatyard-0.8.1.dev240 → boatyard-0.8.2.dev243}/src/boatyard/paths.py +0 -0
  50. {boatyard-0.8.1.dev240 → boatyard-0.8.2.dev243}/src/boatyard/publish.py +0 -0
  51. {boatyard-0.8.1.dev240 → boatyard-0.8.2.dev243}/src/boatyard/py.typed +0 -0
  52. {boatyard-0.8.1.dev240 → boatyard-0.8.2.dev243}/src/boatyard/score.py +0 -0
  53. {boatyard-0.8.1.dev240 → boatyard-0.8.2.dev243}/src/boatyard/score_compose.py +0 -0
  54. {boatyard-0.8.1.dev240 → boatyard-0.8.2.dev243}/src/boatyard/score_generate.py +0 -0
  55. {boatyard-0.8.1.dev240 → boatyard-0.8.2.dev243}/src/boatyard/score_k8s.py +0 -0
  56. {boatyard-0.8.1.dev240 → boatyard-0.8.2.dev243}/src/boatyard/score_patch_templates/gpu-cuda.tpl +0 -0
  57. {boatyard-0.8.1.dev240 → boatyard-0.8.2.dev243}/src/boatyard/score_patch_templates/gpu-pod.tpl +0 -0
  58. {boatyard-0.8.1.dev240 → boatyard-0.8.2.dev243}/src/boatyard/score_patch_templates/gpu-rocm.tpl +0 -0
  59. {boatyard-0.8.1.dev240 → boatyard-0.8.2.dev243}/src/boatyard/score_patch_templates/probe-adapter-healthchecks.tpl +0 -0
  60. {boatyard-0.8.1.dev240 → boatyard-0.8.2.dev243}/src/boatyard/score_patch_templates/restart.tpl +0 -0
  61. {boatyard-0.8.1.dev240 → boatyard-0.8.2.dev243}/src/boatyard/score_patch_templates/scale-to-zero.tpl +0 -0
  62. {boatyard-0.8.1.dev240 → boatyard-0.8.2.dev243}/src/boatyard/verbs/__init__.py +0 -0
  63. {boatyard-0.8.1.dev240 → boatyard-0.8.2.dev243}/src/boatyard/verbs/build.py +0 -0
  64. {boatyard-0.8.1.dev240 → boatyard-0.8.2.dev243}/src/boatyard/verbs/bump.py +0 -0
  65. {boatyard-0.8.1.dev240 → boatyard-0.8.2.dev243}/src/boatyard/verbs/lock.py +0 -0
  66. {boatyard-0.8.1.dev240 → boatyard-0.8.2.dev243}/src/boatyard/verbs/matrix.py +0 -0
  67. {boatyard-0.8.1.dev240 → boatyard-0.8.2.dev243}/src/boatyard/verbs/mirror.py +0 -0
  68. {boatyard-0.8.1.dev240 → boatyard-0.8.2.dev243}/src/boatyard/verbs/publish.py +0 -0
  69. {boatyard-0.8.1.dev240 → boatyard-0.8.2.dev243}/src/boatyard/verbs/score.py +0 -0
  70. {boatyard-0.8.1.dev240 → boatyard-0.8.2.dev243}/src/boatyard/verbs/tree_tags.py +0 -0
  71. {boatyard-0.8.1.dev240 → boatyard-0.8.2.dev243}/src/boatyard/yaml.py +0 -0
  72. {boatyard-0.8.1.dev240 → boatyard-0.8.2.dev243}/tests/conftest.py +0 -0
  73. {boatyard-0.8.1.dev240 → boatyard-0.8.2.dev243}/tests/test_build_docker.py +0 -0
  74. {boatyard-0.8.1.dev240 → boatyard-0.8.2.dev243}/tests/test_bump.py +0 -0
  75. {boatyard-0.8.1.dev240 → boatyard-0.8.2.dev243}/tests/test_config.py +0 -0
  76. {boatyard-0.8.1.dev240 → boatyard-0.8.2.dev243}/tests/test_daemon_gc.py +0 -0
  77. {boatyard-0.8.1.dev240 → boatyard-0.8.2.dev243}/tests/test_image_builds.py +0 -0
  78. {boatyard-0.8.1.dev240 → boatyard-0.8.2.dev243}/tests/test_markers.py +0 -0
  79. {boatyard-0.8.1.dev240 → boatyard-0.8.2.dev243}/tests/test_matrix.py +0 -0
  80. {boatyard-0.8.1.dev240 → boatyard-0.8.2.dev243}/tests/test_mirror.py +0 -0
  81. {boatyard-0.8.1.dev240 → boatyard-0.8.2.dev243}/tests/test_provisioners.py +0 -0
  82. {boatyard-0.8.1.dev240 → boatyard-0.8.2.dev243}/tests/test_publish_compose.py +0 -0
  83. {boatyard-0.8.1.dev240 → boatyard-0.8.2.dev243}/tests/test_score_generate.py +0 -0
  84. {boatyard-0.8.1.dev240 → boatyard-0.8.2.dev243}/tests/test_tree_tags.py +0 -0
  85. {boatyard-0.8.1.dev240 → boatyard-0.8.2.dev243}/tests/test_values.py +0 -0
@@ -49,8 +49,12 @@ Design intent and silent-failure traps, one fact per bullet.
49
49
  - Plain score-compose silently drops `httpGet` probes; boatyard's lens makes the omission loud
50
50
  instead via the workload's `boatyard/probe-adapter` annotation.
51
51
  - Substrate needs live in workload files as `boatyard/*` annotations — `boatyard.yml`
52
- holds no per-workload runtime fact. The shipped `score_patch_templates` are the reader; the
53
- lens is `WorkloadDocument.parse(raw, file_name)`.
52
+ holds no per-workload runtime fact. The gpu annotation (`"true"`) is substrate only
53
+ and the patch templates are its reader; start behavior is a separate annotation —
54
+ `boatyard/autostart: "false"` leaves the container created-stopped instead of
55
+ started by `up`, on any service, gpu or not, recorded in the bundle records as
56
+ held services (lock-time for remote bundles, resolve-time for local and override
57
+ bundles). The lens is `WorkloadDocument.parse(raw, file_name)`.
54
58
 
55
59
  ## Commands
56
60
 
@@ -97,9 +101,10 @@ Quick loop: `uv run pytest`, `uv run ruff check`. Full gate:
97
101
  the compose-surface probe-adapter check, plus provisioner-file selection.
98
102
  - `models/image.py` — the image and local-base models, the Dockerfile parse, and the tree-tag
99
103
  sha machinery.
100
- - `resolve.py` — the `resolve(config, lock, values)` fold answering the assembly plan `up` renders.
101
- - `lock.py` — relock engine + crane resolution.
102
- - `compose.py` — the compose invocation spelling.
104
+ - `resolve.py` — the `resolve(config, lock, values)` fold answering the assembly plan
105
+ `up` renders; the plan carries the config and every consumed bundle record.
106
+ - `lock.py` — relock engine, crane resolution, and the one bundle-record extraction
107
+ every consumer of bundle facts reads through.
103
108
  - `build.py` — build pipeline.
104
109
  - `markers.py` — provisioner and chart-value marker resolution.
105
110
  - `score.py` / `score_compose.py` / `score_k8s.py` / `score_generate.py` — shared base / compose
@@ -107,10 +112,13 @@ Quick loop: `uv run pytest`, `uv run ruff check`. Full gate:
107
112
  - `publish.py` — publish preparation.
108
113
  - `crane.py` — pinned crane installer.
109
114
  - `paths.py` — consumer-repo document paths.
110
- - `temp.py` — shared digest/platform/tree-tag regex spellings.
115
+ - `temp.py` — shared digest/platform/tree-tag regex spellings and the platform quoting
116
+ helper for bashrun command tokens.
111
117
  - `yaml.py` — strict YAML load + model load; `Yaml` and the `is_mapping`/`is_list` guards.
112
118
  - `verbs/up.py` — per-bundle compose projects plus the gateway project over the shared
113
- network, the override documents, the per-run dotenv, unwind on failure.
119
+ network, the override documents, the per-run dotenv, create-stopped then a selective
120
+ start that skips the plan's held services, unwind on failure; no bundle text is
121
+ parsed here — every record rides the plan.
114
122
 
115
123
  ## This file
116
124
 
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.5
2
2
  Name: boatyard
3
- Version: 0.8.1.dev240
3
+ Version: 0.8.2.dev243
4
4
  Summary: Deploy-files definition language and compiler, plus a runtime for the compose target
5
5
  License-File: LICENSE
6
6
  License-File: NOTICE
@@ -1,6 +1,6 @@
1
1
  [project]
2
2
  name = "boatyard"
3
- version = "0.8.1.dev240"
3
+ version = "0.8.2.dev243"
4
4
  description = "Deploy-files definition language and compiler, plus a runtime for the compose target"
5
5
  requires-python = ">=3.13"
6
6
  dependencies = [
@@ -31,6 +31,7 @@ from boatyard.models.lock_file import (
31
31
  refuse_local_lock_entries,
32
32
  )
33
33
  from boatyard.models.workload import (
34
+ AUTOSTART_ANNOTATION,
34
35
  PUBLISH_PORT_ANNOTATION,
35
36
  ROUTE_ANNOTATION,
36
37
  parse_publish_port_annotation,
@@ -102,6 +103,7 @@ class BundleRecords(NamedTuple):
102
103
  routes: list[Route]
103
104
  ports: list[PublishedPort]
104
105
  container_names: list[str]
106
+ held_services: list[str]
105
107
  declared_ports: dict[str, list[tuple[int, int, str]]]
106
108
 
107
109
 
@@ -140,6 +142,8 @@ def relock(config: ConfigFile, *, upgrade: bool = False, check: bool = False) ->
140
142
  routes=records.routes,
141
143
  ports=records.ports,
142
144
  container_names=records.container_names,
145
+ held_services=records.held_services,
146
+ declared_ports=records.declared_ports,
143
147
  )
144
148
 
145
149
  # Refuse committed entries for local base_images keys
@@ -258,6 +262,7 @@ def extract_bundle_records(texts: list[str]) -> BundleRecords:
258
262
  # Collect every stanza before any reference is checked
259
263
  services: list[str] = []
260
264
  container_names: set[str] = set()
265
+ held_services: set[str] = set()
261
266
  declared_ports: dict[str, list[tuple[int, int, str]]] = {}
262
267
  stanzas: list[tuple[str, Yaml, dict[str, str]]] = []
263
268
  for text in texts:
@@ -274,13 +279,15 @@ def extract_bundle_records(texts: list[str]) -> BundleRecords:
274
279
  if "container_name" in stanza:
275
280
  container_names.add(service_name)
276
281
  _collect_declared_ports(declared_ports, service_name, stanza.get("ports"))
277
- stanzas.append((service_name, stanza, _stanza_annotations(stanza)))
282
+ stanzas.append((service_name, stanza, stanza_annotations(stanza)))
278
283
 
279
284
  # Read the routes and ports from the annotations
280
285
  routes: list[Route] = []
281
286
  ports: list[PublishedPort] = []
282
- for service_name, _stanza, stanza_annotations in stanzas:
283
- route_value = stanza_annotations.get(ROUTE_ANNOTATION)
287
+ for service_name, _stanza, service_annotations in stanzas:
288
+ if service_annotations.get(AUTOSTART_ANNOTATION) == "false":
289
+ held_services.add(service_name)
290
+ route_value = service_annotations.get(ROUTE_ANNOTATION)
284
291
  if route_value is not None:
285
292
  for route in parse_route_annotation(route_value):
286
293
  upstream = route.upstream.partition(":")[0]
@@ -290,7 +297,7 @@ def extract_bundle_records(texts: list[str]) -> BundleRecords:
290
297
  f"which the bundle defines no stanza for"
291
298
  )
292
299
  routes.append(Route(path=route.path, upstream=route.upstream, strip_prefix=route.strip_prefix))
293
- publish_value = stanza_annotations.get(PUBLISH_PORT_ANNOTATION)
300
+ publish_value = service_annotations.get(PUBLISH_PORT_ANNOTATION)
294
301
  if publish_value is not None:
295
302
  ports.extend(
296
303
  PublishedPort(
@@ -306,11 +313,12 @@ def extract_bundle_records(texts: list[str]) -> BundleRecords:
306
313
  routes=routes,
307
314
  ports=ports,
308
315
  container_names=sorted(container_names),
316
+ held_services=sorted(held_services),
309
317
  declared_ports=declared_ports,
310
318
  )
311
319
 
312
320
 
313
- def _stanza_annotations(stanza: dict[str, Yaml]) -> dict[str, str]:
321
+ def stanza_annotations(stanza: dict[str, Yaml]) -> dict[str, str]:
314
322
  annotations: dict[str, str] = {}
315
323
  for key in ("annotations", "labels"):
316
324
  value = stanza.get(key)
@@ -150,6 +150,8 @@ class ConfigLockBundle(BaseModel):
150
150
  routes: list[Route]
151
151
  ports: list[PublishedPort]
152
152
  container_names: list[str]
153
+ held_services: list[str] = Field(default_factory=list)
154
+ declared_ports: dict[str, list[tuple[int, int, str]]] = Field(default_factory=dict)
153
155
 
154
156
  @model_validator(mode="after")
155
157
  def _require_digest_pin(self, info: ValidationInfo) -> Self:
@@ -17,6 +17,7 @@ RESTART_ANNOTATION = "boatyard/restart"
17
17
  COMPOSE_RESTART_POLICIES = ("no", "always", "on-failure", "unless-stopped")
18
18
  CONSUMER_INTERPOLATED_ANNOTATION = "boatyard/consumer-interpolated"
19
19
  DOCKERFILE_ANNOTATION = "boatyard/dockerfile"
20
+ AUTOSTART_ANNOTATION = "boatyard/autostart"
20
21
  LOCK_ANNOTATION = "boatyard/lock"
21
22
  ROUTE_ANNOTATION = "boatyard/route"
22
23
  PUBLISH_PORT_ANNOTATION = "boatyard/publish-port"
@@ -47,6 +47,8 @@ class BundleProject(NamedTuple):
47
47
  effective_routes: list[Route]
48
48
  effective_ports: list[PublishedPort]
49
49
  container_names: list[str]
50
+ held_services: list[str]
51
+ declared_ports: dict[str, list[tuple[int, int, str]]]
50
52
 
51
53
 
52
54
  class PublicFace(NamedTuple):
@@ -63,6 +65,7 @@ class GatewayPlan(NamedTuple):
63
65
 
64
66
 
65
67
  class AssemblyPlan(NamedTuple):
68
+ config: ConfigFile
66
69
  bundles: list[BundleProject]
67
70
  gateway: GatewayPlan | None
68
71
  env: dict[str, str]
@@ -176,6 +179,8 @@ def resolve(config: ConfigFile, lock: LockFile, values: ValuesFile) -> AssemblyP
176
179
  adopted_routes = list(locked.routes)
177
180
  adopted_ports = list(locked.ports)
178
181
  adopted_container_names = list(locked.container_names)
182
+ adopted_held_services = list(locked.held_services)
183
+ adopted_declared_ports = dict(locked.declared_ports)
179
184
  bundle_path = None
180
185
  pinned_reference = locked.reference
181
186
  else:
@@ -185,6 +190,8 @@ def resolve(config: ConfigFile, lock: LockFile, values: ValuesFile) -> AssemblyP
185
190
  adopted_routes = records.routes
186
191
  adopted_ports = records.ports
187
192
  adopted_container_names = records.container_names
193
+ adopted_held_services = records.held_services
194
+ adopted_declared_ports = records.declared_ports
188
195
  bundle_path = paths[name]
189
196
  pinned_reference = None
190
197
 
@@ -202,6 +209,8 @@ def resolve(config: ConfigFile, lock: LockFile, values: ValuesFile) -> AssemblyP
202
209
  effective_routes=effective_routes,
203
210
  effective_ports=effective_ports,
204
211
  container_names=adopted_container_names,
212
+ held_services=adopted_held_services,
213
+ declared_ports=adopted_declared_ports,
205
214
  )
206
215
  )
207
216
 
@@ -348,6 +357,7 @@ def resolve(config: ConfigFile, lock: LockFile, values: ValuesFile) -> AssemblyP
348
357
  )
349
358
 
350
359
  return AssemblyPlan(
360
+ config=config,
351
361
  bundles=bundles,
352
362
  gateway=gateway,
353
363
  env=env,
@@ -0,0 +1,17 @@
1
+ import re
2
+ import shlex
3
+ import sys
4
+
5
+ PLATFORM_PATTERN = re.compile(r"^[a-z0-9][a-z0-9-]*/[a-z0-9][a-z0-9-]*$")
6
+
7
+ SHA256_DIGEST_REGEX = r"sha256:[a-f0-9]{64}"
8
+
9
+ TREE_TAG_REGEX = r"tree-[0-9a-f]{40}"
10
+
11
+
12
+ def quote_command_token(value: str) -> str:
13
+ # bashrun splits the command without posix quoting on Windows, where
14
+ # shlex.quote's single quotes would ride the argument literally.
15
+ if sys.platform == "win32":
16
+ return value
17
+ return shlex.quote(value)
@@ -6,9 +6,9 @@ from typing import Annotated
6
6
  import typer
7
7
  from bashrun.bash import bash, bash_check
8
8
 
9
- from boatyard.compose import compose_command
10
9
  from boatyard.models.config_file import ConfigFile
11
10
  from boatyard.paths import DEFAULT_CONFIG_PATH
11
+ from boatyard.temp import quote_command_token
12
12
 
13
13
  app = typer.Typer()
14
14
 
@@ -23,16 +23,13 @@ def down(
23
23
  # Config only: every declared entry names a candidate project, selected or not, and the
24
24
  # bare project name also removes any legacy single-project assembly.
25
25
  candidates = [*(f"{config.project_name}-{row.name}" for row in config.service_entries), config.project_name]
26
+ # Project and entry names match ^[a-z][a-z0-9-]*$; only the directory needs quoting
27
+ project_directory = quote_command_token(str(root))
28
+ volumes_argument = " -v" if volumes else ""
26
29
  for candidate in candidates:
27
30
  bash(
28
- compose_command(
29
- root,
30
- [],
31
- "down",
32
- "--remove-orphans",
33
- *(["-v"] if volumes else []),
34
- project_name=candidate,
35
- )
31
+ f"docker compose -p {candidate} --project-directory {project_directory} "
32
+ f"down --remove-orphans{volumes_argument}"
36
33
  )
37
34
 
38
35
  # The shared network comes down last, after every project that could attach to it
@@ -1,6 +1,7 @@
1
1
  from __future__ import annotations
2
2
 
3
3
  import re
4
+ import sys
4
5
  from collections.abc import Mapping
5
6
  from pathlib import Path
6
7
  from tempfile import NamedTemporaryFile
@@ -11,9 +12,8 @@ import yaml
11
12
  from bashrun.bash import CalledProcessError, bash, bash_check
12
13
 
13
14
  from boatyard.build import run_build
14
- from boatyard.compose import compose_command
15
15
  from boatyard.crane import install_crane
16
- from boatyard.lock import OciArtifactManifest, extract_bundle_records
16
+ from boatyard.lock import OciArtifactManifest
17
17
  from boatyard.models.config_file import (
18
18
  EDGE_IMAGE,
19
19
  EDGE_LISTEN_PORT,
@@ -26,6 +26,7 @@ from boatyard.models.lock_file import LockFile
26
26
  from boatyard.models.values_file import ValuesFile
27
27
  from boatyard.paths import DEFAULT_CONFIG_PATH, LOCK_PATH, VALUES_FILE
28
28
  from boatyard.resolve import AssemblyPlan, BundleProject, GatewayPlan, resolve
29
+ from boatyard.temp import quote_command_token
29
30
  from boatyard.yaml import Yaml
30
31
 
31
32
  # Name the gateway's Caddyfile configs key
@@ -36,13 +37,8 @@ app = typer.Typer()
36
37
 
37
38
  class BundleInvocation(NamedTuple):
38
39
  bundle: BundleProject
39
- compose_files: list[Path]
40
-
41
-
42
- class UpContext(NamedTuple):
43
- env_file: Path
44
- invocations: list[BundleInvocation]
45
- gateway_file: Path | None
40
+ bundle_files: list[Path]
41
+ override_file: Path
46
42
 
47
43
 
48
44
  @app.command()
@@ -68,20 +64,10 @@ def up(
68
64
 
69
65
  # Resolve the assembly plan
70
66
  plan = resolve(config, lock, config_values)
71
- auth_entries = {row.name for row in config.service_entries if row.auth}
72
- shared_network_name = f"{config.project_name}-shared"
73
67
  materialized: list[Path] = []
74
68
 
75
69
  try:
76
- up_context = _materialize_up(config, config_values, plan, auth_entries, shared_network_name, materialized)
77
- _orchestrate_up(
78
- root,
79
- config,
80
- plan,
81
- up_context,
82
- quiet_pull=quiet_pull,
83
- build=build,
84
- )
70
+ _orchestrate_up(plan, config_values, materialized, quiet_pull=quiet_pull, build=build)
85
71
  except CalledProcessError as error:
86
72
  # Exit naming the failing project, keeping the artifacts
87
73
  raise SystemExit(_retained_report(_failing_project(error), materialized)) from None
@@ -95,14 +81,18 @@ def up(
95
81
  path.unlink(missing_ok=True)
96
82
 
97
83
 
98
- def _materialize_up(
99
- config: ConfigFile,
100
- config_values: ValuesFile,
84
+ def _orchestrate_up(
101
85
  plan: AssemblyPlan,
102
- auth_entries: set[str],
103
- shared_network_name: str,
86
+ values: ValuesFile,
104
87
  materialized: list[Path],
105
- ) -> UpContext:
88
+ *,
89
+ quiet_pull: bool,
90
+ build: bool,
91
+ ) -> None:
92
+ config = plan.config
93
+ auth_entries = {row.name for row in config.service_entries if row.auth}
94
+ shared_network_name = f"{config.project_name}-shared"
95
+
106
96
  # Materialize the env file every invocation shares
107
97
  with NamedTemporaryFile(
108
98
  "w", suffix=".env", prefix="boatyard-env-", delete=False, encoding="utf-8", newline="\n"
@@ -116,7 +106,7 @@ def _materialize_up(
116
106
  _materialize(
117
107
  materialized,
118
108
  "boatyard-gateway-",
119
- render_gateway_document(config.project_name, shared_network_name, plan, auth_entries),
109
+ render_gateway_document(plan, auth_entries),
120
110
  )
121
111
  if plan.gateway is not None
122
112
  else None
@@ -128,67 +118,75 @@ def _materialize_up(
128
118
  # If the bundle is local, read its committed compose file
129
119
  if bundle.bundle_path is not None:
130
120
  compose_files = [bundle.bundle_path]
131
- declared_ports = extract_bundle_records([bundle.bundle_path.read_text(encoding="utf-8")]).declared_ports
132
121
  else:
133
- # Otherwise fetch the remote bundle's texts via crane
122
+ # Fetch the remote bundle's texts via crane
134
123
  install_crane()
135
124
  texts = OciArtifactManifest.fetch_compose_texts(bundle.pinned_reference or "")
136
125
  compose_files = [_materialize(materialized, "boatyard-bundle-", text) for text in texts]
137
- declared_ports = extract_bundle_records(texts).declared_ports
138
126
  override_file = _materialize(
139
127
  materialized,
140
128
  "boatyard-override-",
141
- render_override_document(shared_network_name, bundle, config_values, declared_ports),
129
+ render_override_document(shared_network_name, bundle, values, bundle.declared_ports),
142
130
  )
143
- invocations.append(BundleInvocation(bundle=bundle, compose_files=[*compose_files, override_file]))
144
- return UpContext(env_file=env_file, invocations=invocations, gateway_file=gateway_file)
145
-
131
+ invocations.append(BundleInvocation(bundle=bundle, bundle_files=compose_files, override_file=override_file))
146
132
 
147
- def _orchestrate_up(
148
- root: Path,
149
- config: ConfigFile,
150
- plan: AssemblyPlan,
151
- up_context: UpContext,
152
- *,
153
- quiet_pull: bool,
154
- build: bool,
155
- ) -> None:
156
133
  # If any project exists, create the shared network first
157
- if up_context.invocations or up_context.gateway_file is not None:
134
+ if invocations or gateway_file is not None:
158
135
  # If the network does not exist, create it
159
- if not bash_check(f"docker network inspect {config.project_name}-shared"):
160
- bash(f"docker network create {config.project_name}-shared")
136
+ if not bash_check(f"docker network inspect {shared_network_name}"):
137
+ bash(f"docker network create {shared_network_name}")
161
138
 
162
139
  # If build is set, build the local images first
163
140
  if build:
164
141
  run_build(config=config)
165
142
 
166
- # Bring every bundle up as its own project, then the gateway project last
167
- up_arguments = ["up", "--pull", "missing", *(["--quiet-pull"] if quiet_pull else []), "-d"]
168
- for invocation in up_context.invocations:
169
- bash(
170
- compose_command(
171
- root,
172
- invocation.compose_files,
173
- *up_arguments,
174
- project_name=invocation.bundle.project_name,
175
- env_file=up_context.env_file,
176
- slot_names=list(plan.env),
177
- )
143
+ # Create every bundle stopped, then start everything but held services
144
+ pull_arguments = ["--pull", "missing", *(["--quiet-pull"] if quiet_pull else [])]
145
+ for invocation in invocations:
146
+ # Leave held services out of the start step
147
+ command_files = [*invocation.bundle_files, invocation.override_file]
148
+ _run_compose(
149
+ plan,
150
+ env_file,
151
+ command_files,
152
+ invocation.bundle.project_name,
153
+ ["up", *pull_arguments, "-d", "--no-start"],
178
154
  )
179
-
180
- # If a gateway is declared, bring it up last
181
- if up_context.gateway_file is not None:
182
- bash(
183
- compose_command(
184
- root,
185
- [up_context.gateway_file],
186
- *up_arguments,
187
- project_name=config.project_name,
188
- env_file=up_context.env_file,
189
- slot_names=list(plan.env),
155
+ started = sorted(set(invocation.bundle.services) - set(invocation.bundle.held_services))
156
+ if started:
157
+ _run_compose(
158
+ plan,
159
+ env_file,
160
+ command_files,
161
+ invocation.bundle.project_name,
162
+ ["start", *started],
190
163
  )
191
- )
164
+
165
+ # If a gateway is declared, bring it up one-shot; boatyard renders carry no annotations
166
+ if gateway_file is not None:
167
+ _run_compose(plan, env_file, [gateway_file], config.project_name, ["up", *pull_arguments, "-d"])
168
+
169
+
170
+ def _run_compose(
171
+ plan: AssemblyPlan,
172
+ env_file: Path,
173
+ compose_files: list[Path],
174
+ project_name: str,
175
+ arguments: list[str],
176
+ ) -> None:
177
+ # Spell the one compose invocation; the scrub defeats env-file precedence
178
+ root = plan.config.root
179
+ quoted_arguments = [quote_command_token(argument) for argument in arguments]
180
+ files_argument = "".join(f" -f {quote_command_token(str(compose_file))}" for compose_file in compose_files)
181
+ scrub = "".join(f" -u {quote_command_token(name)}" for name in sorted(set(plan.env)))
182
+ prefix = (
183
+ f"docker compose -p {quote_command_token(project_name)}{files_argument} "
184
+ f"--project-directory {quote_command_token(str(root))} --env-file {quote_command_token(str(env_file))}"
185
+ )
186
+ # If not on Windows, prefix the env scrub
187
+ if scrub and sys.platform != "win32":
188
+ prefix = f"env{scrub} {prefix}"
189
+ bash(" ".join([prefix, *quoted_arguments]))
192
190
 
193
191
 
194
192
  def _materialize(materialized: list[Path], prefix: str, text: str) -> Path:
@@ -267,13 +265,10 @@ def _port_entry(port: PublishedPort) -> str:
267
265
  return "{" + ", ".join(fields) + "}"
268
266
 
269
267
 
270
- def render_gateway_document(
271
- project_name: str,
272
- shared_network_name: str,
273
- plan: AssemblyPlan,
274
- auth_entries: set[str],
275
- ) -> str:
268
+ def render_gateway_document(plan: AssemblyPlan, auth_entries: set[str]) -> str:
276
269
  gateway = _require_gateway(plan)
270
+ project_name = plan.config.project_name
271
+ shared_network_name = f"{project_name}-shared"
277
272
 
278
273
  # If an auth option is selected without a public face, refuse
279
274
  if any(bundle.entry_name in auth_entries for bundle in plan.bundles) and gateway.public_face is None:
@@ -46,25 +46,36 @@ class StubArtifacts:
46
46
 
47
47
  class UpSpy:
48
48
  # Captures the per-project invocations: command order, project names, the shared env file
49
- # content, the gateway document, and each bundle's override document.
49
+ # content, the gateway document, and each bundle's override document. A bundle lands as a
50
+ # create-stopped command plus a start command over the same files; the recorded lists hold
51
+ # one entry per project and per document, not one per command.
50
52
  def __init__(self) -> None:
51
53
  self.commands: list[str] = []
52
54
  self.projects: list[str] = []
53
55
  self.env_content: str | None = None
54
56
  self.gateway_documents: list[dict[str, Any]] = []
55
57
  self.override_documents: list[dict[str, Any]] = []
58
+ self._recorded_documents: set[Path] = set()
56
59
 
57
60
  def run(self, command: str) -> None:
58
61
  self.commands.append(command)
59
- self.projects.append(command.split(" -p ", 1)[1].split()[0])
62
+ project = command.split(" -p ", 1)[1].split()[0]
63
+ if not self.projects or self.projects[-1] != project:
64
+ self.projects.append(project)
60
65
  env_match = re.search(r"--env-file (\S+)", command)
61
66
  if env_match is not None and self.env_content is None:
62
67
  self.env_content = Path(env_match.group(1)).read_text(encoding="utf-8")
63
68
  gateway_match = re.search(r"-f (\S*boatyard-gateway-\S+\.yaml)", command)
64
69
  if gateway_match is not None:
65
- self.gateway_documents.append(yaml.safe_load(Path(gateway_match.group(1)).read_text(encoding="utf-8")))
70
+ self._record_document(Path(gateway_match.group(1)), self.gateway_documents)
66
71
  for override_match in re.finditer(r"-f (\S*boatyard-override-\S+\.yaml)", command):
67
- self.override_documents.append(_load_override(Path(override_match.group(1)).read_text(encoding="utf-8")))
72
+ self._record_document(Path(override_match.group(1)), self.override_documents)
73
+
74
+ def _record_document(self, path: Path, documents: list[dict[str, Any]]) -> None:
75
+ if path in self._recorded_documents:
76
+ return
77
+ self._recorded_documents.add(path)
78
+ documents.append(_load_override(path.read_text(encoding="utf-8")))
68
79
 
69
80
 
70
81
  def _bash_check_true(_command: str) -> bool:
@@ -436,13 +447,25 @@ class TestOverrideDocument:
436
447
  )
437
448
  declaring = "services:\n livekit:\n image: demo/livekit:1\n ports:\n - 6178:6178\n"
438
449
  (tmp_path / "declared").mkdir()
439
- declared_spy = _up(
450
+ _write_edge_tree(
440
451
  tmp_path / "declared",
441
452
  monkeypatch,
442
453
  [{"path": "/*", "upstream": "livekit:8000"}],
443
454
  entry_ports=ports,
444
- livekit_text=declaring,
445
455
  )
456
+ declared_lock_path = (tmp_path / "declared").joinpath(*LOCK_PATH.parts)
457
+ lock = yaml.safe_load(declared_lock_path.read_text(encoding="utf-8"))
458
+ lock["bundles"]["LIVEKIT_BUNDLE"]["declared_ports"] = {"livekit": [[6178, 6178, "tcp"]]}
459
+ declared_lock_path.write_text(yaml.safe_dump(lock), encoding="utf-8")
460
+ declared_spy = UpSpy()
461
+ monkeypatch.setattr(up, "bash", declared_spy.run)
462
+ monkeypatch.setattr(up, "bash_check", _bash_check_true)
463
+ monkeypatch.setattr(up, "install_crane", lambda: None)
464
+ monkeypatch.setattr(up, "OciArtifactManifest", StubArtifacts({LIVEKIT_PINNED: [declaring]}))
465
+
466
+ result = runner.invoke(app, ["up"])
467
+
468
+ assert result.exit_code == 0, result.output
446
469
 
447
470
  assert spy.override_documents[0]["services"]["livekit"]["ports"] == [
448
471
  {"published": 16178, "target": 6178},
@@ -480,23 +503,89 @@ class TestUpProjects:
480
503
  ) -> None:
481
504
  spy = _up(tmp_path, monkeypatch, [{"path": "/*", "upstream": "livekit:8000"}])
482
505
 
483
- [bundle_command, gateway_command] = spy.commands
484
- assert bundle_command.startswith(
506
+ [bundle_create, bundle_start, gateway_command] = spy.commands
507
+ assert bundle_create.startswith(
508
+ "env -u BOATYARD_BARRIER_IMAGE -u EDGE_BASE_URL -u PUBLIC_HOST -u PUBLIC_PORT -u PUBLIC_SCHEME "
509
+ "-u PUBLIC_URL -u PUBLIC_URL_PATH docker compose -p edge-demo-livekit -f "
510
+ )
511
+ assert "boatyard-bundle-" in bundle_create
512
+ assert "boatyard-override-" in bundle_create
513
+ assert bundle_create.endswith("up --pull missing -d --no-start")
514
+ assert bundle_start.startswith(
485
515
  "env -u BOATYARD_BARRIER_IMAGE -u EDGE_BASE_URL -u PUBLIC_HOST -u PUBLIC_PORT -u PUBLIC_SCHEME "
486
516
  "-u PUBLIC_URL -u PUBLIC_URL_PATH docker compose -p edge-demo-livekit -f "
487
517
  )
488
- assert "boatyard-bundle-" in bundle_command
489
- assert "boatyard-override-" in bundle_command
490
- assert bundle_command.endswith("up --pull missing -d")
518
+ assert bundle_start.endswith("start livekit")
491
519
  assert gateway_command.startswith(
492
520
  "env -u BOATYARD_BARRIER_IMAGE -u EDGE_BASE_URL -u PUBLIC_HOST -u PUBLIC_PORT -u PUBLIC_SCHEME "
493
521
  "-u PUBLIC_URL -u PUBLIC_URL_PATH docker compose -p edge-demo -f "
494
522
  )
495
523
  assert "boatyard-gateway-" in gateway_command
524
+ assert gateway_command.endswith("up --pull missing -d")
496
525
  assert spy.env_content is not None and spy.env_content.startswith(
497
526
  "BOATYARD_BARRIER_IMAGE=docker.io/library/alpine:3.20\nEDGE_BASE_URL="
498
527
  )
499
528
 
529
+ def test_held_services_stay_out_of_the_start_step(self, tmp_path: Path, monkeypatch: pytest.MonkeyPatch) -> None:
530
+ _write_edge_tree(tmp_path, monkeypatch, [{"path": "/*", "upstream": "livekit:8000"}])
531
+ lock = yaml.safe_load((tmp_path / LOCK_PATH).read_text(encoding="utf-8"))
532
+ lock["bundles"]["LIVEKIT_BUNDLE"]["held_services"] = ["livekit"]
533
+ (tmp_path / LOCK_PATH).write_text(yaml.safe_dump(lock), encoding="utf-8")
534
+ spy = UpSpy()
535
+ monkeypatch.setattr(up, "bash", spy.run)
536
+ monkeypatch.setattr(up, "bash_check", _bash_check_true)
537
+ monkeypatch.setattr(up, "install_crane", lambda: None)
538
+ monkeypatch.setattr(up, "OciArtifactManifest", StubArtifacts({LIVEKIT_PINNED: [LIVEKIT_TEXT]}))
539
+
540
+ result = runner.invoke(app, ["up"])
541
+
542
+ assert result.exit_code == 0, result.output
543
+ [bundle_create, gateway_command] = spy.commands
544
+ assert bundle_create.endswith("up --pull missing -d --no-start")
545
+ assert gateway_command.endswith("up --pull missing -d")
546
+
547
+ def test_gpu_annotation_values_do_not_gate_the_start_step(
548
+ self, tmp_path: Path, monkeypatch: pytest.MonkeyPatch
549
+ ) -> None:
550
+ text = "services:\n livekit:\n image: demo/livekit:1\n annotations:\n boatyard/gpu: managed\n"
551
+ spy = _up(tmp_path, monkeypatch, [{"path": "/*", "upstream": "livekit:8000"}], livekit_text=text)
552
+
553
+ [bundle_create, bundle_start, gateway_command] = spy.commands
554
+ assert bundle_create.endswith("up --pull missing -d --no-start")
555
+ assert bundle_start.endswith("start livekit")
556
+ assert gateway_command.endswith("up --pull missing -d")
557
+
558
+ def test_the_start_step_lists_only_the_unheld_services(
559
+ self, tmp_path: Path, monkeypatch: pytest.MonkeyPatch
560
+ ) -> None:
561
+ text = (
562
+ "services:\n"
563
+ " edge:\n"
564
+ " image: demo/edge:1\n"
565
+ " worker:\n"
566
+ " image: demo/worker:1\n"
567
+ " livekit:\n"
568
+ " image: demo/livekit:1\n"
569
+ )
570
+ _write_edge_tree(tmp_path, monkeypatch, [{"path": "/*", "upstream": "livekit:8000"}])
571
+ lock = yaml.safe_load((tmp_path / LOCK_PATH).read_text(encoding="utf-8"))
572
+ lock["bundles"]["LIVEKIT_BUNDLE"]["services"] = ["edge", "worker", "livekit"]
573
+ lock["bundles"]["LIVEKIT_BUNDLE"]["held_services"] = ["worker"]
574
+ (tmp_path / LOCK_PATH).write_text(yaml.safe_dump(lock), encoding="utf-8")
575
+ spy = UpSpy()
576
+ monkeypatch.setattr(up, "bash", spy.run)
577
+ monkeypatch.setattr(up, "bash_check", _bash_check_true)
578
+ monkeypatch.setattr(up, "install_crane", lambda: None)
579
+ monkeypatch.setattr(up, "OciArtifactManifest", StubArtifacts({LIVEKIT_PINNED: [text]}))
580
+
581
+ result = runner.invoke(app, ["up"])
582
+
583
+ assert result.exit_code == 0, result.output
584
+ [bundle_create, bundle_start, gateway_command] = spy.commands
585
+ assert bundle_create.endswith("up --pull missing -d --no-start")
586
+ assert bundle_start.endswith("start edge livekit")
587
+ assert gateway_command.endswith("up --pull missing -d")
588
+
500
589
  def test_a_failing_project_stops_the_run_and_reports_the_retained_artifacts(
501
590
  self, tmp_path: Path, monkeypatch: pytest.MonkeyPatch
502
591
  ) -> None:
@@ -514,7 +603,7 @@ class TestUpProjects:
514
603
  assert result.exit_code != 0
515
604
  assert isinstance(result.exception, SystemExit)
516
605
  report = str(result.exception)
517
- assert "the project edge-demo failed" in report
606
+ assert "the project edge-demo-livekit failed" in report
518
607
  assert "kept artifacts for inspection:" in report
519
608
 
520
609
  def test_zero_selection_renders_the_gateway_project_alone(
@@ -1,12 +1,13 @@
1
1
  import platform
2
2
  import re
3
+ import sys
3
4
  from collections.abc import Mapping
4
5
  from pathlib import Path
5
6
  from typing import Any
6
7
 
7
8
  import pytest
8
9
  import yaml
9
- from bashrun.bash import CalledProcessError, bash, bash_output
10
+ from bashrun.bash import CalledProcessError, bash, bash_check, bash_output
10
11
  from typer.testing import CliRunner
11
12
 
12
13
  from boatyard.cli import app
@@ -73,26 +74,37 @@ class StubArtifacts:
73
74
 
74
75
  class UpSpy:
75
76
  # Captures the per-project invocations: command order, project names, the shared env file
76
- # content, the gateway document, and each bundle's override document.
77
+ # content, the gateway document, and each bundle's override document. A bundle lands as a
78
+ # create-stopped command plus a start command over the same files; the recorded lists hold
79
+ # one entry per project and per document, not one per command.
77
80
  def __init__(self, texts_by_reference: dict[str, list[str]] | None = None) -> None:
78
81
  self.commands: list[str] = []
79
82
  self.projects: list[str] = []
80
83
  self.env_content: str | None = None
81
84
  self.gateway_documents: list[dict[str, Any]] = []
82
85
  self.override_documents: list[dict[str, Any]] = []
86
+ self._recorded_documents: set[Path] = set()
83
87
  self.artifacts = StubArtifacts(texts_by_reference)
84
88
 
85
89
  def run(self, command: str) -> None:
86
90
  self.commands.append(command)
87
- self.projects.append(command.split(" -p ", 1)[1].split()[0])
91
+ project = command.split(" -p ", 1)[1].split()[0]
92
+ if not self.projects or self.projects[-1] != project:
93
+ self.projects.append(project)
88
94
  env_match = LOCK_ENV_ARGUMENT_PATTERN.search(command)
89
95
  if env_match is not None and self.env_content is None:
90
96
  self.env_content = Path(env_match.group(1)).read_text(encoding="utf-8")
91
97
  gateway_match = ASSEMBLY_ARGUMENT_PATTERN.search(command)
92
98
  if gateway_match is not None:
93
- self.gateway_documents.append(yaml.safe_load(Path(gateway_match.group(1)).read_text(encoding="utf-8")))
99
+ self._record_document(Path(gateway_match.group(1)), self.gateway_documents)
94
100
  for override in re.finditer(r"-f (\S*boatyard-override-\S+\.yaml)", command):
95
- self.override_documents.append(yaml.safe_load(Path(override.group(1)).read_text(encoding="utf-8")))
101
+ self._record_document(Path(override.group(1)), self.override_documents)
102
+
103
+ def _record_document(self, path: Path, documents: list[dict[str, Any]]) -> None:
104
+ if path in self._recorded_documents:
105
+ return
106
+ self._recorded_documents.add(path)
107
+ documents.append(yaml.safe_load(path.read_text(encoding="utf-8")))
96
108
 
97
109
  def spy_up(self, monkeypatch: pytest.MonkeyPatch):
98
110
  monkeypatch.setattr(up, "bash", self.run)
@@ -113,20 +125,73 @@ class UpSpy:
113
125
  runner = CliRunner()
114
126
 
115
127
 
116
- @pytest.fixture(scope="session")
117
- def pinned_compose(tmp_path_factory: pytest.TempPathFactory) -> str:
118
- # Pin the exact compose binary the include-merge assertions run against.
128
+ COMPOSE_CACHE_DIRECTORY = Path.home() / ".cache" / "boatyard" / "compose"
129
+
130
+
131
+ def _cached_compose_binary() -> str:
132
+ # The exact compose binary the include-merge assertions run against, cached
133
+ # under ~/.cache/boatyard so one download serves every run. The download
134
+ # lands on a partial name and renames into place only after its version
135
+ # output checks out — a killed or corrupt download never poisons the cache.
119
136
  architecture = {"x86_64": "x86_64", "aarch64": "aarch64"}[platform.machine()]
120
- binary = tmp_path_factory.mktemp("compose-bin") / "docker-compose"
137
+ directory = COMPOSE_CACHE_DIRECTORY / f"v{PINNED_COMPOSE_VERSION}" / architecture
138
+ binary = directory / "docker-compose"
139
+ if binary.is_file() and bash_check(f"{binary} version"):
140
+ return str(binary)
141
+ directory.mkdir(parents=True, exist_ok=True)
142
+ partial = directory / "docker-compose.partial"
121
143
  release = (
122
144
  "https://github.com/docker/compose/releases/download/"
123
145
  f"v{PINNED_COMPOSE_VERSION}/docker-compose-linux-{architecture}"
124
146
  )
125
- bash(f"curl -fsSL {release} -o {binary}")
126
- binary.chmod(0o755)
147
+ bash(f"curl -fsSL {release} -o {partial}")
148
+ partial.chmod(0o755)
149
+ if PINNED_COMPOSE_VERSION not in bash_output(f"{partial} version"):
150
+ raise ValueError(f"{partial}: the downloaded binary does not report version {PINNED_COMPOSE_VERSION}")
151
+ partial.replace(binary)
127
152
  return str(binary)
128
153
 
129
154
 
155
+ @pytest.fixture(scope="session")
156
+ def pinned_compose() -> str:
157
+ return _cached_compose_binary()
158
+
159
+
160
+ def _patch_compose_shell(monkeypatch: pytest.MonkeyPatch, cache: Path, version_output: str | None = None) -> list[str]:
161
+ # Record every shell call _cached_compose_binary makes against a fake cache
162
+ # directory; the curl stub materializes the downloaded file so the promote
163
+ # path runs for real.
164
+ commands: list[str] = []
165
+ resolved_version = (
166
+ version_output if version_output is not None else f"Docker Compose version v{PINNED_COMPOSE_VERSION}\n"
167
+ )
168
+ module = sys.modules[__name__]
169
+
170
+ def record(command: str) -> None:
171
+ commands.append(command)
172
+ if not command.startswith("curl "):
173
+ return
174
+ match = re.search(r"-o (\S+)", command)
175
+ if match is None:
176
+ raise ValueError(f"the curl command carries no -o target: {command}")
177
+ target = Path(match.group(1))
178
+ target.parent.mkdir(parents=True, exist_ok=True)
179
+ target.write_bytes(b"fake-binary")
180
+
181
+ def probe(command: str) -> bool:
182
+ return command.endswith(" version")
183
+
184
+ def output(command: str) -> str:
185
+ commands.append(command)
186
+ return resolved_version
187
+
188
+ monkeypatch.setattr(module, "bash", record)
189
+ monkeypatch.setattr(module, "bash_check", probe)
190
+ monkeypatch.setattr(module, "bash_output", output)
191
+ monkeypatch.setattr(module, "COMPOSE_CACHE_DIRECTORY", cache)
192
+ return commands
193
+
194
+
130
195
  def _write_config(root: Path, sections: dict[str, Any] | None = None) -> None:
131
196
  payload: dict[str, Any] = {"requires": ">=0.0", "project_name": "demo"}
132
197
  if sections is not None:
@@ -1398,7 +1463,13 @@ class TestBundleOverrides:
1398
1463
  "env -u BOATYARD_BARRIER_IMAGE -u EDGE_BASE_URL -u PLACEFRAME_CUDA__BOATYARD_LOCK__ALPINE_IMAGE "
1399
1464
  "-u PLACEFRAME_CUDA__BOATYARD_LOCK__LOKI_IMAGE "
1400
1465
  "docker compose -p demo-placeframe-cuda -f PRODUCER -f OVERRIDE "
1401
- "--project-directory ROOT --env-file LOCKENV up --pull missing -d"
1466
+ "--project-directory ROOT --env-file LOCKENV up --pull missing -d --no-start"
1467
+ ),
1468
+ (
1469
+ "env -u BOATYARD_BARRIER_IMAGE -u EDGE_BASE_URL -u PLACEFRAME_CUDA__BOATYARD_LOCK__ALPINE_IMAGE "
1470
+ "-u PLACEFRAME_CUDA__BOATYARD_LOCK__LOKI_IMAGE "
1471
+ "docker compose -p demo-placeframe-cuda -f PRODUCER -f OVERRIDE "
1472
+ "--project-directory ROOT --env-file LOCKENV start api grafana"
1402
1473
  ),
1403
1474
  (
1404
1475
  "env -u BOATYARD_BARRIER_IMAGE -u EDGE_BASE_URL -u PLACEFRAME_CUDA__BOATYARD_LOCK__ALPINE_IMAGE "
@@ -1687,6 +1758,48 @@ class TestBundleOverrides:
1687
1758
  )
1688
1759
 
1689
1760
 
1761
+ class TestPinnedComposeCache:
1762
+ def test_a_cached_binary_probes_without_downloading(self, tmp_path: Path, monkeypatch: pytest.MonkeyPatch) -> None:
1763
+ cache = tmp_path / "cache"
1764
+ binary = cache / f"v{PINNED_COMPOSE_VERSION}" / platform.machine() / "docker-compose"
1765
+ binary.parent.mkdir(parents=True)
1766
+ binary.write_bytes(b"fake-binary")
1767
+ commands = _patch_compose_shell(monkeypatch, cache)
1768
+
1769
+ resolved = _cached_compose_binary()
1770
+
1771
+ assert resolved == str(binary)
1772
+ assert commands == []
1773
+
1774
+ def test_a_missing_binary_downloads_validates_and_promotes(
1775
+ self, tmp_path: Path, monkeypatch: pytest.MonkeyPatch
1776
+ ) -> None:
1777
+ cache = tmp_path / "cache"
1778
+ commands = _patch_compose_shell(monkeypatch, cache)
1779
+
1780
+ resolved = _cached_compose_binary()
1781
+
1782
+ binary = cache / f"v{PINNED_COMPOSE_VERSION}" / platform.machine() / "docker-compose"
1783
+ assert resolved == str(binary)
1784
+ assert binary.is_file()
1785
+ assert not (binary.parent / "docker-compose.partial").exists()
1786
+ assert len([command for command in commands if command.startswith("curl ")]) == 1
1787
+
1788
+ def test_a_binary_reporting_the_wrong_version_never_reaches_the_cache(
1789
+ self, tmp_path: Path, monkeypatch: pytest.MonkeyPatch
1790
+ ) -> None:
1791
+ cache = tmp_path / "cache"
1792
+ commands = _patch_compose_shell(monkeypatch, cache, version_output="Docker Compose version v0.0.0\n")
1793
+
1794
+ with pytest.raises(ValueError, match="does not report version"):
1795
+ _cached_compose_binary()
1796
+
1797
+ binary = cache / f"v{PINNED_COMPOSE_VERSION}" / platform.machine() / "docker-compose"
1798
+ assert not binary.exists()
1799
+ assert (binary.parent / "docker-compose.partial").exists()
1800
+ assert len([command for command in commands if command.startswith("curl ")]) == 1
1801
+
1802
+
1690
1803
  class TestComposePortMergeOverIncludes:
1691
1804
  def test_parent_ports_add_to_and_reset_included_ports(self, tmp_path: Path, pinned_compose: str) -> None:
1692
1805
  child = tmp_path / "child.yaml"
@@ -1060,6 +1060,23 @@ def test_extract_bundle_records_collects_declared_ports_in_both_spellings() -> N
1060
1060
  assert records.declared_ports == {"livekit": [(6178, 6178, "tcp"), (5957, 5957, "udp")]}
1061
1061
 
1062
1062
 
1063
+ def test_extract_bundle_records_holds_services_marked_no_autostart() -> None:
1064
+ from boatyard.lock import extract_bundle_records
1065
+
1066
+ text = (
1067
+ "services:\n"
1068
+ " livekit:\n"
1069
+ " image: demo/livekit:1\n"
1070
+ ' annotations:\n boatyard/autostart: "false"\n'
1071
+ " edge:\n"
1072
+ " image: demo/edge:1\n"
1073
+ )
1074
+
1075
+ records = extract_bundle_records([text])
1076
+
1077
+ assert records.held_services == ["livekit"]
1078
+
1079
+
1063
1080
  def _skip_crane_install() -> None:
1064
1081
  return None
1065
1082
 
@@ -43,7 +43,7 @@ wheels = [
43
43
 
44
44
  [[package]]
45
45
  name = "boatyard"
46
- version = "0.8.0"
46
+ version = "0.9.0"
47
47
  source = { editable = "." }
48
48
  dependencies = [
49
49
  { name = "bashrun" },
@@ -1,38 +0,0 @@
1
- from __future__ import annotations
2
-
3
- import shlex
4
- import sys
5
- from collections.abc import Iterable
6
- from pathlib import Path
7
-
8
-
9
- def compose_command(
10
- root: Path,
11
- compose_files: list[Path],
12
- *arguments: str,
13
- project_name: str,
14
- env_file: Path | None = None,
15
- slot_names: Iterable[str] = (),
16
- ) -> str:
17
- # Spell the one docker compose invocation; the env -u scrub defeats compose's
18
- # shell-beats-env-file precedence for every slot name.
19
- quoted_arguments = [_quote(argument) for argument in arguments]
20
- files_argument = "".join(f" -f {_quote(str(compose_file))}" for compose_file in compose_files)
21
- env_argument = f" --env-file {_quote(str(env_file))}" if env_file is not None else ""
22
- scrub = "".join(f" -u {_quote(name)}" for name in sorted(set(slot_names)))
23
- prefix = (
24
- f"docker compose -p {_quote(project_name)}{files_argument} "
25
- f"--project-directory {_quote(str(root))}{env_argument}"
26
- )
27
- # Windows ships no env utility; the scrub stays the POSIX spelling of the guard.
28
- if scrub and sys.platform != "win32":
29
- prefix = f"env{scrub} " + prefix
30
- return " ".join([prefix, *quoted_arguments])
31
-
32
-
33
- def _quote(value: str) -> str:
34
- # bashrun splits the command without posix quoting on Windows, where shlex.quote's
35
- # single quotes would ride the argument literally.
36
- if sys.platform == "win32":
37
- return value
38
- return shlex.quote(value)
@@ -1,7 +0,0 @@
1
- import re
2
-
3
- PLATFORM_PATTERN = re.compile(r"^[a-z0-9][a-z0-9-]*/[a-z0-9][a-z0-9-]*$")
4
-
5
- SHA256_DIGEST_REGEX = r"sha256:[a-f0-9]{64}"
6
-
7
- TREE_TAG_REGEX = r"tree-[0-9a-f]{40}"
File without changes
File without changes