datadouble 0.0.5__tar.gz → 0.0.7__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 (89) hide show
  1. {datadouble-0.0.5 → datadouble-0.0.7}/PKG-INFO +1 -1
  2. {datadouble-0.0.5 → datadouble-0.0.7}/src/datadouble/api.py +39 -3
  3. {datadouble-0.0.5 → datadouble-0.0.7}/src/datadouble/ci.py +166 -8
  4. {datadouble-0.0.5 → datadouble-0.0.7}/src/datadouble/cli.py +54 -4
  5. {datadouble-0.0.5 → datadouble-0.0.7}/src/datadouble/prune.py +229 -31
  6. {datadouble-0.0.5 → datadouble-0.0.7}/src/datadouble/run.py +181 -28
  7. {datadouble-0.0.5 → datadouble-0.0.7}/src/datadouble/spec.py +7 -4
  8. {datadouble-0.0.5 → datadouble-0.0.7}/src/datadouble/verify.py +7 -5
  9. {datadouble-0.0.5 → datadouble-0.0.7}/tests/test_ci.py +128 -2
  10. {datadouble-0.0.5 → datadouble-0.0.7}/tests/test_commands_operations.py +6 -0
  11. datadouble-0.0.7/tests/test_prune_work.py +319 -0
  12. {datadouble-0.0.5 → datadouble-0.0.7}/tests/test_run.py +101 -0
  13. {datadouble-0.0.5 → datadouble-0.0.7}/.gitignore +0 -0
  14. {datadouble-0.0.5 → datadouble-0.0.7}/LICENSE +0 -0
  15. {datadouble-0.0.5 → datadouble-0.0.7}/README.md +0 -0
  16. {datadouble-0.0.5 → datadouble-0.0.7}/pyproject.toml +0 -0
  17. {datadouble-0.0.5 → datadouble-0.0.7}/src/datadouble/__init__.py +0 -0
  18. {datadouble-0.0.5 → datadouble-0.0.7}/src/datadouble/announce.py +0 -0
  19. {datadouble-0.0.5 → datadouble-0.0.7}/src/datadouble/anonymize.py +0 -0
  20. {datadouble-0.0.5 → datadouble-0.0.7}/src/datadouble/boundary.py +0 -0
  21. {datadouble-0.0.5 → datadouble-0.0.7}/src/datadouble/catalog.py +0 -0
  22. {datadouble-0.0.5 → datadouble-0.0.7}/src/datadouble/channels.py +0 -0
  23. {datadouble-0.0.5 → datadouble-0.0.7}/src/datadouble/closure.py +0 -0
  24. {datadouble-0.0.5 → datadouble-0.0.7}/src/datadouble/discover.py +0 -0
  25. {datadouble-0.0.5 → datadouble-0.0.7}/src/datadouble/engine.py +0 -0
  26. {datadouble-0.0.5 → datadouble-0.0.7}/src/datadouble/files.py +0 -0
  27. {datadouble-0.0.5 → datadouble-0.0.7}/src/datadouble/images.py +0 -0
  28. {datadouble-0.0.5 → datadouble-0.0.7}/src/datadouble/jailer.py +0 -0
  29. {datadouble-0.0.5 → datadouble-0.0.7}/src/datadouble/jsonpath.py +0 -0
  30. {datadouble-0.0.5 → datadouble-0.0.7}/src/datadouble/locales/__init__.py +0 -0
  31. {datadouble-0.0.5 → datadouble-0.0.7}/src/datadouble/locales/base.py +0 -0
  32. {datadouble-0.0.5 → datadouble-0.0.7}/src/datadouble/locales/data/first_names.txt +0 -0
  33. {datadouble-0.0.5 → datadouble-0.0.7}/src/datadouble/locales/data/sources.txt +0 -0
  34. {datadouble-0.0.5 → datadouble-0.0.7}/src/datadouble/locales/data/streets.txt +0 -0
  35. {datadouble-0.0.5 → datadouble-0.0.7}/src/datadouble/locales/data/surnames.txt +0 -0
  36. {datadouble-0.0.5 → datadouble-0.0.7}/src/datadouble/locales/gb.py +0 -0
  37. {datadouble-0.0.5 → datadouble-0.0.7}/src/datadouble/locales/us.py +0 -0
  38. {datadouble-0.0.5 → datadouble-0.0.7}/src/datadouble/locales/vocabulary.py +0 -0
  39. {datadouble-0.0.5 → datadouble-0.0.7}/src/datadouble/names.py +0 -0
  40. {datadouble-0.0.5 → datadouble-0.0.7}/src/datadouble/notify.py +0 -0
  41. {datadouble-0.0.5 → datadouble-0.0.7}/src/datadouble/objects.py +0 -0
  42. {datadouble-0.0.5 → datadouble-0.0.7}/src/datadouble/outcome.py +0 -0
  43. {datadouble-0.0.5 → datadouble-0.0.7}/src/datadouble/pii.py +0 -0
  44. {datadouble-0.0.5 → datadouble-0.0.7}/src/datadouble/planner.py +0 -0
  45. {datadouble-0.0.5 → datadouble-0.0.7}/src/datadouble/programs.py +0 -0
  46. {datadouble-0.0.5 → datadouble-0.0.7}/src/datadouble/progress.py +0 -0
  47. {datadouble-0.0.5 → datadouble-0.0.7}/src/datadouble/promote.py +0 -0
  48. {datadouble-0.0.5 → datadouble-0.0.7}/src/datadouble/py.typed +0 -0
  49. {datadouble-0.0.5 → datadouble-0.0.7}/src/datadouble/redaction.py +0 -0
  50. {datadouble-0.0.5 → datadouble-0.0.7}/src/datadouble/registry.py +0 -0
  51. {datadouble-0.0.5 → datadouble-0.0.7}/src/datadouble/replicate.py +0 -0
  52. {datadouble-0.0.5 → datadouble-0.0.7}/src/datadouble/resolve.py +0 -0
  53. {datadouble-0.0.5 → datadouble-0.0.7}/src/datadouble/runtime.py +0 -0
  54. {datadouble-0.0.5 → datadouble-0.0.7}/src/datadouble/secrets.py +0 -0
  55. {datadouble-0.0.5 → datadouble-0.0.7}/src/datadouble/settings.py +0 -0
  56. {datadouble-0.0.5 → datadouble-0.0.7}/src/datadouble/signing.py +0 -0
  57. {datadouble-0.0.5 → datadouble-0.0.7}/src/datadouble/staging.py +0 -0
  58. {datadouble-0.0.5 → datadouble-0.0.7}/src/datadouble/storage.py +0 -0
  59. {datadouble-0.0.5 → datadouble-0.0.7}/src/datadouble/strict.py +0 -0
  60. {datadouble-0.0.5 → datadouble-0.0.7}/src/datadouble/subset.py +0 -0
  61. {datadouble-0.0.5 → datadouble-0.0.7}/src/datadouble/versions.py +0 -0
  62. {datadouble-0.0.5 → datadouble-0.0.7}/tests/conftest.py +0 -0
  63. {datadouble-0.0.5 → datadouble-0.0.7}/tests/fake_engine.py +0 -0
  64. {datadouble-0.0.5 → datadouble-0.0.7}/tests/fakes.py +0 -0
  65. {datadouble-0.0.5 → datadouble-0.0.7}/tests/test_anonymize_pii.py +0 -0
  66. {datadouble-0.0.5 → datadouble-0.0.7}/tests/test_api.py +0 -0
  67. {datadouble-0.0.5 → datadouble-0.0.7}/tests/test_catalog.py +0 -0
  68. {datadouble-0.0.5 → datadouble-0.0.7}/tests/test_cli.py +0 -0
  69. {datadouble-0.0.5 → datadouble-0.0.7}/tests/test_closure.py +0 -0
  70. {datadouble-0.0.5 → datadouble-0.0.7}/tests/test_commands.py +0 -0
  71. {datadouble-0.0.5 → datadouble-0.0.7}/tests/test_discover.py +0 -0
  72. {datadouble-0.0.5 → datadouble-0.0.7}/tests/test_extends.py +0 -0
  73. {datadouble-0.0.5 → datadouble-0.0.7}/tests/test_files.py +0 -0
  74. {datadouble-0.0.5 → datadouble-0.0.7}/tests/test_jailer.py +0 -0
  75. {datadouble-0.0.5 → datadouble-0.0.7}/tests/test_jsonpath.py +0 -0
  76. {datadouble-0.0.5 → datadouble-0.0.7}/tests/test_locales.py +0 -0
  77. {datadouble-0.0.5 → datadouble-0.0.7}/tests/test_notify.py +0 -0
  78. {datadouble-0.0.5 → datadouble-0.0.7}/tests/test_objects.py +0 -0
  79. {datadouble-0.0.5 → datadouble-0.0.7}/tests/test_operations.py +0 -0
  80. {datadouble-0.0.5 → datadouble-0.0.7}/tests/test_planner.py +0 -0
  81. {datadouble-0.0.5 → datadouble-0.0.7}/tests/test_programs.py +0 -0
  82. {datadouble-0.0.5 → datadouble-0.0.7}/tests/test_progress.py +0 -0
  83. {datadouble-0.0.5 → datadouble-0.0.7}/tests/test_redaction.py +0 -0
  84. {datadouble-0.0.5 → datadouble-0.0.7}/tests/test_resolve_strict.py +0 -0
  85. {datadouble-0.0.5 → datadouble-0.0.7}/tests/test_runtime.py +0 -0
  86. {datadouble-0.0.5 → datadouble-0.0.7}/tests/test_spec.py +0 -0
  87. {datadouble-0.0.5 → datadouble-0.0.7}/tests/test_storage_images.py +0 -0
  88. {datadouble-0.0.5 → datadouble-0.0.7}/tests/test_subset.py +0 -0
  89. {datadouble-0.0.5 → datadouble-0.0.7}/tests/test_transform.py +0 -0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.5
