boatyard 0.9.4.dev258__tar.gz → 0.9.5__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 (83) hide show
  1. {boatyard-0.9.4.dev258 → boatyard-0.9.5}/PKG-INFO +1 -1
  2. {boatyard-0.9.4.dev258 → boatyard-0.9.5}/pyproject.toml +1 -1
  3. {boatyard-0.9.4.dev258 → boatyard-0.9.5}/src/boatyard/models/workload.py +33 -0
  4. {boatyard-0.9.4.dev258 → boatyard-0.9.5}/src/boatyard/score.py +64 -7
  5. {boatyard-0.9.4.dev258 → boatyard-0.9.5}/tests/test_score_generate.py +359 -1
  6. {boatyard-0.9.4.dev258 → boatyard-0.9.5}/.gitattributes +0 -0
  7. {boatyard-0.9.4.dev258 → boatyard-0.9.5}/.github/workflows/cleanup-pr-releases.yml +0 -0
  8. {boatyard-0.9.4.dev258 → boatyard-0.9.5}/.github/workflows/integrate.yml +0 -0
  9. {boatyard-0.9.4.dev258 → boatyard-0.9.5}/.github/workflows/merge-gate.yml +0 -0
  10. {boatyard-0.9.4.dev258 → boatyard-0.9.5}/.github/workflows/release.yml +0 -0
  11. {boatyard-0.9.4.dev258 → boatyard-0.9.5}/.gitignore +0 -0
  12. {boatyard-0.9.4.dev258 → boatyard-0.9.5}/.python-version +0 -0
  13. {boatyard-0.9.4.dev258 → boatyard-0.9.5}/AGENTS.md +0 -0
  14. {boatyard-0.9.4.dev258 → boatyard-0.9.5}/CLAUDE.md +0 -0
  15. {boatyard-0.9.4.dev258 → boatyard-0.9.5}/LICENSE +0 -0
  16. {boatyard-0.9.4.dev258 → boatyard-0.9.5}/NOTICE +0 -0
  17. {boatyard-0.9.4.dev258 → boatyard-0.9.5}/README.md +0 -0
  18. {boatyard-0.9.4.dev258 → boatyard-0.9.5}/design/AGENTS.md +0 -0
  19. {boatyard-0.9.4.dev258 → boatyard-0.9.5}/design/CLAUDE.md +0 -0
  20. {boatyard-0.9.4.dev258 → boatyard-0.9.5}/design/apt-hermeticity.md +0 -0
  21. {boatyard-0.9.4.dev258 → boatyard-0.9.5}/design/mirror-digest-retention.md +0 -0
  22. {boatyard-0.9.4.dev258 → boatyard-0.9.5}/design/precision-attribution.md +0 -0
  23. {boatyard-0.9.4.dev258 → boatyard-0.9.5}/design/semver-image-bundle-lines.md +0 -0
  24. {boatyard-0.9.4.dev258 → boatyard-0.9.5}/publish.yml +0 -0
  25. {boatyard-0.9.4.dev258 → boatyard-0.9.5}/ruff.base.toml +0 -0
  26. {boatyard-0.9.4.dev258 → boatyard-0.9.5}/ruff.toml +0 -0
  27. {boatyard-0.9.4.dev258 → boatyard-0.9.5}/scripts/preflight.py +0 -0
  28. {boatyard-0.9.4.dev258 → boatyard-0.9.5}/src/boatyard/__init__.py +0 -0
  29. {boatyard-0.9.4.dev258 → boatyard-0.9.5}/src/boatyard/build.py +0 -0
  30. {boatyard-0.9.4.dev258 → boatyard-0.9.5}/src/boatyard/cli.py +0 -0
  31. {boatyard-0.9.4.dev258 → boatyard-0.9.5}/src/boatyard/crane.py +0 -0
  32. {boatyard-0.9.4.dev258 → boatyard-0.9.5}/src/boatyard/lock.py +0 -0
  33. {boatyard-0.9.4.dev258 → boatyard-0.9.5}/src/boatyard/markers.py +0 -0
  34. {boatyard-0.9.4.dev258 → boatyard-0.9.5}/src/boatyard/models/__init__.py +0 -0
  35. {boatyard-0.9.4.dev258 → boatyard-0.9.5}/src/boatyard/models/config_file.py +0 -0
  36. {boatyard-0.9.4.dev258 → boatyard-0.9.5}/src/boatyard/models/image.py +0 -0
  37. {boatyard-0.9.4.dev258 → boatyard-0.9.5}/src/boatyard/models/k8s_pins.py +0 -0
  38. {boatyard-0.9.4.dev258 → boatyard-0.9.5}/src/boatyard/models/lock_file.py +0 -0
  39. {boatyard-0.9.4.dev258 → boatyard-0.9.5}/src/boatyard/models/pyproject.py +0 -0
  40. {boatyard-0.9.4.dev258 → boatyard-0.9.5}/src/boatyard/models/values_file.py +0 -0
  41. {boatyard-0.9.4.dev258 → boatyard-0.9.5}/src/boatyard/paths.py +0 -0
  42. {boatyard-0.9.4.dev258 → boatyard-0.9.5}/src/boatyard/publish.py +0 -0
  43. {boatyard-0.9.4.dev258 → boatyard-0.9.5}/src/boatyard/py.typed +0 -0
  44. {boatyard-0.9.4.dev258 → boatyard-0.9.5}/src/boatyard/resolve.py +0 -0
  45. {boatyard-0.9.4.dev258 → boatyard-0.9.5}/src/boatyard/score_compose.py +0 -0
  46. {boatyard-0.9.4.dev258 → boatyard-0.9.5}/src/boatyard/score_generate.py +0 -0
  47. {boatyard-0.9.4.dev258 → boatyard-0.9.5}/src/boatyard/score_k8s.py +0 -0
  48. {boatyard-0.9.4.dev258 → boatyard-0.9.5}/src/boatyard/score_patch_templates/gpu-cuda.tpl +0 -0
  49. {boatyard-0.9.4.dev258 → boatyard-0.9.5}/src/boatyard/score_patch_templates/gpu-pod.tpl +0 -0
  50. {boatyard-0.9.4.dev258 → boatyard-0.9.5}/src/boatyard/score_patch_templates/gpu-rocm.tpl +0 -0
  51. {boatyard-0.9.4.dev258 → boatyard-0.9.5}/src/boatyard/score_patch_templates/probe-adapter-healthchecks.tpl +0 -0
  52. {boatyard-0.9.4.dev258 → boatyard-0.9.5}/src/boatyard/score_patch_templates/restart.tpl +0 -0
  53. {boatyard-0.9.4.dev258 → boatyard-0.9.5}/src/boatyard/score_patch_templates/scale-to-zero.tpl +0 -0
  54. {boatyard-0.9.4.dev258 → boatyard-0.9.5}/src/boatyard/temp.py +0 -0
  55. {boatyard-0.9.4.dev258 → boatyard-0.9.5}/src/boatyard/verbs/__init__.py +0 -0
  56. {boatyard-0.9.4.dev258 → boatyard-0.9.5}/src/boatyard/verbs/build.py +0 -0
  57. {boatyard-0.9.4.dev258 → boatyard-0.9.5}/src/boatyard/verbs/bump.py +0 -0
  58. {boatyard-0.9.4.dev258 → boatyard-0.9.5}/src/boatyard/verbs/down.py +0 -0
  59. {boatyard-0.9.4.dev258 → boatyard-0.9.5}/src/boatyard/verbs/lock.py +0 -0
  60. {boatyard-0.9.4.dev258 → boatyard-0.9.5}/src/boatyard/verbs/matrix.py +0 -0
  61. {boatyard-0.9.4.dev258 → boatyard-0.9.5}/src/boatyard/verbs/mirror.py +0 -0
  62. {boatyard-0.9.4.dev258 → boatyard-0.9.5}/src/boatyard/verbs/publish.py +0 -0
  63. {boatyard-0.9.4.dev258 → boatyard-0.9.5}/src/boatyard/verbs/score.py +0 -0
  64. {boatyard-0.9.4.dev258 → boatyard-0.9.5}/src/boatyard/verbs/tree_tags.py +0 -0
  65. {boatyard-0.9.4.dev258 → boatyard-0.9.5}/src/boatyard/verbs/up.py +0 -0
  66. {boatyard-0.9.4.dev258 → boatyard-0.9.5}/src/boatyard/yaml.py +0 -0
  67. {boatyard-0.9.4.dev258 → boatyard-0.9.5}/tests/conftest.py +0 -0
  68. {boatyard-0.9.4.dev258 → boatyard-0.9.5}/tests/test_assembly.py +0 -0
  69. {boatyard-0.9.4.dev258 → boatyard-0.9.5}/tests/test_build_docker.py +0 -0
  70. {boatyard-0.9.4.dev258 → boatyard-0.9.5}/tests/test_bump.py +0 -0
  71. {boatyard-0.9.4.dev258 → boatyard-0.9.5}/tests/test_compose.py +0 -0
  72. {boatyard-0.9.4.dev258 → boatyard-0.9.5}/tests/test_config.py +0 -0
  73. {boatyard-0.9.4.dev258 → boatyard-0.9.5}/tests/test_daemon_gc.py +0 -0
  74. {boatyard-0.9.4.dev258 → boatyard-0.9.5}/tests/test_image_builds.py +0 -0
  75. {boatyard-0.9.4.dev258 → boatyard-0.9.5}/tests/test_lock.py +0 -0
  76. {boatyard-0.9.4.dev258 → boatyard-0.9.5}/tests/test_markers.py +0 -0
  77. {boatyard-0.9.4.dev258 → boatyard-0.9.5}/tests/test_matrix.py +0 -0
  78. {boatyard-0.9.4.dev258 → boatyard-0.9.5}/tests/test_mirror.py +0 -0
  79. {boatyard-0.9.4.dev258 → boatyard-0.9.5}/tests/test_provisioners.py +0 -0
  80. {boatyard-0.9.4.dev258 → boatyard-0.9.5}/tests/test_publish_compose.py +0 -0
  81. {boatyard-0.9.4.dev258 → boatyard-0.9.5}/tests/test_tree_tags.py +0 -0
  82. {boatyard-0.9.4.dev258 → boatyard-0.9.5}/tests/test_values.py +0 -0
  83. {boatyard-0.9.4.dev258 → boatyard-0.9.5}/uv.lock +0 -0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.5
