boatyard 0.9.1.dev250__tar.gz → 0.9.2__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.
- {boatyard-0.9.1.dev250 → boatyard-0.9.2}/AGENTS.md +11 -0
- {boatyard-0.9.1.dev250 → boatyard-0.9.2}/PKG-INFO +1 -1
- {boatyard-0.9.1.dev250 → boatyard-0.9.2}/pyproject.toml +1 -1
- {boatyard-0.9.1.dev250 → boatyard-0.9.2}/src/boatyard/lock.py +25 -9
- {boatyard-0.9.1.dev250 → boatyard-0.9.2}/src/boatyard/models/config_file.py +17 -61
- {boatyard-0.9.1.dev250 → boatyard-0.9.2}/src/boatyard/models/workload.py +99 -27
- {boatyard-0.9.1.dev250 → boatyard-0.9.2}/src/boatyard/resolve.py +24 -20
- {boatyard-0.9.1.dev250 → boatyard-0.9.2}/src/boatyard/score.py +88 -2
- {boatyard-0.9.1.dev250 → boatyard-0.9.2}/src/boatyard/score_compose.py +9 -1
- {boatyard-0.9.1.dev250 → boatyard-0.9.2}/src/boatyard/verbs/up.py +10 -13
- {boatyard-0.9.1.dev250 → boatyard-0.9.2}/tests/test_assembly.py +63 -31
- {boatyard-0.9.1.dev250 → boatyard-0.9.2}/tests/test_compose.py +55 -63
- {boatyard-0.9.1.dev250 → boatyard-0.9.2}/tests/test_config.py +65 -189
- {boatyard-0.9.1.dev250 → boatyard-0.9.2}/tests/test_lock.py +53 -34
- {boatyard-0.9.1.dev250 → boatyard-0.9.2}/tests/test_score_generate.py +244 -0
- {boatyard-0.9.1.dev250 → boatyard-0.9.2}/tests/test_values.py +1 -1
- {boatyard-0.9.1.dev250 → boatyard-0.9.2}/.gitattributes +0 -0
- {boatyard-0.9.1.dev250 → boatyard-0.9.2}/.github/workflows/cleanup-pr-releases.yml +0 -0
- {boatyard-0.9.1.dev250 → boatyard-0.9.2}/.github/workflows/integrate.yml +0 -0
- {boatyard-0.9.1.dev250 → boatyard-0.9.2}/.github/workflows/merge-gate.yml +0 -0
- {boatyard-0.9.1.dev250 → boatyard-0.9.2}/.github/workflows/release.yml +0 -0
- {boatyard-0.9.1.dev250 → boatyard-0.9.2}/.gitignore +0 -0
- {boatyard-0.9.1.dev250 → boatyard-0.9.2}/.python-version +0 -0
- {boatyard-0.9.1.dev250 → boatyard-0.9.2}/CLAUDE.md +0 -0
- {boatyard-0.9.1.dev250 → boatyard-0.9.2}/LICENSE +0 -0
- {boatyard-0.9.1.dev250 → boatyard-0.9.2}/NOTICE +0 -0
- {boatyard-0.9.1.dev250 → boatyard-0.9.2}/README.md +0 -0
- {boatyard-0.9.1.dev250 → boatyard-0.9.2}/design/AGENTS.md +0 -0
- {boatyard-0.9.1.dev250 → boatyard-0.9.2}/design/CLAUDE.md +0 -0
- {boatyard-0.9.1.dev250 → boatyard-0.9.2}/design/apt-hermeticity.md +0 -0
- {boatyard-0.9.1.dev250 → boatyard-0.9.2}/design/mirror-digest-retention.md +0 -0
- {boatyard-0.9.1.dev250 → boatyard-0.9.2}/design/precision-attribution.md +0 -0
- {boatyard-0.9.1.dev250 → boatyard-0.9.2}/design/semver-image-bundle-lines.md +0 -0
- {boatyard-0.9.1.dev250 → boatyard-0.9.2}/publish.yml +0 -0
- {boatyard-0.9.1.dev250 → boatyard-0.9.2}/ruff.base.toml +0 -0
- {boatyard-0.9.1.dev250 → boatyard-0.9.2}/ruff.toml +0 -0
- {boatyard-0.9.1.dev250 → boatyard-0.9.2}/scripts/preflight.py +0 -0
- {boatyard-0.9.1.dev250 → boatyard-0.9.2}/src/boatyard/__init__.py +0 -0
- {boatyard-0.9.1.dev250 → boatyard-0.9.2}/src/boatyard/build.py +0 -0
- {boatyard-0.9.1.dev250 → boatyard-0.9.2}/src/boatyard/cli.py +0 -0
- {boatyard-0.9.1.dev250 → boatyard-0.9.2}/src/boatyard/crane.py +0 -0
- {boatyard-0.9.1.dev250 → boatyard-0.9.2}/src/boatyard/markers.py +0 -0
- {boatyard-0.9.1.dev250 → boatyard-0.9.2}/src/boatyard/models/__init__.py +0 -0
- {boatyard-0.9.1.dev250 → boatyard-0.9.2}/src/boatyard/models/image.py +0 -0
- {boatyard-0.9.1.dev250 → boatyard-0.9.2}/src/boatyard/models/k8s_pins.py +0 -0
- {boatyard-0.9.1.dev250 → boatyard-0.9.2}/src/boatyard/models/lock_file.py +0 -0
- {boatyard-0.9.1.dev250 → boatyard-0.9.2}/src/boatyard/models/pyproject.py +0 -0
- {boatyard-0.9.1.dev250 → boatyard-0.9.2}/src/boatyard/models/values_file.py +0 -0
- {boatyard-0.9.1.dev250 → boatyard-0.9.2}/src/boatyard/paths.py +0 -0
- {boatyard-0.9.1.dev250 → boatyard-0.9.2}/src/boatyard/publish.py +0 -0
- {boatyard-0.9.1.dev250 → boatyard-0.9.2}/src/boatyard/py.typed +0 -0
- {boatyard-0.9.1.dev250 → boatyard-0.9.2}/src/boatyard/score_generate.py +0 -0
- {boatyard-0.9.1.dev250 → boatyard-0.9.2}/src/boatyard/score_k8s.py +0 -0
- {boatyard-0.9.1.dev250 → boatyard-0.9.2}/src/boatyard/score_patch_templates/gpu-cuda.tpl +0 -0
- {boatyard-0.9.1.dev250 → boatyard-0.9.2}/src/boatyard/score_patch_templates/gpu-pod.tpl +0 -0
- {boatyard-0.9.1.dev250 → boatyard-0.9.2}/src/boatyard/score_patch_templates/gpu-rocm.tpl +0 -0
- {boatyard-0.9.1.dev250 → boatyard-0.9.2}/src/boatyard/score_patch_templates/probe-adapter-healthchecks.tpl +0 -0
- {boatyard-0.9.1.dev250 → boatyard-0.9.2}/src/boatyard/score_patch_templates/restart.tpl +0 -0
- {boatyard-0.9.1.dev250 → boatyard-0.9.2}/src/boatyard/score_patch_templates/scale-to-zero.tpl +0 -0
- {boatyard-0.9.1.dev250 → boatyard-0.9.2}/src/boatyard/temp.py +0 -0
- {boatyard-0.9.1.dev250 → boatyard-0.9.2}/src/boatyard/verbs/__init__.py +0 -0
- {boatyard-0.9.1.dev250 → boatyard-0.9.2}/src/boatyard/verbs/build.py +0 -0
- {boatyard-0.9.1.dev250 → boatyard-0.9.2}/src/boatyard/verbs/bump.py +0 -0
- {boatyard-0.9.1.dev250 → boatyard-0.9.2}/src/boatyard/verbs/down.py +0 -0
- {boatyard-0.9.1.dev250 → boatyard-0.9.2}/src/boatyard/verbs/lock.py +0 -0
- {boatyard-0.9.1.dev250 → boatyard-0.9.2}/src/boatyard/verbs/matrix.py +0 -0
- {boatyard-0.9.1.dev250 → boatyard-0.9.2}/src/boatyard/verbs/mirror.py +0 -0
- {boatyard-0.9.1.dev250 → boatyard-0.9.2}/src/boatyard/verbs/publish.py +0 -0
- {boatyard-0.9.1.dev250 → boatyard-0.9.2}/src/boatyard/verbs/score.py +0 -0
- {boatyard-0.9.1.dev250 → boatyard-0.9.2}/src/boatyard/verbs/tree_tags.py +0 -0
- {boatyard-0.9.1.dev250 → boatyard-0.9.2}/src/boatyard/yaml.py +0 -0
- {boatyard-0.9.1.dev250 → boatyard-0.9.2}/tests/conftest.py +0 -0
- {boatyard-0.9.1.dev250 → boatyard-0.9.2}/tests/test_build_docker.py +0 -0
- {boatyard-0.9.1.dev250 → boatyard-0.9.2}/tests/test_bump.py +0 -0
- {boatyard-0.9.1.dev250 → boatyard-0.9.2}/tests/test_daemon_gc.py +0 -0
- {boatyard-0.9.1.dev250 → boatyard-0.9.2}/tests/test_image_builds.py +0 -0
- {boatyard-0.9.1.dev250 → boatyard-0.9.2}/tests/test_markers.py +0 -0
- {boatyard-0.9.1.dev250 → boatyard-0.9.2}/tests/test_matrix.py +0 -0
- {boatyard-0.9.1.dev250 → boatyard-0.9.2}/tests/test_mirror.py +0 -0
- {boatyard-0.9.1.dev250 → boatyard-0.9.2}/tests/test_provisioners.py +0 -0
- {boatyard-0.9.1.dev250 → boatyard-0.9.2}/tests/test_publish_compose.py +0 -0
- {boatyard-0.9.1.dev250 → boatyard-0.9.2}/tests/test_tree_tags.py +0 -0
- {boatyard-0.9.1.dev250 → boatyard-0.9.2}/uv.lock +0 -0
|
@@ -38,6 +38,17 @@ Design intent and silent-failure traps, one fact per bullet.
|
|
|
38
38
|
entry set plus the bare project name, removing the shared network last.
|
|
39
39
|
- The `boatyard-gateway` service does no token validation; re-protection is a bundle-shipped
|
|
40
40
|
oauth2-proxy sidecar treaty.
|
|
41
|
+
- Routes are path claims the serving surface authors: a workload's `boatyard/route: /auth/*`
|
|
42
|
+
(an optional `@port-name` qualifier when `service.ports` declares several, an optional
|
|
43
|
+
`, strip` entry) or a provisioner service stanza's `route:`/`port:` keys, which the compile
|
|
44
|
+
pass re-spells as the same annotations. The upstream is derived — the declaring service at
|
|
45
|
+
its `service.ports` listen port (`targetPort` else `port`) — so the rendered stanza carries
|
|
46
|
+
the claim verbatim plus a `boatyard/port` annotation, and adoption composes the two into
|
|
47
|
+
route records; nothing hand-copies an upstream.
|
|
48
|
+
- The gateway table is compiler output: it orders by path specificity (longest concrete
|
|
49
|
+
prefix first, the `/*` catch-all last), and each claiming workload exports
|
|
50
|
+
`<WORKLOAD>_ROUTE_PATH` (the claim's concrete path) into the tool env provisioner
|
|
51
|
+
templates read via `{{ env }}`.
|
|
41
52
|
- `$`-doubling: a literal `$` in file text placed inside a compose document (edge Caddyfile,
|
|
42
53
|
file-sourced configs, score's bind inlining) is doubled via `double_dollars` in
|
|
43
54
|
`models/config_file.py` — the one home. Text outside a compose document (k8s manifests) never
|
|
@@ -16,6 +16,7 @@ from boatyard.models.config_file import (
|
|
|
16
16
|
PublishedPort,
|
|
17
17
|
Route,
|
|
18
18
|
ConfigFile,
|
|
19
|
+
artifact_service_names,
|
|
19
20
|
artifact_slots,
|
|
20
21
|
bundle_lock_key,
|
|
21
22
|
chart_lock_key,
|
|
@@ -33,8 +34,10 @@ from boatyard.models.workload import (
|
|
|
33
34
|
AUTOSTART_ANNOTATION,
|
|
34
35
|
PUBLISH_PORT_ANNOTATION,
|
|
35
36
|
ROUTE_ANNOTATION,
|
|
37
|
+
ROUTE_PORT_ANNOTATION,
|
|
36
38
|
parse_publish_port_annotation,
|
|
37
39
|
parse_route_annotation,
|
|
40
|
+
parse_route_port_annotation,
|
|
38
41
|
)
|
|
39
42
|
from boatyard.temp import SHA256_DIGEST_REGEX
|
|
40
43
|
from boatyard.yaml import Yaml, is_list, is_mapping, load_yaml_model
|
|
@@ -129,8 +132,8 @@ def relock(config: ConfigFile, *, upgrade: bool = False, check: bool = False) ->
|
|
|
129
132
|
|
|
130
133
|
# Record the bundle's lock entry
|
|
131
134
|
texts = OciArtifactManifest.fetch_compose_texts(pinned)
|
|
132
|
-
refuse_unresolved_references(name, entry.routes, entry.ports, texts)
|
|
133
135
|
records = extract_bundle_records(texts)
|
|
136
|
+
refuse_unresolved_references(name, records.routes, entry.ports, artifact_service_names(texts))
|
|
134
137
|
if GATEWAY_SERVICE_NAME in records.services:
|
|
135
138
|
raise ValueError(f"{pinned}: the included bundle defines the reserved service {GATEWAY_SERVICE_NAME!r}")
|
|
136
139
|
bundles[key] = ConfigLockBundle(
|
|
@@ -280,19 +283,32 @@ def extract_bundle_records(texts: list[str]) -> BundleRecords:
|
|
|
280
283
|
# Read the routes and ports from the annotations
|
|
281
284
|
routes: list[Route] = []
|
|
282
285
|
ports: list[PublishedPort] = []
|
|
286
|
+
route_owners: dict[str, str] = {}
|
|
283
287
|
for service_name, _stanza, service_annotations in stanzas:
|
|
284
288
|
if service_annotations.get(AUTOSTART_ANNOTATION) == "false":
|
|
285
289
|
held_services.add(service_name)
|
|
286
290
|
route_value = service_annotations.get(ROUTE_ANNOTATION)
|
|
287
291
|
if route_value is not None:
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
292
|
+
claim = parse_route_annotation(route_value)
|
|
293
|
+
port_value = service_annotations.get(ROUTE_PORT_ANNOTATION)
|
|
294
|
+
if port_value is None:
|
|
295
|
+
raise ValueError(
|
|
296
|
+
f"{ROUTE_ANNOTATION}: the claim on the service {service_name!r} carries no "
|
|
297
|
+
f"{ROUTE_PORT_ANNOTATION} label; re-render the bundle with the claims grammar"
|
|
298
|
+
)
|
|
299
|
+
if claim.path in route_owners:
|
|
300
|
+
raise ValueError(
|
|
301
|
+
f"{ROUTE_ANNOTATION}: the path {claim.path} is claimed by both {route_owners[claim.path]} "
|
|
302
|
+
f"and {service_name}"
|
|
303
|
+
)
|
|
304
|
+
route_owners[claim.path] = service_name
|
|
305
|
+
routes.append(
|
|
306
|
+
Route(
|
|
307
|
+
path=claim.path,
|
|
308
|
+
upstream=f"{service_name}:{parse_route_port_annotation(port_value)}",
|
|
309
|
+
strip_prefix=claim.strip_prefix,
|
|
310
|
+
)
|
|
311
|
+
)
|
|
296
312
|
publish_value = service_annotations.get(PUBLISH_PORT_ANNOTATION)
|
|
297
313
|
if publish_value is not None:
|
|
298
314
|
ports.extend(
|
|
@@ -27,7 +27,6 @@ from boatyard.models.pyproject import PYPROJECT_PATH, PyprojectToml
|
|
|
27
27
|
from boatyard.models.image import Image, LocalBaseEntry, dockerfile_stem, parse_dockerfile
|
|
28
28
|
from boatyard.models.workload import (
|
|
29
29
|
ROUTE_PATH_PATTERN,
|
|
30
|
-
ROUTE_UPSTREAM_PATTERN,
|
|
31
30
|
LoadedWorkload,
|
|
32
31
|
)
|
|
33
32
|
from boatyard.temp import PLATFORM_PATTERN, SHA256_DIGEST_REGEX
|
|
@@ -56,6 +55,9 @@ DECLARED_REFERENCE_PATTERN = re.compile(
|
|
|
56
55
|
rf"^(?P<path>[^:@\s$]+)(?::(?P<tag>[^@\s$]+))?(?:@(?P<digest>{SHA256_DIGEST_REGEX}))?$"
|
|
57
56
|
)
|
|
58
57
|
|
|
58
|
+
# Match a derived route record's upstream: a service name and a literal port
|
|
59
|
+
ROUTE_UPSTREAM_SHAPE = re.compile(r"[a-zA-Z0-9][a-zA-Z0-9_.-]*:[0-9]+")
|
|
60
|
+
|
|
59
61
|
TEMPLATE_KEY_PATTERN = re.compile(r"\{([a-z][a-z0-9_]*)\}")
|
|
60
62
|
|
|
61
63
|
# Match the range operators a ref tag must never carry; exact tags only
|
|
@@ -224,39 +226,9 @@ class ConfigFile(BaseModel):
|
|
|
224
226
|
if isinstance(project_name, str) and ENTRY_NAME_PATTERN.fullmatch(project_name) is None:
|
|
225
227
|
raise ValueError(f"project_name {project_name!r} must match ^[a-z][a-z0-9-]*$")
|
|
226
228
|
|
|
227
|
-
#
|
|
228
|
-
|
|
229
|
-
(
|
|
230
|
-
for name, entry in services.items()
|
|
231
|
-
for where, entry_routes in (
|
|
232
|
-
[(f"services.{name}", entry.routes)]
|
|
233
|
-
if not isinstance(entry, ServiceGroup)
|
|
234
|
-
else [
|
|
235
|
-
(f"services.{name}.options.{option_name}", option.routes)
|
|
236
|
-
for option_name, option in entry.options.items()
|
|
237
|
-
]
|
|
238
|
-
+ [(f"services.{name}", entry.routes)]
|
|
239
|
-
)
|
|
240
|
-
for route in entry_routes
|
|
241
|
-
]
|
|
242
|
-
owner: dict[str, str] = {}
|
|
243
|
-
for where, route in route_sites:
|
|
244
|
-
if route.path in owner:
|
|
245
|
-
raise ValueError(f"{where}: route path {route.path} is already declared at {owner[route.path]}")
|
|
246
|
-
owner[route.path] = where
|
|
247
|
-
|
|
248
|
-
# If the reserved auth group is declared, cap its options at one route
|
|
249
|
-
if AUTH_GROUP_NAME in services:
|
|
250
|
-
auth = services[AUTH_GROUP_NAME]
|
|
251
|
-
if not isinstance(auth, ServiceGroup):
|
|
252
|
-
raise ValueError(f"services.{AUTH_GROUP_NAME} must be a group (the name is reserved)")
|
|
253
|
-
for option_name, option in auth.options.items():
|
|
254
|
-
if len(option.routes) > 1:
|
|
255
|
-
raise ValueError(
|
|
256
|
-
f"services.{AUTH_GROUP_NAME}.options.{option_name}: an auth option declares "
|
|
257
|
-
"at most one route; the exactly-one effective-route check runs at resolve "
|
|
258
|
-
"over authored plus adopted routes"
|
|
259
|
-
)
|
|
229
|
+
# The reserved auth group is a group like any other for shape purposes
|
|
230
|
+
if AUTH_GROUP_NAME in services and not isinstance(services[AUTH_GROUP_NAME], ServiceGroup):
|
|
231
|
+
raise ValueError(f"services.{AUTH_GROUP_NAME} must be a group (the name is reserved)")
|
|
260
232
|
return services
|
|
261
233
|
|
|
262
234
|
@model_validator(mode="after")
|
|
@@ -276,19 +248,6 @@ class ConfigFile(BaseModel):
|
|
|
276
248
|
"platforms is required when images are declared (an amd64-only repo declares [linux/amd64])"
|
|
277
249
|
)
|
|
278
250
|
|
|
279
|
-
# Find any declared route across entries and options
|
|
280
|
-
declares_routes = any(
|
|
281
|
-
routes
|
|
282
|
-
for member in self.services.values()
|
|
283
|
-
for routes in (
|
|
284
|
-
[member.routes, *(option.routes for option in member.options.values())]
|
|
285
|
-
if isinstance(member, ServiceGroup)
|
|
286
|
-
else [member.routes]
|
|
287
|
-
)
|
|
288
|
-
)
|
|
289
|
-
# If routes are declared, require a gateway
|
|
290
|
-
if declares_routes and self.gateway_port is None:
|
|
291
|
-
raise ValueError("routes require a gateway declaration")
|
|
292
251
|
upstream_sites: list[tuple[str, str]] = [
|
|
293
252
|
(f"base_images.{name}", reference) for name, reference in self.remote_base_images.items()
|
|
294
253
|
]
|
|
@@ -341,7 +300,6 @@ class ServiceGroup(BaseModel):
|
|
|
341
300
|
|
|
342
301
|
options: dict[str, ServiceEntry] = Field(default_factory=dict)
|
|
343
302
|
workloads: list[str] = Field(default_factory=list)
|
|
344
|
-
routes: list[Route] = Field(default_factory=list)
|
|
345
303
|
ports: list[PublishedPort] = Field(default_factory=list)
|
|
346
304
|
|
|
347
305
|
@model_validator(mode="after")
|
|
@@ -360,7 +318,6 @@ class ServiceEntry(BaseModel):
|
|
|
360
318
|
ref: str | None = None
|
|
361
319
|
workloads: list[str] = Field(default_factory=list)
|
|
362
320
|
vars: VarsMap = Field(default_factory=dict)
|
|
363
|
-
routes: list[Route] = Field(default_factory=list)
|
|
364
321
|
ports: list[PublishedPort] = Field(default_factory=list)
|
|
365
322
|
|
|
366
323
|
@property
|
|
@@ -415,13 +372,12 @@ class Route(BaseModel):
|
|
|
415
372
|
path: str
|
|
416
373
|
upstream: str
|
|
417
374
|
strip_prefix: bool = False
|
|
418
|
-
raw: str | None = None
|
|
419
375
|
|
|
420
376
|
@model_validator(mode="after")
|
|
421
377
|
def _validate(self) -> Self:
|
|
422
378
|
if ROUTE_PATH_PATTERN.fullmatch(self.path) is None:
|
|
423
379
|
raise ValueError(f"route path {self.path!r} must be a /-rooted segment chain, optionally wildcarded as …/*")
|
|
424
|
-
if
|
|
380
|
+
if ROUTE_UPSTREAM_SHAPE.fullmatch(self.upstream) is None:
|
|
425
381
|
raise ValueError(
|
|
426
382
|
f"route upstream {self.upstream!r} must be a service name and a literal port (grafana:3000)"
|
|
427
383
|
)
|
|
@@ -477,7 +433,6 @@ class FlattenedServiceEntry(NamedTuple):
|
|
|
477
433
|
name: str
|
|
478
434
|
site: str
|
|
479
435
|
entry: ServiceEntry
|
|
480
|
-
effective_routes: list[Route]
|
|
481
436
|
effective_ports: list[PublishedPort]
|
|
482
437
|
auth: bool
|
|
483
438
|
|
|
@@ -678,7 +633,6 @@ def flatten_service_entries(services: dict[str, ServiceGroup | ServiceEntry]) ->
|
|
|
678
633
|
name=qualified_option_name(root_name, option_name),
|
|
679
634
|
site=f"services.{root_name}.options.{option_name}",
|
|
680
635
|
entry=option,
|
|
681
|
-
effective_routes=option.routes + member.routes,
|
|
682
636
|
effective_ports=option.ports + member.ports,
|
|
683
637
|
auth=root_name == AUTH_GROUP_NAME,
|
|
684
638
|
)
|
|
@@ -692,7 +646,6 @@ def flatten_service_entries(services: dict[str, ServiceGroup | ServiceEntry]) ->
|
|
|
692
646
|
name=root_name,
|
|
693
647
|
site=f"services.{root_name}",
|
|
694
648
|
entry=member,
|
|
695
|
-
effective_routes=member.routes,
|
|
696
649
|
effective_ports=member.ports,
|
|
697
650
|
auth=root_name == AUTH_GROUP_NAME,
|
|
698
651
|
)
|
|
@@ -752,12 +705,7 @@ def artifact_slots(texts: list[str]) -> dict[str, Slot]:
|
|
|
752
705
|
return slots
|
|
753
706
|
|
|
754
707
|
|
|
755
|
-
def
|
|
756
|
-
entry_name: str,
|
|
757
|
-
routes: list[Route],
|
|
758
|
-
ports: list[PublishedPort],
|
|
759
|
-
texts: list[str],
|
|
760
|
-
) -> set[str]:
|
|
708
|
+
def artifact_service_names(texts: list[str]) -> set[str]:
|
|
761
709
|
# Union the services keys across the texts
|
|
762
710
|
service_names: set[str] = set()
|
|
763
711
|
for text in texts:
|
|
@@ -765,6 +713,15 @@ def refuse_unresolved_references(
|
|
|
765
713
|
services = document.get("services") if is_mapping(document) else None
|
|
766
714
|
if is_mapping(services):
|
|
767
715
|
service_names.update(services)
|
|
716
|
+
return service_names
|
|
717
|
+
|
|
718
|
+
|
|
719
|
+
def refuse_unresolved_references(
|
|
720
|
+
entry_name: str,
|
|
721
|
+
routes: list[Route],
|
|
722
|
+
ports: list[PublishedPort],
|
|
723
|
+
service_names: set[str],
|
|
724
|
+
) -> None:
|
|
768
725
|
references = {route.upstream.partition(":")[0]: route.path for route in routes}
|
|
769
726
|
references.update({port.service: str(port.published) for port in ports})
|
|
770
727
|
unknown = sorted(name for name in references if name not in service_names)
|
|
@@ -774,7 +731,6 @@ def refuse_unresolved_references(
|
|
|
774
731
|
f"services entry {entry_name!r}: {references[name]!r} references {name!r}, "
|
|
775
732
|
f"which resolves to no service in the bundle (services: {sorted(service_names)})"
|
|
776
733
|
)
|
|
777
|
-
return service_names
|
|
778
734
|
|
|
779
735
|
|
|
780
736
|
def mirrored_ref(reference: str, prefix: str) -> str:
|
|
@@ -20,11 +20,14 @@ DOCKERFILE_ANNOTATION = "boatyard/dockerfile"
|
|
|
20
20
|
AUTOSTART_ANNOTATION = "boatyard/autostart"
|
|
21
21
|
LOCK_ANNOTATION = "boatyard/lock"
|
|
22
22
|
ROUTE_ANNOTATION = "boatyard/route"
|
|
23
|
+
ROUTE_PORT_ANNOTATION = "boatyard/port"
|
|
23
24
|
PUBLISH_PORT_ANNOTATION = "boatyard/publish-port"
|
|
24
25
|
|
|
25
26
|
ROUTE_PATH_PATTERN = re.compile(r"(?:/\*|/(?:[^/\s*]+(?:/[^/\s*]+)*)?(?:/\*)?)")
|
|
26
27
|
|
|
27
|
-
|
|
28
|
+
ROUTE_PORT_NAME_PATTERN = re.compile(r"[a-zA-Z0-9][a-zA-Z0-9_.-]*")
|
|
29
|
+
|
|
30
|
+
ROUTE_PATH_EXPORT_SUFFIX = "ROUTE_PATH"
|
|
28
31
|
|
|
29
32
|
PUBLISH_PORT_PROTOCOLS: tuple[Literal["tcp", "udp"], ...] = ("tcp", "udp")
|
|
30
33
|
|
|
@@ -39,6 +42,7 @@ class WorkloadDocument(BaseModel):
|
|
|
39
42
|
metadata: WorkloadMetadata = Field(default_factory=_default_metadata)
|
|
40
43
|
containers: dict[str, WorkloadContainer] = Field(default_factory=dict)
|
|
41
44
|
resources: dict[str, WorkloadResource] = Field(default_factory=dict)
|
|
45
|
+
service: WorkloadService | None = None
|
|
42
46
|
|
|
43
47
|
@classmethod
|
|
44
48
|
def parse(cls, raw: Yaml, file_name: str) -> Self:
|
|
@@ -63,7 +67,7 @@ class WorkloadDocument(BaseModel):
|
|
|
63
67
|
|
|
64
68
|
route = annotations.get(ROUTE_ANNOTATION)
|
|
65
69
|
if route is not None:
|
|
66
|
-
parse_route_annotation(route)
|
|
70
|
+
resolve_route_port(parse_route_annotation(route), self.service_ports)
|
|
67
71
|
|
|
68
72
|
publish_port = annotations.get(PUBLISH_PORT_ANNOTATION)
|
|
69
73
|
if publish_port is not None:
|
|
@@ -121,9 +125,20 @@ class WorkloadDocument(BaseModel):
|
|
|
121
125
|
return annotation.split(",") if annotation is not None else []
|
|
122
126
|
|
|
123
127
|
@property
|
|
124
|
-
def
|
|
128
|
+
def service_ports(self) -> dict[str, int | WorkloadPortSpec]:
|
|
129
|
+
return self.service.ports if self.service is not None else {}
|
|
130
|
+
|
|
131
|
+
@property
|
|
132
|
+
def resolved_route(self) -> ResolvedRoute | None:
|
|
125
133
|
annotation = self.metadata.annotations.get(ROUTE_ANNOTATION)
|
|
126
|
-
|
|
134
|
+
if annotation is None:
|
|
135
|
+
return None
|
|
136
|
+
claim = parse_route_annotation(annotation)
|
|
137
|
+
return ResolvedRoute(
|
|
138
|
+
path=claim.path,
|
|
139
|
+
port=resolve_route_port(claim, self.service_ports),
|
|
140
|
+
strip_prefix=claim.strip_prefix,
|
|
141
|
+
)
|
|
127
142
|
|
|
128
143
|
@property
|
|
129
144
|
def published_ports(self) -> list[WorkloadPublishedPort]:
|
|
@@ -216,6 +231,19 @@ class WorkloadResource(BaseModel):
|
|
|
216
231
|
type: str
|
|
217
232
|
|
|
218
233
|
|
|
234
|
+
class WorkloadPortSpec(BaseModel):
|
|
235
|
+
model_config = ConfigDict(extra="allow")
|
|
236
|
+
|
|
237
|
+
port: int
|
|
238
|
+
target_port: int | None = Field(default=None, alias="targetPort")
|
|
239
|
+
|
|
240
|
+
|
|
241
|
+
class WorkloadService(BaseModel):
|
|
242
|
+
model_config = ConfigDict(extra="allow")
|
|
243
|
+
|
|
244
|
+
ports: dict[str, int | WorkloadPortSpec] = Field(default_factory=dict)
|
|
245
|
+
|
|
246
|
+
|
|
219
247
|
class WorkloadProbe(BaseModel):
|
|
220
248
|
model_config = ConfigDict(extra="allow")
|
|
221
249
|
|
|
@@ -245,9 +273,15 @@ class LoadedWorkload(NamedTuple):
|
|
|
245
273
|
return cls(path.name, text, raw, document)
|
|
246
274
|
|
|
247
275
|
|
|
248
|
-
class
|
|
276
|
+
class RouteClaim(NamedTuple):
|
|
277
|
+
path: str
|
|
278
|
+
port_name: str | None
|
|
279
|
+
strip_prefix: bool = False
|
|
280
|
+
|
|
281
|
+
|
|
282
|
+
class ResolvedRoute(NamedTuple):
|
|
249
283
|
path: str
|
|
250
|
-
|
|
284
|
+
port: int
|
|
251
285
|
strip_prefix: bool = False
|
|
252
286
|
|
|
253
287
|
|
|
@@ -288,29 +322,67 @@ def select_provisioner_files(
|
|
|
288
322
|
return [(name, selected[name]) for name in sorted(selected)]
|
|
289
323
|
|
|
290
324
|
|
|
291
|
-
def parse_route_annotation(value: str) ->
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
325
|
+
def parse_route_annotation(value: str) -> RouteClaim:
|
|
326
|
+
entries = value.split(",")
|
|
327
|
+
strip_prefix = False
|
|
328
|
+
if entries[-1].strip() == "strip":
|
|
329
|
+
strip_prefix = True
|
|
330
|
+
entries = entries[:-1]
|
|
331
|
+
if len(entries) != 1:
|
|
332
|
+
raise ValueError(f"{ROUTE_ANNOTATION} claims exactly one path, plus an optional ', strip' entry")
|
|
333
|
+
claim = entries[0]
|
|
334
|
+
if not claim or claim != claim.strip():
|
|
335
|
+
raise ValueError(f"{ROUTE_ANNOTATION} entry {claim!r} must be non-empty and unpadded")
|
|
336
|
+
if "=" in claim:
|
|
337
|
+
raise ValueError(
|
|
338
|
+
f"{ROUTE_ANNOTATION} entry {claim!r}: the path=host:port route table grammar is removed; "
|
|
339
|
+
"claim one path, with an optional @port-name qualifier and an optional ', strip' entry"
|
|
340
|
+
)
|
|
341
|
+
path, separator, port_name = claim.partition("@")
|
|
342
|
+
if ROUTE_PATH_PATTERN.fullmatch(path) is None:
|
|
343
|
+
raise ValueError(f"{ROUTE_ANNOTATION} path {path!r} must be a /-rooted segment chain, optionally wildcarded")
|
|
344
|
+
if separator and ROUTE_PORT_NAME_PATTERN.fullmatch(port_name) is None:
|
|
345
|
+
raise ValueError(f"{ROUTE_ANNOTATION} port qualifier {port_name!r} must be a plain port name")
|
|
346
|
+
if strip_prefix and not path.endswith("/*"):
|
|
347
|
+
raise ValueError(f"{ROUTE_ANNOTATION}: strip requires the path to end in /* ({path})")
|
|
348
|
+
return RouteClaim(path=path, port_name=port_name if separator else None, strip_prefix=strip_prefix)
|
|
349
|
+
|
|
350
|
+
|
|
351
|
+
def resolve_route_port(claim: RouteClaim, ports: dict[str, int | WorkloadPortSpec]) -> int:
|
|
352
|
+
if not ports:
|
|
353
|
+
raise ValueError(
|
|
354
|
+
f"{ROUTE_ANNOTATION} claims {claim.path} but the workload declares no service.ports stanza; "
|
|
355
|
+
"add the listen port the claim resolves against"
|
|
356
|
+
)
|
|
357
|
+
if claim.port_name is None:
|
|
358
|
+
if len(ports) != 1:
|
|
307
359
|
raise ValueError(
|
|
308
|
-
f"{ROUTE_ANNOTATION}
|
|
360
|
+
f"{ROUTE_ANNOTATION} claims {claim.path} with no port qualifier but service.ports declares "
|
|
361
|
+
f"several ({', '.join(sorted(ports))}); name one with the @ qualifier"
|
|
309
362
|
)
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
|
|
363
|
+
return listen_port(next(iter(ports.values())))
|
|
364
|
+
if claim.port_name not in ports:
|
|
365
|
+
raise ValueError(
|
|
366
|
+
f"{ROUTE_ANNOTATION} port qualifier @{claim.port_name} names no service.ports entry "
|
|
367
|
+
f"({', '.join(sorted(ports))})"
|
|
368
|
+
)
|
|
369
|
+
return listen_port(ports[claim.port_name])
|
|
370
|
+
|
|
371
|
+
|
|
372
|
+
def listen_port(spec: int | WorkloadPortSpec) -> int:
|
|
373
|
+
if isinstance(spec, WorkloadPortSpec):
|
|
374
|
+
return spec.target_port if spec.target_port is not None else spec.port
|
|
375
|
+
return spec
|
|
376
|
+
|
|
377
|
+
|
|
378
|
+
def parse_route_port_annotation(value: str) -> int:
|
|
379
|
+
if value.isdigit() and 1 <= int(value) <= 65535:
|
|
380
|
+
return int(value)
|
|
381
|
+
raise ValueError(f"{ROUTE_PORT_ANNOTATION} {value!r} must be a literal port in the range 1-65535")
|
|
382
|
+
|
|
383
|
+
|
|
384
|
+
def route_path_export_name(workload_name: str) -> str:
|
|
385
|
+
return workload_name.upper().replace("-", "_") + "_" + ROUTE_PATH_EXPORT_SUFFIX
|
|
314
386
|
|
|
315
387
|
|
|
316
388
|
def parse_publish_port_annotation(value: str) -> list[WorkloadPublishedPort]:
|
|
@@ -16,6 +16,7 @@ from boatyard.models.config_file import (
|
|
|
16
16
|
PublishedPort,
|
|
17
17
|
Route,
|
|
18
18
|
Slot,
|
|
19
|
+
artifact_service_names,
|
|
19
20
|
artifact_slots,
|
|
20
21
|
bundle_lock_key,
|
|
21
22
|
compose_bundle_output_path,
|
|
@@ -44,7 +45,7 @@ class BundleProject(NamedTuple):
|
|
|
44
45
|
bundle_path: Path | None
|
|
45
46
|
pinned_reference: str | None
|
|
46
47
|
services: list[str]
|
|
47
|
-
|
|
48
|
+
routes: list[Route]
|
|
48
49
|
effective_ports: list[PublishedPort]
|
|
49
50
|
container_names: list[str]
|
|
50
51
|
held_services: list[str]
|
|
@@ -195,8 +196,7 @@ def resolve(config: ConfigFile, lock: LockFile, values: ValuesFile) -> AssemblyP
|
|
|
195
196
|
bundle_path = paths[name]
|
|
196
197
|
pinned_reference = None
|
|
197
198
|
|
|
198
|
-
# If config declarations exist, they replace the adopted set wholesale
|
|
199
|
-
effective_routes = list(row.effective_routes) if row.effective_routes else adopted_routes
|
|
199
|
+
# If config port declarations exist, they replace the adopted set wholesale
|
|
200
200
|
effective_ports = list(row.effective_ports) if row.effective_ports else adopted_ports
|
|
201
201
|
|
|
202
202
|
bundles.append(
|
|
@@ -206,7 +206,7 @@ def resolve(config: ConfigFile, lock: LockFile, values: ValuesFile) -> AssemblyP
|
|
|
206
206
|
bundle_path=bundle_path,
|
|
207
207
|
pinned_reference=pinned_reference,
|
|
208
208
|
services=adopted_services,
|
|
209
|
-
|
|
209
|
+
routes=adopted_routes,
|
|
210
210
|
effective_ports=effective_ports,
|
|
211
211
|
container_names=adopted_container_names,
|
|
212
212
|
held_services=adopted_held_services,
|
|
@@ -248,22 +248,23 @@ def resolve(config: ConfigFile, lock: LockFile, values: ValuesFile) -> AssemblyP
|
|
|
248
248
|
# Raise if an artifact references a service it does not define
|
|
249
249
|
for bundle in bundles:
|
|
250
250
|
if bundle.bundle_path is None:
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
251
|
+
# A remote winner's adopted routes must reference its locked service set
|
|
252
|
+
service_names = set(bundle.services)
|
|
253
|
+
else:
|
|
254
|
+
service_names = artifact_service_names([texts[bundle.entry_name]])
|
|
255
|
+
refuse_unresolved_references(bundle.entry_name, bundle.routes, bundle.effective_ports, service_names)
|
|
255
256
|
|
|
256
257
|
# If the bundle defines the reserved gateway service, refuse
|
|
257
258
|
if GATEWAY_SERVICE_NAME in service_names:
|
|
258
259
|
raise ValueError(
|
|
259
|
-
f"{bundle.bundle_path.as_posix()
|
|
260
|
-
f"{GATEWAY_SERVICE_NAME!r}"
|
|
260
|
+
f"{bundle.bundle_path.as_posix() if bundle.bundle_path is not None else bundle.pinned_reference}: "
|
|
261
|
+
f"the included bundle defines the reserved service {GATEWAY_SERVICE_NAME!r}"
|
|
261
262
|
)
|
|
262
263
|
|
|
263
264
|
# Validate the combined declarations across winners
|
|
264
265
|
path_claims: dict[str, str] = {}
|
|
265
266
|
for bundle in bundles:
|
|
266
|
-
for route in bundle.
|
|
267
|
+
for route in bundle.routes:
|
|
267
268
|
# If two winners claim one route path, refuse
|
|
268
269
|
if route.path in path_claims:
|
|
269
270
|
raise ValueError(
|
|
@@ -272,13 +273,6 @@ def resolve(config: ConfigFile, lock: LockFile, values: ValuesFile) -> AssemblyP
|
|
|
272
273
|
)
|
|
273
274
|
path_claims[route.path] = bundle.entry_name
|
|
274
275
|
|
|
275
|
-
# Require the selected auth option to carry exactly one effective route
|
|
276
|
-
for row in service_entries:
|
|
277
|
-
if row.name in winners and row.auth:
|
|
278
|
-
selected = next(bundle for bundle in bundles if bundle.entry_name == row.name)
|
|
279
|
-
if len(selected.effective_routes) != 1:
|
|
280
|
-
raise ValueError(f"{source}: the selected auth option {row.name!r} carries exactly one effective route")
|
|
281
|
-
|
|
282
276
|
# If routes exist but no gateway is declared, refuse
|
|
283
277
|
if path_claims and config.gateway_port is None:
|
|
284
278
|
raise ValueError(f"{source}: effective routes require a gateway declaration")
|
|
@@ -346,10 +340,13 @@ def resolve(config: ConfigFile, lock: LockFile, values: ValuesFile) -> AssemblyP
|
|
|
346
340
|
parts = PLACEHOLDER.split(hand[name])
|
|
347
341
|
env[name] = "".join(part if index % 2 == 0 else env[part] for index, part in enumerate(parts))
|
|
348
342
|
|
|
349
|
-
# If a gateway is declared, plan it over the winners' routes
|
|
343
|
+
# If a gateway is declared, plan it over the winners' routes in specificity order
|
|
350
344
|
gateway = None
|
|
351
345
|
if config.gateway_port is not None:
|
|
352
|
-
routes =
|
|
346
|
+
routes = sorted(
|
|
347
|
+
((bundle.entry_name, route) for bundle in bundles for route in bundle.routes),
|
|
348
|
+
key=lambda pair: route_specificity(pair[1]),
|
|
349
|
+
)
|
|
353
350
|
gateway = GatewayPlan(
|
|
354
351
|
port=values.gateway_port if values.gateway_port is not None else config.gateway_port,
|
|
355
352
|
public_face=public_face,
|
|
@@ -404,6 +401,13 @@ def _in_assembly(row: FlattenedServiceEntry, choices: dict[str, str]) -> bool:
|
|
|
404
401
|
return row.option is None or row.option == choices.get(row.root)
|
|
405
402
|
|
|
406
403
|
|
|
404
|
+
def route_specificity(route: Route) -> tuple[int, int, str]:
|
|
405
|
+
# Longest concrete prefix first, an exact path before its own wildcard, then the spelling for determinism
|
|
406
|
+
wildcard = route.path.endswith("/*")
|
|
407
|
+
concrete = route.path.removesuffix("/*")
|
|
408
|
+
return (-len(concrete), 1 if wildcard else 0, route.path)
|
|
409
|
+
|
|
410
|
+
|
|
407
411
|
def _entry_env(env: dict[str, str], shas_by_root: dict[Path, dict[str, str]], sources: BundleSources) -> None:
|
|
408
412
|
# Spell machine slots after the producer's entry name, not the consumer's
|
|
409
413
|
entry = sources.bundle_path.stem.removeprefix("compose.")
|