2
2
  Name: datadouble
3
- Version: 0.0.5
3
+ Version: 0.0.7
4
4
  Summary: Realistic, safe copies of production data for development and testing
5
5
  Project-URL: Homepage, https://datadouble.tightlinesoftware.com/
6
6
  Project-URL: Source, https://github.com/datadouble/datadouble
@@ -76,7 +76,14 @@ from datadouble.planner import (
76
76
  plan,
77
77
  )
78
78
  from datadouble.promote import Promoted, PromoteError, promote
79
- from datadouble.prune import PruneError, PruneResult, PruneTarget, prune
79
+ from datadouble.prune import (
80
+ DEFAULT_WORK,
81
+ PruneError,
82
+ PruneResult,
83
+ PruneTarget,
84
+ prune,
85
+ prune_work,
86
+ )
80
87
  from datadouble.registry import Registry, RegistryError, installed
81
88
  from datadouble.replicate import (
82
89
  Copy,
@@ -399,13 +406,23 @@ class CopiesRequest(_Groups):
399
406
 
400
407
 
401
408
  class PruneRequest(_Request):
402
- """Apply retention to the build's stores, the export stores, or staging."""
409
+ """Apply retention to the build's stores, the export stores, staging, or the work directory."""
403
410
 
404
411
  command: Literal[Command.PRUNE]
405
412
  spec: Path
406
413
  target: PruneTarget
414
+ work: Path | None = None
415
+ """The build's work directory, whose old generations ``work`` removes
416
+ (default: ``.datadouble``); only for that target."""
407
417
  dry_run: bool = False
408
418
 
419
+ @model_validator(mode="after")
420
+ def _work_only_for_work(self) -> "PruneRequest":
421
+ if self.work is not None and self.target is not PruneTarget.WORK:
422
+ message = "work names the work directory, which only target work prunes"
423
+ raise ValueError(message)
424
+ return self
425
+
409
426
 
410
427
  class CiInitRequest(_Request):
411
428
  """Write one side's CI/CD configuration for a spec's jobs."""
@@ -445,6 +462,12 @@ class CiInitRequest(_Request):
445
462
  beside the ``kubernetes`` runtime's); the system's default when unset."""
446
463
  cloud: str | None = None
447
464
  """The Kubernetes cloud a system's Kubernetes agents start in; its default when unset."""
465
+ service_account: str | None = None
466
+ """An existing service account, a Kubernetes object name, that Kubernetes agents' pods
467
+ run as, such as one an administrator manages for the side. ``ci init`` then names it in
468
+ the pods and in its setup steps, and the Argo CD chart creates no account or RBAC of
469
+ its own. When unset, the pods run as ``datadouble-<spec>-<side>``, which the setup
470
+ steps (Jenkins) or the chart (Argo CD) create. Docker agents refuse it."""
448
471
  spec_source: SpecSource = SpecSourceKind.CHECKOUT
449
472
  """Where jobs find the spec's directory (the spec, the specs it extends, its lock):
450
473
  ``checkout``, the CI system's checkout of this repository; ``{"mounted": {"path": ...,
@@ -459,6 +482,13 @@ class CiInitRequest(_Request):
459
482
  """The Git URL of a mirror of this repository, holding the release's tag, which the
460
483
  jobs load Datadouble's own CI code from at run time: the Jenkins shared library, or
461
484
  the Argo CD chart. The public repository when unset; other systems refuse it."""
485
+ host_paths: dict[str, str] = Field(default_factory=dict[str, str])
486
+ """Directories a Docker agent binds from elsewhere on the runner: each key is a
487
+ directory as the spec names it, and its value the same directory on the runner. Every
488
+ path a job mounts under a key comes from the same place under its value, and the job
489
+ still sees it at the spec's path. Absolute directories other than ``/``, none inside
490
+ another key; only for ``docker`` agents, and never for a path a job hands to engine
491
+ containers on the ``docker`` runtime."""
462
492
 
463
493
 
464
494
  type Request = (
@@ -1023,6 +1053,7 @@ def _ci_init(request: CiInitRequest, registry: Registry) -> CiInitResponse:
1023
1053
  docker_socket=request.docker_socket,
1024
1054
  agent=agent,
1025
1055
  cloud=request.cloud,
1056
+ service_account=request.service_account,
1026
1057
  remote=registry.remote_settings(),
1027
1058
  spec_files=tuple(
1028
1059
  (layer.path.as_posix(), (loaded.directory / layer.path).read_text(encoding="utf-8"))
@@ -1032,6 +1063,7 @@ def _ci_init(request: CiInitRequest, registry: Registry) -> CiInitResponse:
1032
1063
  spec_source=request.spec_source,
1033
1064
  manual=request.manual,
1034
1065
  library_remote=request.library_remote,
1066
+ host_paths=tuple(request.host_paths.items()),
1035
1067
  )
1036
1068
  planned = pipeline(spec, options)
1037
1069
  if planned.identity_token and not adapter.identity_token:
@@ -1071,7 +1103,11 @@ def _operate(request: Request, registry: Registry) -> Response:
1071
1103
  )
1072
1104
  case PruneRequest():
1073
1105
  spec = load_spec(request.spec)
1074
- result = prune(spec, registry, request.target, dry_run=request.dry_run)
1106
+ if request.target is PruneTarget.WORK:
1107
+ work = request.work or DEFAULT_WORK
1108
+ result = prune_work(spec, registry, work, dry_run=request.dry_run)
1109
+ else:
1110
+ result = prune(spec, registry, request.target, dry_run=request.dry_run)
1075
1111
  return PruneResponse(result=result, bytes=result.bytes)
1076
1112
  case CiInitRequest():
1077
1113
  return _ci_init(request, registry)
@@ -298,7 +298,8 @@ class Job:
298
298
  """Values the person starting the job by hand gives."""
299
299
  timeout_minutes: int = 60
300
300
  mounts: tuple[str, ...] = ()
301
- """Host paths the job's container sees at the same path."""
301
+ """Paths the job's container sees: on a Docker agent, host paths at the same path,
302
+ unless a :class:`HostPath` maps them (:func:`binds`)."""
302
303
  environment: tuple[str, ...] = ()
303
304
  """Environment variables the job reads secrets from, by name."""
304
305
  artifacts: str | None = None
@@ -307,6 +308,26 @@ class Job:
307
308
  publishes it; the job never commits anything."""
308
309
 
309
310
 
311
+ @dataclass(frozen=True, slots=True)
312
+ class HostPath:
313
+ """A directory a Docker agent binds from another place on the host (``ci init --host-path``).
314
+
315
+ Every mount under ``container`` comes from the same place under ``host``,
316
+ and the job still sees it at the spec's path.
317
+ """
318
+
319
+ container: str
320
+ host: str
321
+
322
+ def source(self, path: str) -> str | None:
323
+ """Where ``path`` is on the host, if it is under ``container``; None otherwise."""
324
+ if not PurePosixPath(path).is_relative_to(self.container):
325
+ return None
326
+ return (
327
+ PurePosixPath(self.host) / PurePosixPath(path).relative_to(self.container)
328
+ ).as_posix()
329
+
330
+
310
331
  @dataclass(frozen=True, slots=True)
311
332
  class Pipeline:
312
333
  """Everything a CI/CD adapter needs to write one side's jobs for a spec."""
@@ -345,6 +366,9 @@ class Pipeline:
345
366
  """Where the jobs run Datadouble."""
346
367
  cloud: str | None = None
347
368
  """The Kubernetes cloud Kubernetes agents' pods start in; None for the system's default."""
369
+ service_account: str | None = None
370
+ """The existing service account Kubernetes agents' pods run as, which someone else
371
+ manages; None for the system's own, named after the spec and side."""
348
372
  runtime: Mapping[str, JsonValue] | None = None
349
373
  """The spec's ``runtime`` section, for systems whose jobs run beside its pods."""
350
374
  spec_source: SpecSource = SpecSourceKind.CHECKOUT
@@ -358,6 +382,8 @@ class Pipeline:
358
382
  library_remote: str | None = None
359
383
  """A Git URL of a mirror of this repository, which jobs load Datadouble's own CI code
360
384
  from at run time (the Jenkins library, the Argo CD chart); None for the public one."""
385
+ host_paths: tuple[HostPath, ...] = ()
386
+ """Directories a Docker agent binds from elsewhere on the host (:func:`binds`)."""
361
387
 
362
388
  def environment(self) -> tuple[str, ...]:
363
389
  """Every secret the jobs read by name.
@@ -729,11 +755,12 @@ class _Context:
729
755
  model: Spec
730
756
  side: Side
731
757
  chosen: frozenset[JobKind]
732
- work: str
758
+ work: str | None
759
+ """The build's work directory, as an absolute path, when ``ci init`` was given one."""
733
760
 
734
761
 
735
762
  def _build(context: _Context) -> Job:
736
- arguments = ("run", _STAGES, "--spec", context.spec, "--work", context.work)
763
+ arguments = ("run", _STAGES, "--spec", context.spec, "--work", str(context.work))
737
764
  return Job(
738
765
  JobKind.BUILD,
739
766
  (Trigger.SCHEDULE, Trigger.MANUAL),
@@ -802,13 +829,18 @@ def _release(context: _Context) -> Job:
802
829
 
803
830
 
804
831
  def _prune(context: _Context) -> Job:
832
+ """Prune each of the side's targets; in production, also the work directory, if known."""
833
+ invocations = [
834
+ Invocation(("prune", "--spec", context.spec, "--target", target, Placeholder.DRY_RUN))
835
+ for target in _PRUNE_TARGETS[context.side]
836
+ ]
837
+ if context.side is Side.PRODUCTION and context.work is not None:
838
+ arguments = ("prune", "--spec", context.spec, "--target", "work", "--work", context.work)
839
+ invocations.append(Invocation((*arguments, Placeholder.DRY_RUN)))
805
840
  return Job(
806
841
  JobKind.PRUNE,
807
842
  (Trigger.SCHEDULE, Trigger.MANUAL),
808
- tuple(
809
- Invocation(("prune", "--spec", context.spec, "--target", target, Placeholder.DRY_RUN))
810
- for target in _PRUNE_TARGETS[context.side]
811
- ),
843
+ tuple(invocations),
812
844
  schedule="0 4 * * *",
813
845
  parameters=(Placeholder.DRY_RUN,),
814
846
  )
@@ -876,6 +908,9 @@ class PipelineOptions:
876
908
  """The Docker daemon's socket native steps use, written into the configuration."""
877
909
  agent: Agent = Agent.DOCKER
878
910
  cloud: str | None = None
911
+ service_account: str | None = None
912
+ """The existing service account Kubernetes agents' pods run as
913
+ (:attr:`Pipeline.service_account`)."""
879
914
  remote: RemoteSettings = field(default_factory=RemoteSettings)
880
915
  """The settings the installed adapters declare remote, which never become mounts."""
881
916
  spec_source: SpecSource = SpecSourceKind.CHECKOUT
@@ -886,6 +921,9 @@ class PipelineOptions:
886
921
  """Leave out every schedule and follow-on trigger, so only a person starts the jobs."""
887
922
  library_remote: str | None = None
888
923
  """A Git URL of a mirror of this repository (:attr:`Pipeline.library_remote`)."""
924
+ host_paths: tuple[tuple[str, str], ...] = ()
925
+ """Directories a Docker agent binds from elsewhere on the host, as the path in the
926
+ job and the path on the host (:attr:`Pipeline.host_paths`)."""
889
927
 
890
928
 
891
929
  _STARTERS = frozenset({Trigger.SCHEDULE, Trigger.AFTER})
@@ -1008,6 +1046,23 @@ def _library_remote(options: PipelineOptions) -> str | None:
1008
1046
  return remote
1009
1047
 
1010
1048
 
1049
+ def _service_account(options: PipelineOptions) -> str | None:
1050
+ """The service account the pods run as, checked: a Kubernetes object name, for pods."""
1051
+ account = options.service_account
1052
+ if account is None:
1053
+ return None
1054
+ if options.agent is not Agent.KUBERNETES:
1055
+ message = "a service account applies only to kubernetes agents"
1056
+ raise CiError(message)
1057
+ if len(account) > _OBJECT_NAME_LENGTH or not _OBJECT_NAME.fullmatch(account):
1058
+ message = (
1059
+ "a service account has a Kubernetes object name: lower-case letters, digits,"
1060
+ f" `-` and `.`, at most {_OBJECT_NAME_LENGTH} characters; {account!r} is not one"
1061
+ )
1062
+ raise CiError(message)
1063
+ return account
1064
+
1065
+
1011
1066
  def _docker(options: PipelineOptions) -> tuple[str | None, str | None]:
1012
1067
  """The Docker command and socket to write into the configuration, checked."""
1013
1068
  docker = options.docker
@@ -1023,6 +1078,97 @@ def _docker(options: PipelineOptions) -> tuple[str | None, str | None]:
1023
1078
  return options.docker, None if socket is None else str(socket)
1024
1079
 
1025
1080
 
1081
+ def _host_directory(path: str) -> str:
1082
+ """``path`` as a normal absolute directory other than /, which Docker can bind."""
1083
+ normal = posixpath.normpath(path) if path.startswith("/") else ""
1084
+ if (
1085
+ normal in {"", "/"}
1086
+ or ".." in PurePosixPath(path).parts
1087
+ or ":" in path
1088
+ or _UNQUOTABLE.search(path)
1089
+ ):
1090
+ message = (
1091
+ f"a host path mapping joins two absolute directories other than /, without `..`,"
1092
+ f" `:`, spaces, quotes or backslashes; {path!r} is not one"
1093
+ )
1094
+ raise CiError(message)
1095
+ return "/" + normal.lstrip("/")
1096
+
1097
+
1098
+ def _host_paths(
1099
+ spec: Spec, options: PipelineOptions, side: Side, jobs: tuple[Job, ...]
1100
+ ) -> tuple[HostPath, ...]:
1101
+ """The ``--host-path`` mappings, checked against the agent, each other and the jobs.
1102
+
1103
+ Only a Docker agent binds host paths; a Kubernetes pod mounts its claims at
1104
+ the spec's paths. A job that starts engines on the ``docker`` runtime hands
1105
+ them its own paths, which they bind from the host by those paths, so a
1106
+ mapping may not cover them. A mapping that covers none of the jobs' paths
1107
+ is a mistake.
1108
+ """
1109
+ if not options.host_paths:
1110
+ return ()
1111
+ if options.agent is not Agent.DOCKER:
1112
+ message = (
1113
+ "host path mappings apply only to docker agents; a Kubernetes pod mounts its"
1114
+ " claims at the spec's paths"
1115
+ )
1116
+ raise CiError(message)
1117
+ mappings = tuple(
1118
+ HostPath(_host_directory(container), _host_directory(host))
1119
+ for container, host in options.host_paths
1120
+ )
1121
+ for mapping in mappings:
1122
+ for other in mappings:
1123
+ if other is not mapping and PurePosixPath(mapping.container).is_relative_to(
1124
+ other.container
1125
+ ):
1126
+ message = (
1127
+ f"the host path mappings for {other.container} and {mapping.container}"
1128
+ " overlap; map each directory once"
1129
+ )
1130
+ raise CiError(message)
1131
+ if not any(mapping.source(path) for job in jobs for path in job.mounts):
1132
+ mounted = sorted({path for job in jobs for path in job.mounts})
1133
+ message = (
1134
+ f"no path these jobs mount is under {mapping.container}, so its host path"
1135
+ f" mapping does nothing; they mount {', '.join(mounted) or 'nothing'}"
1136
+ )
1137
+ raise CiError(message)
1138
+ engines = spec.runtime is not None and "docker" in spec.runtime
1139
+ starting = [job for job in jobs if engines and "runtime" in sections(job.kind, side)]
1140
+ mapped = {
1141
+ job.kind: [path for path in job.mounts if any(m.source(path) for m in mappings)]
1142
+ for job in starting
1143
+ }
1144
+ refused = {kind: paths for kind, paths in mapped.items() if paths}
1145
+ if refused:
1146
+ kind, paths = next(iter(refused.items()))
1147
+ message = (
1148
+ f"{kind} starts engine containers on the docker runtime, which bind its paths"
1149
+ f" from the host at the same paths, so {', '.join(paths)} cannot come from"
1150
+ " elsewhere on the host; generate it without the mapping"
1151
+ )
1152
+ raise CiError(message)
1153
+ return mappings
1154
+
1155
+
1156
+ def binds(pipeline: Pipeline, job: Job) -> tuple[str, ...]:
1157
+ """The job's mounts as a Docker agent's step takes them.
1158
+
1159
+ A path under a host path mapping is ``HOST:PATH``, bound from ``HOST`` on
1160
+ the runner at ``PATH`` in the job; any other path is itself, bound at the
1161
+ same path.
1162
+ """
1163
+ result: list[str] = []
1164
+ for path in job.mounts:
1165
+ source = next(
1166
+ (found for m in pipeline.host_paths if (found := m.source(path)) is not None), None
1167
+ )
1168
+ result.append(path if source is None else f"{source}:{path}")
1169
+ return tuple(result)
1170
+
1171
+
1026
1172
  def pipeline(spec: Spec, options: PipelineOptions) -> Pipeline:
1027
1173
  """The jobs to generate for one side of the boundary, decided here for every system."""
1028
1174
  side = side_of(options.kinds, options.side)
@@ -1049,6 +1195,12 @@ def pipeline(spec: Spec, options: PipelineOptions) -> Pipeline:
1049
1195
  )
1050
1196
  raise CiError(message)
1051
1197
  extra.append(options.work)
1198
+ # Production's prune removes old generations from the work directory it is given.
1199
+ pruned = (
1200
+ options.work
1201
+ if side is Side.PRODUCTION and options.work is not None and options.work.is_absolute()
1202
+ else None
1203
+ )
1052
1204
  if JobKind.PROMOTE in chosen and spec.promote is None:
1053
1205
  message = "promote needs the spec's `promote` section"
1054
1206
  raise CiError(message)
@@ -1057,7 +1209,9 @@ def pipeline(spec: Spec, options: PipelineOptions) -> Pipeline:
1057
1209
  raise CiError(message)
1058
1210
  shared = _spec_mounts(options)
1059
1211
  records = _records(spec, side, options.work)
1060
- context = _Context(options.spec_path, spec, side, chosen, str(options.work))
1212
+ context = _Context(
1213
+ options.spec_path, spec, side, chosen, None if pruned is None else str(pruned)
1214
+ )
1061
1215
  jobs = tuple(
1062
1216
  replace(
1063
1217
  _manual(_recording(_JOBS[kind](context), spec, records), manual=options.manual),
@@ -1067,6 +1221,7 @@ def pipeline(spec: Spec, options: PipelineOptions) -> Pipeline:
1067
1221
  side,
1068
1222
  (
1069
1223
  *(extra if kind is JobKind.BUILD else ()),
1224
+ *((pruned,) if kind is JobKind.PRUNE and pruned is not None else ()),
1070
1225
  *(() if records is None else (records,)),
1071
1226
  *shared,
1072
1227
  ),
@@ -1082,6 +1237,7 @@ def pipeline(spec: Spec, options: PipelineOptions) -> Pipeline:
1082
1237
  if kind in chosen
1083
1238
  )
1084
1239
  _distinct_credential(options.spec_source, jobs)
1240
+ mappings = _host_paths(spec, options, side, jobs)
1085
1241
  return Pipeline(
1086
1242
  spec=options.spec_path,
1087
1243
  name=spec.name,
@@ -1101,11 +1257,13 @@ def pipeline(spec: Spec, options: PipelineOptions) -> Pipeline:
1101
1257
  docker_socket=docker_socket,
1102
1258
  agent=options.agent,
1103
1259
  cloud=options.cloud,
1260
+ service_account=_service_account(options),
1104
1261
  runtime=spec.runtime,
1105
1262
  spec_source=options.spec_source,
1106
1263
  manual=options.manual,
1107
1264
  library_remote=_library_remote(options),
1108
1265
  generator=options.generator,
1266
+ host_paths=mappings,
1109
1267
  )
1110
1268
 
1111
1269
 
@@ -82,6 +82,7 @@ class _Arguments(argparse.Namespace):
82
82
  docker_socket: str | None
83
83
  agent: str | None
84
84
  cloud: str | None
85
+ service_account: str | None
85
86
  spec_source: str | None
86
87
  spec_dir: str | None
87
88
  spec_config_map: str | None
@@ -90,6 +91,7 @@ class _Arguments(argparse.Namespace):
90
91
  spec_credential: str | None
91
92
  manual: bool
92
93
  library_remote: str | None
94
+ host_paths: list[tuple[str, str]] | None
93
95
  level: str | None
94
96
  acknowledge_destination: str | None
95
97
  sample_rows: int | None
@@ -153,6 +155,14 @@ def _jobs(text: str) -> list[str]:
153
155
  return names
154
156
 
155
157
 
158
+ def _host_path(text: str) -> tuple[str, str]:
159
+ container, equals, host = text.partition("=")
160
+ if not equals or not container.startswith("/") or not host.startswith("/"):
161
+ message = "a host path mapping is PATH=HOST, two absolute directories"
162
+ raise argparse.ArgumentTypeError(message)
163
+ return container, host
164
+
165
+
156
166
  def _windows(text: str) -> list[int]:
157
167
  try:
158
168
  days = [int(part) for part in text.split(",") if part.strip()]
@@ -335,13 +345,20 @@ def _operation_parsers(add: _Add) -> None:
335
345
  )
336
346
  copies = add(api.Command.COPIES, "list copies")
337
347
  _group_arguments(copies)
338
- prune = add(api.Command.PRUNE, "remove old images, as the spec's prune settings say")
348
+ prune = add(
349
+ api.Command.PRUNE,
350
+ "remove old images and work directories, as the spec's prune settings say",
351
+ )
339
352
  prune.add_argument("--spec", required=True, help="the spec file, in YAML or JSON")
340
353
  prune.add_argument(
341
354
  "--target",
342
355
  required=True,
343
356
  choices=[target.value for target in PruneTarget],
344
- help="where to prune: the build's stores, the export stores, or staging",
357
+ help="where to prune: the build's stores, the export stores, staging, or the work"
358
+ " directory's old generations",
359
+ )
360
+ prune.add_argument(
361
+ "--work", help="the build's work directory, for --target work (default: .datadouble)"
345
362
  )
346
363
  prune.add_argument(
347
364
  "--dry-run",
@@ -379,7 +396,8 @@ def _ci_parsers(add: _Add) -> None:
379
396
  "--work",
380
397
  help="the build's work directory, an absolute path in production scratch space."
381
398
  " Build needs it, and so does every production job when notify sends recoveries to a"
382
- " webhook, since jobs record their last outcome there",
399
+ " webhook, since jobs record their last outcome there. Production's prune job removes"
400
+ " old generations from it",
383
401
  )
384
402
  init.add_argument(
385
403
  "--side",
@@ -405,6 +423,14 @@ def _ci_parsers(add: _Add) -> None:
405
423
  "--cloud",
406
424
  help="the Kubernetes cloud that Kubernetes agents start in (default: the system's)",
407
425
  )
426
+ init.add_argument(
427
+ "--service-account",
428
+ metavar="NAME",
429
+ help="an existing service account that Kubernetes agents' pods run as, such as one"
430
+ " managed for the side by an administrator; the setup steps then only check its RBAC,"
431
+ " and Argo CD's chart creates none (default: datadouble-<spec>-<side>, created for"
432
+ " the jobs)",
433
+ )
408
434
  init.add_argument(
409
435
  "--manual",
410
436
  action="store_true",
@@ -475,6 +501,16 @@ def _ci_parsers(add: _Add) -> None:
475
501
  help="the Docker daemon's socket on the runner, as an absolute path (default: the"
476
502
  " runner's DATADOUBLE_DOCKER_SOCKET, or /var/run/docker.sock)",
477
503
  )
504
+ init.add_argument(
505
+ "--host-path",
506
+ dest="host_paths",
507
+ type=_host_path,
508
+ action="append",
509
+ metavar="PATH=HOST",
510
+ help="on docker agents, bind the spec's directory PATH, and every path under it, from"
511
+ " HOST on the runner; jobs still see the spec's paths (repeatable). Not for paths a"
512
+ " job hands to engine containers on the docker runtime",
513
+ )
478
514
 
479
515
 
480
516
  def build_parser() -> CommandParser:
@@ -660,6 +696,8 @@ def _announce_fields(arguments: _Arguments) -> dict[str, JsonValue]:
660
696
 
661
697
  def _prune_fields(arguments: _Arguments) -> dict[str, JsonValue]:
662
698
  fields: dict[str, JsonValue] = {"spec": arguments.spec, "target": arguments.target}
699
+ if arguments.work:
700
+ fields["work"] = arguments.work
663
701
  if arguments.report_only:
664
702
  fields["dry_run"] = True
665
703
  return fields
@@ -720,11 +758,23 @@ def _ci_init_fields(arguments: _Arguments) -> dict[str, JsonValue]:
720
758
  "environment",
721
759
  "agent",
722
760
  "cloud",
761
+ "service_account",
723
762
  "docker",
724
763
  "docker_socket",
725
764
  "manual",
726
765
  "library_remote",
727
- )
766
+ ) | _host_paths(arguments)
767
+
768
+
769
+ def _host_paths(arguments: _Arguments) -> dict[str, JsonValue]:
770
+ """``--host-path`` as the request's mapping, refusing a directory mapped twice."""
771
+ mapping: dict[str, JsonValue] = {}
772
+ for container, host in arguments.host_paths or ():
773
+ if container in mapping:
774
+ message = f"--host-path maps {container} twice"
775
+ raise UsageError(message)
776
+ mapping[container] = host
777
+ return {"host_paths": mapping} if mapping else {}
728
778
 
729
779
 
730
780
  _FIELDS: dict[str, Callable[[_Arguments], dict[str, JsonValue]]] = {