2
2
  Name: boatyard
3
- Version: 0.9.4.dev258
3
+ Version: 0.9.5
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.9.4.dev258"
3
+ version = "0.9.5"
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 = [
@@ -28,6 +28,10 @@ ROUTE_PATH_PATTERN = re.compile(r"(?:/\*|/(?:[^/\s*]+(?:/[^/\s*]+)*)?(?:/\*)?)")
28
28
 
29
29
  ROUTE_PORT_NAME_PATTERN = re.compile(r"[a-zA-Z0-9][a-zA-Z0-9_.-]*")
30
30
 
31
+ LISTENER_REFERENCE_PREFIX = "${listeners."
32
+
33
+ LISTENER_PORT_LOOKUP = "port"
34
+
31
35
  ROUTE_PATH_EXPORT_SUFFIX = "ROUTE_PATH"
32
36
 
33
37
  PUBLISH_PORT_PROTOCOLS: tuple[Literal["tcp", "udp"], ...] = ("tcp", "udp")
@@ -101,6 +105,25 @@ class WorkloadDocument(BaseModel):
101
105
  f"a {CONTAINER_PORTS_ANNOTATION} listener"
102
106
  )
103
107
 
108
+ variables = container.model_extra.get("variables") if container.model_extra is not None else None
109
+ if not is_mapping(variables):
110
+ continue
111
+ for key, value in variables.items():
112
+ if not isinstance(value, str) or not value.startswith(LISTENER_REFERENCE_PREFIX):
113
+ continue
114
+ listener = listener_port_reference(value)
115
+ if listener is None:
116
+ raise ValueError(
117
+ f"the container {name!r} variables {key} value {value!r} must be "
118
+ f"${{listeners.<listener>.{LISTENER_PORT_LOOKUP}}} naming a service.ports entry "
119
+ f"or a {CONTAINER_PORTS_ANNOTATION} listener"
120
+ )
121
+ if listener not in listeners:
122
+ raise ValueError(
123
+ f"the container {name!r} variables {key} value {value!r} names no declared "
124
+ f"listener ({', '.join(sorted(listeners))})"
125
+ )
126
+
104
127
  publish_port = annotations.get(PUBLISH_PORT_ANNOTATION)
105
128
  if publish_port is not None:
106
129
  parse_publish_port_annotation(publish_port)
@@ -449,6 +472,16 @@ def parse_container_ports_annotation(value: str) -> dict[str, int]:
449
472
  return ports
450
473
 
451
474
 
475
+ def listener_port_reference(value: str) -> str | None:
476
+ # The whole-value grammar ${listeners.<name>.port}; None names any other spelling
477
+ if not value.startswith(LISTENER_REFERENCE_PREFIX) or not value.endswith("}"):
478
+ return None
479
+ name, separator, lookup = value[len(LISTENER_REFERENCE_PREFIX) : -1].partition(".")
480
+ if not separator or not name or lookup != LISTENER_PORT_LOOKUP:
481
+ return None
482
+ return name
483
+
484
+
452
485
  def route_path_export_name(workload_name: str) -> str:
453
486
  return workload_name.upper().replace("-", "_") + "_" + ROUTE_PATH_EXPORT_SUFFIX
454
487
 
@@ -30,6 +30,7 @@ from boatyard.models.workload import (
30
30
  ROUTE_ANNOTATION,
31
31
  ROUTE_PORT_ANNOTATION,
32
32
  LoadedWorkload,
33
+ listener_port_reference,
33
34
  parse_route_annotation,
34
35
  route_path_export_name,
35
36
  select_provisioner_files,
@@ -46,6 +47,8 @@ STRING_FORM_FIELDS = ("state", "outputs", "volumes", "services", "manifests")
46
47
  PROVISIONER_ROUTE_KEY = "route"
47
48
  PROVISIONER_PORT_KEY = "port"
48
49
 
50
+ STATE_TEMPLATE_PATTERN = re.compile(r"\{\{\s*\.State\.([a-zA-Z0-9_.-]+)\s*\}\}")
51
+
49
52
 
50
53
  class AuthoredProvisioner(BaseModel):
51
54
  model_config = ConfigDict(extra="forbid")
@@ -223,11 +226,12 @@ def translate_service_claims(entry: Yaml, source: str) -> Yaml:
223
226
  services_value = entry.get("services")
224
227
  if not is_mapping(services_value):
225
228
  return entry
226
- services = {name: claimed_service_stanza(name, stanza, source) for name, stanza in services_value.items()}
229
+ state = entry.get("state")
230
+ services = {name: claimed_service_stanza(name, stanza, source, state) for name, stanza in services_value.items()}
227
231
  return {**entry, "services": services}
228
232
 
229
233
 
230
- def claimed_service_stanza(name: str, stanza: Yaml, source: str) -> Yaml:
234
+ def claimed_service_stanza(name: str, stanza: Yaml, source: str, state: Yaml) -> Yaml:
231
235
  if not is_mapping(stanza) or (PROVISIONER_ROUTE_KEY not in stanza and PROVISIONER_PORT_KEY not in stanza):
232
236
  return stanza
233
237
  route_value = stanza.get(PROVISIONER_ROUTE_KEY)
@@ -249,8 +253,7 @@ def claimed_service_stanza(name: str, stanza: Yaml, source: str) -> Yaml:
249
253
  raise ValueError(
250
254
  f"{site}: {PROVISIONER_ROUTE_KEY}: requires the {PROVISIONER_PORT_KEY}: key naming the listen port"
251
255
  )
252
- if isinstance(port_value, bool) or not isinstance(port_value, int) or not 1 <= port_value <= 65535:
253
- raise ValueError(f"{site}: {PROVISIONER_PORT_KEY}: must be a literal port in the range 1-65535")
256
+ port = provisioner_route_port(port_value, state, site)
254
257
  annotations = stanza.get("annotations")
255
258
  if annotations is not None and not is_mapping(annotations):
256
259
  raise ValueError(f"{site}: annotations: must be a mapping")
@@ -259,18 +262,51 @@ def claimed_service_stanza(name: str, stanza: Yaml, source: str) -> Yaml:
259
262
  if annotation in spelled:
260
263
  raise ValueError(f"{site}: annotates {annotation} directly; declare {PROVISIONER_ROUTE_KEY}: instead")
261
264
  spelled[ROUTE_ANNOTATION] = route_value
262
- spelled[ROUTE_PORT_ANNOTATION] = str(port_value)
265
+ spelled[ROUTE_PORT_ANNOTATION] = str(port)
263
266
  return {
264
267
  **{key: value for key, value in stanza.items() if key not in (PROVISIONER_ROUTE_KEY, PROVISIONER_PORT_KEY)},
265
268
  "annotations": spelled,
266
269
  }
267
270
 
268
271
 
272
+ def provisioner_route_port(value: Yaml, state: Yaml, site: str) -> int:
273
+ # A literal int rides through; a string is one {{ .State.<name> }} template rendered
274
+ # against the provisioner's own state (the state the templating engine resolves the
275
+ # stanza's other templates against), so the port annotation carries the integer
276
+ shapes = f"{site}: {PROVISIONER_PORT_KEY}: must be a literal port in the range 1-65535 or a {{{{ .State.<name> }}}} template"
277
+ match value:
278
+ case bool():
279
+ raise ValueError(shapes)
280
+ case int():
281
+ if not 1 <= value <= 65535:
282
+ raise ValueError(shapes)
283
+ return value
284
+ case str():
285
+ pass
286
+ case _:
287
+ raise ValueError(shapes)
288
+ template = STATE_TEMPLATE_PATTERN.fullmatch(value)
289
+ if template is None:
290
+ raise ValueError(shapes)
291
+ resolved: Yaml = state
292
+ for segment in template.group(1).split("."):
293
+ if not is_mapping(resolved) or segment not in resolved:
294
+ raise ValueError(f"{site}: {PROVISIONER_PORT_KEY}: {value!r} names no entry the state declares")
295
+ resolved = resolved[segment]
296
+ rendered = str(resolved)
297
+ if not rendered.isdigit() or not 1 <= int(rendered) <= 65535:
298
+ raise ValueError(
299
+ f"{site}: {PROVISIONER_PORT_KEY}: {value!r} renders to {rendered!r}, not a port in the range 1-65535"
300
+ )
301
+ return int(rendered)
302
+
303
+
269
304
  def injected_workload(config: ConfigFile, workload: LoadedWorkload, variable_values: dict[str, str]) -> Yaml:
270
305
  # The image reference is composed from the container's declared source and injected
271
306
  # before score sees the document; it is never authored in the workload file. Probe
272
- # ports ride the same pass: authored as listener names, rewritten to the resolved
273
- # port so both renderings hand the score tools the integer.
307
+ # ports and listener references in container variables ride the same pass: authored
308
+ # as listener names, rewritten to the resolved port so both renderings hand the
309
+ # score tools the concrete value.
274
310
  sources = workload.document.container_sources()
275
311
  if not sources:
276
312
  return workload.raw
@@ -313,6 +349,7 @@ def injected_workload(config: ConfigFile, workload: LoadedWorkload, variable_val
313
349
  raise ValueError(f"{workload.file_name}: containers.{container} must be a mapping")
314
350
  entry["image"] = reference
315
351
  rewrite_probe_ports(containers, workload)
352
+ rewrite_listener_variables(containers, workload)
316
353
  return document
317
354
 
318
355
 
@@ -335,6 +372,26 @@ def rewrite_probe_ports(containers: dict[str, Yaml], workload: LoadedWorkload) -
335
372
  http_get["port"] = listeners[port]
336
373
 
337
374
 
375
+ def rewrite_listener_variables(containers: dict[str, Yaml], workload: LoadedWorkload) -> None:
376
+ # The lens already refused every ${listeners.<name>.port} reference that names no
377
+ # declared listener, so the rewrite is a plain substitution over the validated
378
+ # documents; the port lands as a string because the score schemas type variables
379
+ # as strings and the old self-port resource idiom rendered the string form
380
+ listeners = workload.document.listener_ports
381
+ for entry in containers.values():
382
+ if not is_mapping(entry):
383
+ continue
384
+ variables = entry.get("variables")
385
+ if not is_mapping(variables):
386
+ continue
387
+ for key, value in variables.items():
388
+ if not isinstance(value, str):
389
+ continue
390
+ name = listener_port_reference(value)
391
+ if name is not None:
392
+ variables[key] = str(listeners[name])
393
+
394
+
338
395
  def dump_yaml(value: Yaml) -> str:
339
396
  return yaml.dump(
340
397
  value,
@@ -1295,7 +1295,9 @@ def test_provisioner_claims_translate_into_annotations_under_the_string_form(
1295
1295
  }
1296
1296
 
1297
1297
 
1298
- def _invoke_claiming_provisioner(monkeypatch: pytest.MonkeyPatch, tmp_path: Path, provisioner: str) -> None:
1298
+ def _invoke_claiming_provisioner(
1299
+ monkeypatch: pytest.MonkeyPatch, tmp_path: Path, provisioner: str
1300
+ ) -> CompiledProvisionersRecorder:
1299
1301
  sources = {
1300
1302
  "stack/score/api.yaml": _workload_referencing("config", "api"),
1301
1303
  "stack/score/compose/config.yaml": provisioner,
@@ -1311,6 +1313,7 @@ def _invoke_claiming_provisioner(monkeypatch: pytest.MonkeyPatch, tmp_path: Path
1311
1313
  config,
1312
1314
  _lock_for_images({"EXAMPLE_IMAGE": "ghcr.io/org/example:1@" + DIGEST, **ALPINE_LOCK}),
1313
1315
  )
1316
+ return recorder
1314
1317
 
1315
1318
 
1316
1319
  def test_a_provisioner_route_without_its_port_refuses(tmp_path: Path, monkeypatch: pytest.MonkeyPatch) -> None:
@@ -1383,6 +1386,124 @@ def test_a_provisioner_stanza_annotating_the_claim_directly_refuses(
1383
1386
  )
1384
1387
 
1385
1388
 
1389
+ PROVISIONER_WITH_TEMPLATED_CLAIM = """
1390
+ - uri: template://example/config
1391
+ type: example-config
1392
+ state:
1393
+ grafana_port: 3000
1394
+ services:
1395
+ grafana:
1396
+ image: ${EXAMPLE_IMAGE:?err}
1397
+ route: /grafana/*
1398
+ port: "{{ .State.grafana_port }}"
1399
+ healthcheck:
1400
+ test:
1401
+ [
1402
+ "CMD",
1403
+ "wget",
1404
+ "--quiet",
1405
+ "--tries=1",
1406
+ "--output-document=-",
1407
+ "http://localhost:{{ .State.grafana_port }}/health",
1408
+ ]
1409
+ interval: 5s
1410
+ """
1411
+
1412
+
1413
+ def test_a_templated_provisioner_route_port_renders_into_the_annotation(
1414
+ tmp_path: Path, monkeypatch: pytest.MonkeyPatch
1415
+ ) -> None:
1416
+ recorder = _invoke_claiming_provisioner(monkeypatch, tmp_path, PROVISIONER_WITH_TEMPLATED_CLAIM)
1417
+
1418
+ [document] = recorder.compiled
1419
+ [entry] = document
1420
+ assert isinstance(entry, dict)
1421
+ services_text = entry["services"]
1422
+ assert isinstance(services_text, str)
1423
+ grafana = yaml.safe_load(services_text)["grafana"]
1424
+ assert "route" not in grafana
1425
+ assert "port" not in grafana
1426
+ assert grafana["annotations"] == {"boatyard/route": "/grafana/*", "boatyard/port": "3000"}
1427
+
1428
+
1429
+ def test_the_healthcheck_templating_the_same_state_key_rides_through(
1430
+ tmp_path: Path, monkeypatch: pytest.MonkeyPatch
1431
+ ) -> None:
1432
+ recorder = _invoke_claiming_provisioner(monkeypatch, tmp_path, PROVISIONER_WITH_TEMPLATED_CLAIM)
1433
+
1434
+ [document] = recorder.compiled
1435
+ [entry] = document
1436
+ assert isinstance(entry, dict)
1437
+ services_text = entry["services"]
1438
+ assert isinstance(services_text, str)
1439
+ grafana = yaml.safe_load(services_text)["grafana"]
1440
+ assert grafana["healthcheck"]["test"][-1] == "http://localhost:{{ .State.grafana_port }}/health"
1441
+ assert grafana["annotations"]["boatyard/port"] == "3000"
1442
+
1443
+
1444
+ def test_a_templated_provisioner_route_port_refuses_a_non_integer_render(
1445
+ tmp_path: Path, monkeypatch: pytest.MonkeyPatch
1446
+ ) -> None:
1447
+ with pytest.raises(ValueError, match=r"renders to 'not-a-port', not a port in the range 1-65535"):
1448
+ _invoke_claiming_provisioner(
1449
+ monkeypatch,
1450
+ tmp_path,
1451
+ """
1452
+ - uri: template://example/config
1453
+ type: example-config
1454
+ state:
1455
+ grafana_port: not-a-port
1456
+ services:
1457
+ grafana:
1458
+ image: ${EXAMPLE_IMAGE:?err}
1459
+ route: /grafana/*
1460
+ port: "{{ .State.grafana_port }}"
1461
+ """,
1462
+ )
1463
+
1464
+
1465
+ def test_a_templated_provisioner_route_port_refuses_an_out_of_range_render(
1466
+ tmp_path: Path, monkeypatch: pytest.MonkeyPatch
1467
+ ) -> None:
1468
+ with pytest.raises(ValueError, match=r"renders to '70000', not a port in the range 1-65535"):
1469
+ _invoke_claiming_provisioner(
1470
+ monkeypatch,
1471
+ tmp_path,
1472
+ """
1473
+ - uri: template://example/config
1474
+ type: example-config
1475
+ state:
1476
+ grafana_port: 70000
1477
+ services:
1478
+ grafana:
1479
+ image: ${EXAMPLE_IMAGE:?err}
1480
+ route: /grafana/*
1481
+ port: "{{ .State.grafana_port }}"
1482
+ """,
1483
+ )
1484
+
1485
+
1486
+ def test_a_templated_provisioner_route_port_refuses_a_missing_state_key(
1487
+ tmp_path: Path, monkeypatch: pytest.MonkeyPatch
1488
+ ) -> None:
1489
+ with pytest.raises(ValueError, match=r"names no entry the state declares"):
1490
+ _invoke_claiming_provisioner(
1491
+ monkeypatch,
1492
+ tmp_path,
1493
+ """
1494
+ - uri: template://example/config
1495
+ type: example-config
1496
+ state:
1497
+ grafana_port: 3000
1498
+ services:
1499
+ grafana:
1500
+ image: ${EXAMPLE_IMAGE:?err}
1501
+ route: /grafana/*
1502
+ port: "{{ .State.admin_port }}"
1503
+ """,
1504
+ )
1505
+
1506
+
1386
1507
  WORKLOAD_WITH_LIVENESS = """
1387
1508
  metadata:
1388
1509
  name: api
@@ -1651,6 +1772,243 @@ def test_the_k8s_rendering_receives_the_resolved_probe_port(tmp_path: Path, monk
1651
1772
  assert "port: mgmt\n" not in recorder.workload_contents["api.yaml"]
1652
1773
 
1653
1774
 
1775
+ WORKLOAD_VARIABLES_BARE_SERVICE_PORT = """
1776
+ metadata:
1777
+ name: api
1778
+ annotations:
1779
+ boatyard/lock: api=API_IMAGE
1780
+ service:
1781
+ ports:
1782
+ web: 5678
1783
+ containers:
1784
+ api:
1785
+ variables:
1786
+ SERVICE_PORT: ${listeners.web.port}
1787
+ """
1788
+
1789
+ WORKLOAD_VARIABLES_TARGET_SERVICE_PORT = """
1790
+ apiVersion: score.dev/v1b1
1791
+ metadata:
1792
+ name: api
1793
+ annotations:
1794
+ boatyard/lock: api=API_IMAGE
1795
+ service:
1796
+ ports:
1797
+ web:
1798
+ port: 80
1799
+ targetPort: 9090
1800
+ containers:
1801
+ api:
1802
+ variables:
1803
+ SERVICE_PORT: ${listeners.web.port}
1804
+ """
1805
+
1806
+ WORKLOAD_VARIABLES_CONTAINER_PORT = """
1807
+ metadata:
1808
+ name: api
1809
+ annotations:
1810
+ boatyard/container-ports: mgmt=9000
1811
+ boatyard/lock: api=API_IMAGE
1812
+ containers:
1813
+ api:
1814
+ variables:
1815
+ SERVICE_PORT: ${listeners.mgmt.port}
1816
+ """
1817
+
1818
+
1819
+ def test_listener_variable_references_resolve_over_both_service_port_shapes() -> None:
1820
+ for fixture, resolved in (
1821
+ (WORKLOAD_VARIABLES_BARE_SERVICE_PORT, 5678),
1822
+ (WORKLOAD_VARIABLES_TARGET_SERVICE_PORT, 9090),
1823
+ ):
1824
+ document = WorkloadDocument.parse(yaml.safe_load(fixture), "api.yaml")
1825
+
1826
+ assert document.listener_ports == {"web": resolved}
1827
+
1828
+
1829
+ def test_listener_variable_references_resolve_the_container_ports_annotation() -> None:
1830
+ document = WorkloadDocument.parse(yaml.safe_load(WORKLOAD_VARIABLES_CONTAINER_PORT), "api.yaml")
1831
+
1832
+ assert document.listener_ports == {"mgmt": 9000}
1833
+
1834
+
1835
+ def test_unknown_listener_variable_names_refuse_listing_the_declared_listeners() -> None:
1836
+ with pytest.raises(ValidationError, match=r"names no declared listener \(mgmt, web\)"):
1837
+ WorkloadDocument.parse(
1838
+ {
1839
+ "metadata": {
1840
+ "name": "api",
1841
+ "annotations": {"boatyard/container-ports": "mgmt=9000", "boatyard/lock": "api=API_IMAGE"},
1842
+ },
1843
+ "service": {"ports": {"web": 5678}},
1844
+ "containers": {"api": {"variables": {"SERVICE_PORT": "${listeners.admin.port}"}}},
1845
+ },
1846
+ "api.yaml",
1847
+ )
1848
+
1849
+
1850
+ def test_malformed_listener_variable_paths_refuse() -> None:
1851
+ malformed = ("${listeners.web}", "${listeners.web.port.extra}", "${listeners.web.hostname}")
1852
+ for value in malformed:
1853
+ with pytest.raises(ValidationError, match=r"must be \$\{listeners\.<listener>\.port\}"):
1854
+ WorkloadDocument.parse(
1855
+ {
1856
+ "metadata": {"name": "api", "annotations": {"boatyard/lock": "api=API_IMAGE"}},
1857
+ "service": {"ports": {"web": 5678}},
1858
+ "containers": {"api": {"variables": {"SERVICE_PORT": value}}},
1859
+ },
1860
+ "api.yaml",
1861
+ )
1862
+
1863
+
1864
+ def test_the_compose_rendering_receives_the_resolved_listener_variable(
1865
+ tmp_path: Path, monkeypatch: pytest.MonkeyPatch
1866
+ ) -> None:
1867
+ (tmp_path / "stack" / "score").mkdir(parents=True)
1868
+ (tmp_path / "stack" / "score" / "api.yaml").write_text(WORKLOAD_VARIABLES_TARGET_SERVICE_PORT, encoding="utf-8")
1869
+ recorder = WorkloadContentsRecorder()
1870
+ monkeypatch.setattr(score_module, "bash", recorder.run)
1871
+ config = _generated_config(
1872
+ tmp_path,
1873
+ ["api.yaml"],
1874
+ repository="ghcr.io/org/repo",
1875
+ project_name="example",
1876
+ platforms=["linux/amd64"],
1877
+ services={"core": {"options": {"main": {"workloads": ["api.yaml"]}}}},
1878
+ )
1879
+
1880
+ score_compose_module.generate_compose(
1881
+ config,
1882
+ _lock_for_images({"API_IMAGE": "ghcr.io/org/api:1@" + DIGEST, **ALPINE_LOCK}),
1883
+ )
1884
+
1885
+ assert "SERVICE_PORT: '9090'\n" in recorder.workload_contents["api.yaml"]
1886
+ assert "${listeners." not in recorder.workload_contents["api.yaml"]
1887
+
1888
+
1889
+ WORKLOAD_VARIABLES_DOCKERFILE_PORT = (
1890
+ "metadata:\n"
1891
+ " name: api\n"
1892
+ " annotations:\n"
1893
+ " boatyard/dockerfile: api=workloads/api/Dockerfile\n"
1894
+ " boatyard/container-ports: mgmt=9000\n"
1895
+ "containers:\n"
1896
+ " api:\n"
1897
+ " variables:\n"
1898
+ " SERVICE_PORT: ${listeners.mgmt.port}\n"
1899
+ )
1900
+
1901
+
1902
+ def test_the_k8s_rendering_receives_the_resolved_listener_variable(
1903
+ tmp_path: Path, monkeypatch: pytest.MonkeyPatch
1904
+ ) -> None:
1905
+ _write_pins(tmp_path, {"API_SHA": PINNED_TAG})
1906
+ recorder = _pins_k8s_recorder(monkeypatch, tmp_path, WORKLOAD_VARIABLES_DOCKERFILE_PORT)
1907
+ config, k8s = _pinned_config(tmp_path)
1908
+
1909
+ generate_k8s(config, k8s, LockFile.model_validate({}), local=False)
1910
+
1911
+ assert "SERVICE_PORT: '9000'\n" in recorder.workload_contents["api.yaml"]
1912
+ assert "${listeners." not in recorder.workload_contents["api.yaml"]
1913
+
1914
+
1915
+ WORKLOAD_LEGACY_SELF_PORT = """
1916
+ metadata:
1917
+ name: api
1918
+ annotations:
1919
+ boatyard/lock: api=API_IMAGE
1920
+ service:
1921
+ ports:
1922
+ web: 8000
1923
+ resources:
1924
+ self-port:
1925
+ type: service-port
1926
+ id: api-web
1927
+ params:
1928
+ workload: api
1929
+ port: web
1930
+ containers:
1931
+ api:
1932
+ variables:
1933
+ SERVICE_PORT: ${resources.self-port.port}
1934
+ """
1935
+
1936
+
1937
+ def test_the_legacy_self_port_resource_idiom_rides_through_unchanged(
1938
+ tmp_path: Path, monkeypatch: pytest.MonkeyPatch
1939
+ ) -> None:
1940
+ (tmp_path / "stack" / "score").mkdir(parents=True)
1941
+ (tmp_path / "stack" / "score" / "api.yaml").write_text(WORKLOAD_LEGACY_SELF_PORT, encoding="utf-8")
1942
+ recorder = WorkloadContentsRecorder()
1943
+ monkeypatch.setattr(score_module, "bash", recorder.run)
1944
+ config = _generated_config(
1945
+ tmp_path,
1946
+ ["api.yaml"],
1947
+ repository="ghcr.io/org/repo",
1948
+ project_name="example",
1949
+ platforms=["linux/amd64"],
1950
+ services={"core": {"options": {"main": {"workloads": ["api.yaml"]}}}},
1951
+ )
1952
+
1953
+ score_compose_module.generate_compose(
1954
+ config,
1955
+ _lock_for_images({"API_IMAGE": "ghcr.io/org/api:1@" + DIGEST, **ALPINE_LOCK}),
1956
+ )
1957
+
1958
+ assert "SERVICE_PORT: ${resources.self-port.port}\n" in recorder.workload_contents["api.yaml"]
1959
+
1960
+
1961
+ SELF_PORT_PROVISIONER = (
1962
+ "- uri: template://example/self-port\n type: service-port\n state:\n port: 9090\n outputs:\n port: 9090\n"
1963
+ )
1964
+
1965
+ WORKLOAD_IDIOM_SELF_PORT = (
1966
+ "apiVersion: score.dev/v1b1\n"
1967
+ "metadata:\n"
1968
+ " name: idiom\n"
1969
+ " annotations:\n"
1970
+ " boatyard/lock: idiom=API_IMAGE\n"
1971
+ "resources:\n"
1972
+ " self-port:\n"
1973
+ " type: service-port\n"
1974
+ " id: idiom-main\n"
1975
+ "containers:\n"
1976
+ " idiom:\n"
1977
+ " variables:\n"
1978
+ " SERVICE_PORT: ${resources.self-port.port}\n"
1979
+ )
1980
+
1981
+
1982
+ def test_listener_variable_ports_render_as_the_self_port_idiom_renders(
1983
+ tmp_path: Path, monkeypatch: pytest.MonkeyPatch
1984
+ ) -> None:
1985
+ _skip_unless_pinned_score_compose()
1986
+ score_dir = tmp_path / "stack" / "score"
1987
+ (score_dir / "compose").mkdir(parents=True)
1988
+ (score_dir / "api.yaml").write_text(WORKLOAD_VARIABLES_TARGET_SERVICE_PORT, encoding="utf-8")
1989
+ (score_dir / "idiom.yaml").write_text(WORKLOAD_IDIOM_SELF_PORT, encoding="utf-8")
1990
+ (score_dir / "compose" / "self-port.yaml").write_text(SELF_PORT_PROVISIONER, encoding="utf-8")
1991
+ config = _generated_config(
1992
+ tmp_path,
1993
+ ["api.yaml", "idiom.yaml"],
1994
+ repository="ghcr.io/org/repo",
1995
+ project_name="example",
1996
+ platforms=["linux/amd64"],
1997
+ services={"core": {"options": {"main": {"workloads": ["api.yaml", "idiom.yaml"]}}}},
1998
+ )
1999
+
2000
+ score_compose_module.generate_compose(
2001
+ config,
2002
+ _lock_for_images({"API_IMAGE": "ghcr.io/org/api:1@" + DIGEST, **ALPINE_LOCK}),
2003
+ )
2004
+
2005
+ document = yaml.safe_load(
2006
+ (tmp_path / "stack" / "generated" / "compose" / "compose.core-main.yaml").read_text(encoding="utf-8")
2007
+ )
2008
+ assert document["services"]["api"]["environment"] == {"SERVICE_PORT": "9090"}
2009
+ assert document["services"]["idiom"]["environment"] == {"SERVICE_PORT": "9090"}
2010
+
2011
+
1654
2012
  def test_workload_resources_parse_typed() -> None:
1655
2013
  document = WorkloadDocument.parse(
1656
2014
  {"resources": {"db": {"type": "example-db"}}, "metadata": {"name": "api"}}, "api.yaml"
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes