dr-docker 0.4.0__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.
- dr_docker-0.4.0/.env.example +1 -0
- dr_docker-0.4.0/.github/pull_request_template.md +32 -0
- dr_docker-0.4.0/.github/workflows/ci.yml +37 -0
- dr_docker-0.4.0/.gitignore +207 -0
- dr_docker-0.4.0/.pre-commit-config.yaml +14 -0
- dr_docker-0.4.0/CLAUDE.md +48 -0
- dr_docker-0.4.0/LICENSE +21 -0
- dr_docker-0.4.0/PKG-INFO +102 -0
- dr_docker-0.4.0/README.md +59 -0
- dr_docker-0.4.0/pyproject.toml +52 -0
- dr_docker-0.4.0/src/dr_docker/__init__.py +30 -0
- dr_docker-0.4.0/src/dr_docker/_json_validation.py +25 -0
- dr_docker-0.4.0/src/dr_docker/adapters.py +23 -0
- dr_docker-0.4.0/src/dr_docker/cidfile.py +76 -0
- dr_docker-0.4.0/src/dr_docker/cleanup.py +59 -0
- dr_docker-0.4.0/src/dr_docker/docker_contract.py +82 -0
- dr_docker-0.4.0/src/dr_docker/errors.py +33 -0
- dr_docker-0.4.0/src/dr_docker/subprocess_adapter.py +362 -0
- dr_docker-0.4.0/src/dr_docker/version.py +4 -0
- dr_docker-0.4.0/tests/test_adapter_protocols.py +21 -0
- dr_docker-0.4.0/tests/test_contract_models.py +212 -0
- dr_docker-0.4.0/tests/test_subprocess_adapter.py +307 -0
- dr_docker-0.4.0/uv.lock +512 -0
|
@@ -0,0 +1 @@
|
|
|
1
|
+
PYPI_API_TOKEN=pypi-xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
## Summary
|
|
2
|
+
|
|
3
|
+
<!-- What changed and why? -->
|
|
4
|
+
|
|
5
|
+
## Context / Issue
|
|
6
|
+
|
|
7
|
+
<!-- Link the relevant issue or background context -->
|
|
8
|
+
|
|
9
|
+
## User-visible impact
|
|
10
|
+
|
|
11
|
+
<!-- Describe user-visible changes (or explicitly note "none") -->
|
|
12
|
+
|
|
13
|
+
## Manual test steps
|
|
14
|
+
|
|
15
|
+
<!-- List manual steps taken (if any), with outcomes -->
|
|
16
|
+
|
|
17
|
+
## Screenshots / GIFs (if UI changes)
|
|
18
|
+
|
|
19
|
+
<!-- Provide before/after evidence for UI changes -->
|
|
20
|
+
|
|
21
|
+
## Boundary + Contract Checklist
|
|
22
|
+
|
|
23
|
+
- [ ] I confirmed this PR stays within `nl-runtime-primitives` scope (runtime primitives only; no orchestration loops/policies).
|
|
24
|
+
- [ ] If runtime orchestration/loop logic was needed, I routed it to `nl_latents`.
|
|
25
|
+
- [ ] I reviewed boundary guidance in `README.md` and `CLAUDE.md` and kept ownership clear.
|
|
26
|
+
- [ ] I documented runtime contract impact (if any).
|
|
27
|
+
- [ ] I documented contract versioning/migration impact (if any).
|
|
28
|
+
|
|
29
|
+
## Testing
|
|
30
|
+
|
|
31
|
+
- [ ] Tests pass locally (include commands and results).
|
|
32
|
+
- [ ] Added/updated tests where behavior changed.
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
name: CI
|
|
2
|
+
|
|
3
|
+
on:
|
|
4
|
+
push:
|
|
5
|
+
pull_request:
|
|
6
|
+
|
|
7
|
+
jobs:
|
|
8
|
+
quality:
|
|
9
|
+
runs-on: ubuntu-latest
|
|
10
|
+
steps:
|
|
11
|
+
- name: Checkout
|
|
12
|
+
uses: actions/checkout@v4
|
|
13
|
+
|
|
14
|
+
- name: Set up Python
|
|
15
|
+
uses: actions/setup-python@v5
|
|
16
|
+
with:
|
|
17
|
+
python-version: "3.12"
|
|
18
|
+
|
|
19
|
+
- name: Set up uv
|
|
20
|
+
uses: astral-sh/setup-uv@v6
|
|
21
|
+
with:
|
|
22
|
+
enable-cache: true
|
|
23
|
+
|
|
24
|
+
- name: Install dependencies
|
|
25
|
+
run: uv sync --group dev
|
|
26
|
+
|
|
27
|
+
- name: Run tests
|
|
28
|
+
run: uv run pytest -q -m "not docker"
|
|
29
|
+
|
|
30
|
+
- name: Run format check
|
|
31
|
+
run: uv run ruff format --check
|
|
32
|
+
|
|
33
|
+
- name: Run lint
|
|
34
|
+
run: uv run ruff check
|
|
35
|
+
|
|
36
|
+
- name: Run type checks
|
|
37
|
+
run: uv run ty check
|
|
@@ -0,0 +1,207 @@
|
|
|
1
|
+
# Byte-compiled / optimized / DLL files
|
|
2
|
+
__pycache__/
|
|
3
|
+
*.py[codz]
|
|
4
|
+
*$py.class
|
|
5
|
+
|
|
6
|
+
# C extensions
|
|
7
|
+
*.so
|
|
8
|
+
|
|
9
|
+
# Distribution / packaging
|
|
10
|
+
.Python
|
|
11
|
+
build/
|
|
12
|
+
develop-eggs/
|
|
13
|
+
dist/
|
|
14
|
+
downloads/
|
|
15
|
+
eggs/
|
|
16
|
+
.eggs/
|
|
17
|
+
lib/
|
|
18
|
+
lib64/
|
|
19
|
+
parts/
|
|
20
|
+
sdist/
|
|
21
|
+
var/
|
|
22
|
+
wheels/
|
|
23
|
+
share/python-wheels/
|
|
24
|
+
*.egg-info/
|
|
25
|
+
.installed.cfg
|
|
26
|
+
*.egg
|
|
27
|
+
MANIFEST
|
|
28
|
+
|
|
29
|
+
# PyInstaller
|
|
30
|
+
# Usually these files are written by a python script from a template
|
|
31
|
+
# before PyInstaller builds the exe, so as to inject date/other infos into it.
|
|
32
|
+
*.manifest
|
|
33
|
+
*.spec
|
|
34
|
+
|
|
35
|
+
# Installer logs
|
|
36
|
+
pip-log.txt
|
|
37
|
+
pip-delete-this-directory.txt
|
|
38
|
+
|
|
39
|
+
# Unit test / coverage reports
|
|
40
|
+
htmlcov/
|
|
41
|
+
.tox/
|
|
42
|
+
.nox/
|
|
43
|
+
.coverage
|
|
44
|
+
.coverage.*
|
|
45
|
+
.cache
|
|
46
|
+
nosetests.xml
|
|
47
|
+
coverage.xml
|
|
48
|
+
*.cover
|
|
49
|
+
*.py.cover
|
|
50
|
+
.hypothesis/
|
|
51
|
+
.pytest_cache/
|
|
52
|
+
cover/
|
|
53
|
+
|
|
54
|
+
# Translations
|
|
55
|
+
*.mo
|
|
56
|
+
*.pot
|
|
57
|
+
|
|
58
|
+
# Django stuff:
|
|
59
|
+
*.log
|
|
60
|
+
local_settings.py
|
|
61
|
+
db.sqlite3
|
|
62
|
+
db.sqlite3-journal
|
|
63
|
+
|
|
64
|
+
# Flask stuff:
|
|
65
|
+
instance/
|
|
66
|
+
.webassets-cache
|
|
67
|
+
|
|
68
|
+
# Scrapy stuff:
|
|
69
|
+
.scrapy
|
|
70
|
+
|
|
71
|
+
# Sphinx documentation
|
|
72
|
+
docs/_build/
|
|
73
|
+
|
|
74
|
+
# PyBuilder
|
|
75
|
+
.pybuilder/
|
|
76
|
+
target/
|
|
77
|
+
|
|
78
|
+
# Jupyter Notebook
|
|
79
|
+
.ipynb_checkpoints
|
|
80
|
+
|
|
81
|
+
# IPython
|
|
82
|
+
profile_default/
|
|
83
|
+
ipython_config.py
|
|
84
|
+
|
|
85
|
+
# pyenv
|
|
86
|
+
# For a library or package, you might want to ignore these files since the code is
|
|
87
|
+
# intended to run in multiple environments; otherwise, check them in:
|
|
88
|
+
# .python-version
|
|
89
|
+
|
|
90
|
+
# pipenv
|
|
91
|
+
# According to pypa/pipenv#598, it is recommended to include Pipfile.lock in version control.
|
|
92
|
+
# However, in case of collaboration, if having platform-specific dependencies or dependencies
|
|
93
|
+
# having no cross-platform support, pipenv may install dependencies that don't work, or not
|
|
94
|
+
# install all needed dependencies.
|
|
95
|
+
#Pipfile.lock
|
|
96
|
+
|
|
97
|
+
# UV
|
|
98
|
+
# Similar to Pipfile.lock, it is generally recommended to include uv.lock in version control.
|
|
99
|
+
# This is especially recommended for binary packages to ensure reproducibility, and is more
|
|
100
|
+
# commonly ignored for libraries.
|
|
101
|
+
#uv.lock
|
|
102
|
+
|
|
103
|
+
# poetry
|
|
104
|
+
# Similar to Pipfile.lock, it is generally recommended to include poetry.lock in version control.
|
|
105
|
+
# This is especially recommended for binary packages to ensure reproducibility, and is more
|
|
106
|
+
# commonly ignored for libraries.
|
|
107
|
+
# https://python-poetry.org/docs/basic-usage/#commit-your-poetrylock-file-to-version-control
|
|
108
|
+
#poetry.lock
|
|
109
|
+
#poetry.toml
|
|
110
|
+
|
|
111
|
+
# pdm
|
|
112
|
+
# Similar to Pipfile.lock, it is generally recommended to include pdm.lock in version control.
|
|
113
|
+
# pdm recommends including project-wide configuration in pdm.toml, but excluding .pdm-python.
|
|
114
|
+
# https://pdm-project.org/en/latest/usage/project/#working-with-version-control
|
|
115
|
+
#pdm.lock
|
|
116
|
+
#pdm.toml
|
|
117
|
+
.pdm-python
|
|
118
|
+
.pdm-build/
|
|
119
|
+
|
|
120
|
+
# pixi
|
|
121
|
+
# Similar to Pipfile.lock, it is generally recommended to include pixi.lock in version control.
|
|
122
|
+
#pixi.lock
|
|
123
|
+
# Pixi creates a virtual environment in the .pixi directory, just like venv module creates one
|
|
124
|
+
# in the .venv directory. It is recommended not to include this directory in version control.
|
|
125
|
+
.pixi
|
|
126
|
+
|
|
127
|
+
# PEP 582; used by e.g. github.com/David-OConnor/pyflow and github.com/pdm-project/pdm
|
|
128
|
+
__pypackages__/
|
|
129
|
+
|
|
130
|
+
# Celery stuff
|
|
131
|
+
celerybeat-schedule
|
|
132
|
+
celerybeat.pid
|
|
133
|
+
|
|
134
|
+
# SageMath parsed files
|
|
135
|
+
*.sage.py
|
|
136
|
+
|
|
137
|
+
# Environments
|
|
138
|
+
.env
|
|
139
|
+
.envrc
|
|
140
|
+
.venv
|
|
141
|
+
env/
|
|
142
|
+
venv/
|
|
143
|
+
ENV/
|
|
144
|
+
env.bak/
|
|
145
|
+
venv.bak/
|
|
146
|
+
|
|
147
|
+
# Spyder project settings
|
|
148
|
+
.spyderproject
|
|
149
|
+
.spyproject
|
|
150
|
+
|
|
151
|
+
# Rope project settings
|
|
152
|
+
.ropeproject
|
|
153
|
+
|
|
154
|
+
# mkdocs documentation
|
|
155
|
+
/site
|
|
156
|
+
|
|
157
|
+
# mypy
|
|
158
|
+
.mypy_cache/
|
|
159
|
+
.dmypy.json
|
|
160
|
+
dmypy.json
|
|
161
|
+
|
|
162
|
+
# Pyre type checker
|
|
163
|
+
.pyre/
|
|
164
|
+
|
|
165
|
+
# pytype static type analyzer
|
|
166
|
+
.pytype/
|
|
167
|
+
|
|
168
|
+
# Cython debug symbols
|
|
169
|
+
cython_debug/
|
|
170
|
+
|
|
171
|
+
# PyCharm
|
|
172
|
+
# JetBrains specific template is maintained in a separate JetBrains.gitignore that can
|
|
173
|
+
# be found at https://github.com/github/gitignore/blob/main/Global/JetBrains.gitignore
|
|
174
|
+
# and can be added to the global gitignore or merged into this file. For a more nuclear
|
|
175
|
+
# option (not recommended) you can uncomment the following to ignore the entire idea folder.
|
|
176
|
+
#.idea/
|
|
177
|
+
|
|
178
|
+
# Abstra
|
|
179
|
+
# Abstra is an AI-powered process automation framework.
|
|
180
|
+
# Ignore directories containing user credentials, local state, and settings.
|
|
181
|
+
# Learn more at https://abstra.io/docs
|
|
182
|
+
.abstra/
|
|
183
|
+
|
|
184
|
+
# Visual Studio Code
|
|
185
|
+
# Visual Studio Code specific template is maintained in a separate VisualStudioCode.gitignore
|
|
186
|
+
# that can be found at https://github.com/github/gitignore/blob/main/Global/VisualStudioCode.gitignore
|
|
187
|
+
# and can be added to the global gitignore or merged into this file. However, if you prefer,
|
|
188
|
+
# you could uncomment the following to ignore the entire vscode folder
|
|
189
|
+
# .vscode/
|
|
190
|
+
|
|
191
|
+
# Ruff stuff:
|
|
192
|
+
.ruff_cache/
|
|
193
|
+
|
|
194
|
+
# PyPI configuration file
|
|
195
|
+
.pypirc
|
|
196
|
+
|
|
197
|
+
# Cursor
|
|
198
|
+
# Cursor is an AI-powered code editor. `.cursorignore` specifies files/directories to
|
|
199
|
+
# exclude from AI features like autocomplete and code analysis. Recommended for sensitive data
|
|
200
|
+
# refer to https://docs.cursor.com/context/ignore-files
|
|
201
|
+
.cursorignore
|
|
202
|
+
.cursorindexingignore
|
|
203
|
+
|
|
204
|
+
# Marimo
|
|
205
|
+
marimo/_static/
|
|
206
|
+
marimo/_lsp/
|
|
207
|
+
__marimo__/
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
# CLAUDE.md
|
|
2
|
+
|
|
3
|
+
Operational guidance for working in `dr-docker`.
|
|
4
|
+
|
|
5
|
+
## What To Optimize For
|
|
6
|
+
|
|
7
|
+
- Preserve a small, stable public contract.
|
|
8
|
+
- Prefer strict, explicit behavior over permissive fallbacks.
|
|
9
|
+
- Keep changes minimal and easy to reason about.
|
|
10
|
+
|
|
11
|
+
## Scope Rules
|
|
12
|
+
|
|
13
|
+
Allowed:
|
|
14
|
+
- Docker runtime primitive contracts
|
|
15
|
+
- Runtime adapter and validation behavior
|
|
16
|
+
- Typed error-envelope behavior
|
|
17
|
+
- Tests for contract guarantees
|
|
18
|
+
|
|
19
|
+
Not allowed:
|
|
20
|
+
- Orchestration/control-loop logic
|
|
21
|
+
- Scheduler/policy/selector behavior
|
|
22
|
+
- Prompt-catalog or prompt-composition ownership
|
|
23
|
+
|
|
24
|
+
## Change Rules
|
|
25
|
+
|
|
26
|
+
- Do not add broad compatibility shims.
|
|
27
|
+
- Do not expand the public surface without clear necessity.
|
|
28
|
+
- Treat validator behavior and exported symbols as contract-critical.
|
|
29
|
+
- If a change breaks downstream expectations, bump `CONTRACT_VERSION` and package version together.
|
|
30
|
+
|
|
31
|
+
## Testing Standard
|
|
32
|
+
|
|
33
|
+
Before finishing work, run:
|
|
34
|
+
|
|
35
|
+
```bash
|
|
36
|
+
uv run pytest -q
|
|
37
|
+
uv run ruff check
|
|
38
|
+
uv run ty check
|
|
39
|
+
```
|
|
40
|
+
|
|
41
|
+
If behavior changed, tests should clearly pin the new behavior.
|
|
42
|
+
|
|
43
|
+
## Practical Style
|
|
44
|
+
|
|
45
|
+
- Keep errors typed and deterministic (`ErrorCode` + `ErrorEnvelope`).
|
|
46
|
+
- Prefer explicit failure over silent fallback.
|
|
47
|
+
- Keep contracts small and explicit at package boundaries.
|
|
48
|
+
- Keep docs concise; avoid duplicating large architectural narratives.
|
dr_docker-0.4.0/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 Danielle Rothermel
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
dr_docker-0.4.0/PKG-INFO
ADDED
|
@@ -0,0 +1,102 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: dr-docker
|
|
3
|
+
Version: 0.4.0
|
|
4
|
+
Summary: Docker runtime contracts and subprocess adapter
|
|
5
|
+
Project-URL: Homepage, https://github.com/drothermel/dr-docker
|
|
6
|
+
Project-URL: Repository, https://github.com/drothermel/dr-docker
|
|
7
|
+
Project-URL: Issues, https://github.com/drothermel/dr-docker/issues
|
|
8
|
+
Author: NL Stack
|
|
9
|
+
License: MIT License
|
|
10
|
+
|
|
11
|
+
Copyright (c) 2026 Danielle Rothermel
|
|
12
|
+
|
|
13
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
14
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
15
|
+
in the Software without restriction, including without limitation the rights
|
|
16
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
17
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
18
|
+
furnished to do so, subject to the following conditions:
|
|
19
|
+
|
|
20
|
+
The above copyright notice and this permission notice shall be included in all
|
|
21
|
+
copies or substantial portions of the Software.
|
|
22
|
+
|
|
23
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
24
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
25
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
26
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
27
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
28
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
29
|
+
SOFTWARE.
|
|
30
|
+
License-File: LICENSE
|
|
31
|
+
Keywords: contracts,docker,runtime,sandbox,subprocess
|
|
32
|
+
Classifier: Development Status :: 4 - Beta
|
|
33
|
+
Classifier: Intended Audience :: Developers
|
|
34
|
+
Classifier: License :: OSI Approved :: MIT License
|
|
35
|
+
Classifier: Programming Language :: Python :: 3
|
|
36
|
+
Classifier: Programming Language :: Python :: 3.10
|
|
37
|
+
Classifier: Programming Language :: Python :: 3.11
|
|
38
|
+
Classifier: Programming Language :: Python :: 3.12
|
|
39
|
+
Classifier: Typing :: Typed
|
|
40
|
+
Requires-Python: >=3.10
|
|
41
|
+
Requires-Dist: pydantic<3.0,>=2.0
|
|
42
|
+
Description-Content-Type: text/markdown
|
|
43
|
+
|
|
44
|
+
# dr-docker
|
|
45
|
+
|
|
46
|
+
Reusable Docker execution contracts and adapters.
|
|
47
|
+
|
|
48
|
+
## Purpose
|
|
49
|
+
|
|
50
|
+
This repo provides Docker runtime contracts and a concrete subprocess adapter:
|
|
51
|
+
- Docker runtime request/result contracts with security and resource profiles
|
|
52
|
+
- Runtime adapter protocol
|
|
53
|
+
- Subprocess-based Docker adapter with stream capping and cidfile cleanup
|
|
54
|
+
- Typed error envelopes
|
|
55
|
+
|
|
56
|
+
## Public Surface
|
|
57
|
+
|
|
58
|
+
```python
|
|
59
|
+
from dr_docker import (
|
|
60
|
+
CONTRACT_VERSION,
|
|
61
|
+
DockerMount,
|
|
62
|
+
DockerRuntimeRequest,
|
|
63
|
+
DockerRuntimeResult,
|
|
64
|
+
ErrorCode,
|
|
65
|
+
ErrorEnvelope,
|
|
66
|
+
ResourceLimits,
|
|
67
|
+
RuntimeAdapter,
|
|
68
|
+
RuntimePrimitiveError,
|
|
69
|
+
SecurityProfile,
|
|
70
|
+
SubprocessDockerAdapter,
|
|
71
|
+
TmpfsMount,
|
|
72
|
+
__version__,
|
|
73
|
+
)
|
|
74
|
+
```
|
|
75
|
+
|
|
76
|
+
## Contract Guarantees
|
|
77
|
+
|
|
78
|
+
- `DockerRuntimeResult(ok=False)` requires `error`
|
|
79
|
+
- Successful result envelopes must not include `error`
|
|
80
|
+
- Error envelopes are typed (`ErrorCode`) with non-empty message and JSON-safe details
|
|
81
|
+
- Supported `ErrorCode` values are `timeout`, `unavailable`, and `internal_error`
|
|
82
|
+
|
|
83
|
+
## Development
|
|
84
|
+
|
|
85
|
+
```bash
|
|
86
|
+
uv sync --group dev
|
|
87
|
+
uv run pytest -q
|
|
88
|
+
uv run ruff format --check
|
|
89
|
+
uv run ruff check
|
|
90
|
+
uv run ty check
|
|
91
|
+
```
|
|
92
|
+
|
|
93
|
+
## Publishing
|
|
94
|
+
|
|
95
|
+
```bash
|
|
96
|
+
cp .env.example .env
|
|
97
|
+
# set PYPI_API_TOKEN in .env
|
|
98
|
+
set -a; source .env; set +a
|
|
99
|
+
uv build
|
|
100
|
+
uvx twine check dist/*
|
|
101
|
+
uvx twine upload -u __token__ -p "$PYPI_API_TOKEN" dist/*
|
|
102
|
+
```
|
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
# dr-docker
|
|
2
|
+
|
|
3
|
+
Reusable Docker execution contracts and adapters.
|
|
4
|
+
|
|
5
|
+
## Purpose
|
|
6
|
+
|
|
7
|
+
This repo provides Docker runtime contracts and a concrete subprocess adapter:
|
|
8
|
+
- Docker runtime request/result contracts with security and resource profiles
|
|
9
|
+
- Runtime adapter protocol
|
|
10
|
+
- Subprocess-based Docker adapter with stream capping and cidfile cleanup
|
|
11
|
+
- Typed error envelopes
|
|
12
|
+
|
|
13
|
+
## Public Surface
|
|
14
|
+
|
|
15
|
+
```python
|
|
16
|
+
from dr_docker import (
|
|
17
|
+
CONTRACT_VERSION,
|
|
18
|
+
DockerMount,
|
|
19
|
+
DockerRuntimeRequest,
|
|
20
|
+
DockerRuntimeResult,
|
|
21
|
+
ErrorCode,
|
|
22
|
+
ErrorEnvelope,
|
|
23
|
+
ResourceLimits,
|
|
24
|
+
RuntimeAdapter,
|
|
25
|
+
RuntimePrimitiveError,
|
|
26
|
+
SecurityProfile,
|
|
27
|
+
SubprocessDockerAdapter,
|
|
28
|
+
TmpfsMount,
|
|
29
|
+
__version__,
|
|
30
|
+
)
|
|
31
|
+
```
|
|
32
|
+
|
|
33
|
+
## Contract Guarantees
|
|
34
|
+
|
|
35
|
+
- `DockerRuntimeResult(ok=False)` requires `error`
|
|
36
|
+
- Successful result envelopes must not include `error`
|
|
37
|
+
- Error envelopes are typed (`ErrorCode`) with non-empty message and JSON-safe details
|
|
38
|
+
- Supported `ErrorCode` values are `timeout`, `unavailable`, and `internal_error`
|
|
39
|
+
|
|
40
|
+
## Development
|
|
41
|
+
|
|
42
|
+
```bash
|
|
43
|
+
uv sync --group dev
|
|
44
|
+
uv run pytest -q
|
|
45
|
+
uv run ruff format --check
|
|
46
|
+
uv run ruff check
|
|
47
|
+
uv run ty check
|
|
48
|
+
```
|
|
49
|
+
|
|
50
|
+
## Publishing
|
|
51
|
+
|
|
52
|
+
```bash
|
|
53
|
+
cp .env.example .env
|
|
54
|
+
# set PYPI_API_TOKEN in .env
|
|
55
|
+
set -a; source .env; set +a
|
|
56
|
+
uv build
|
|
57
|
+
uvx twine check dist/*
|
|
58
|
+
uvx twine upload -u __token__ -p "$PYPI_API_TOKEN" dist/*
|
|
59
|
+
```
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
[build-system]
|
|
2
|
+
requires = ["hatchling>=1.24.2"]
|
|
3
|
+
build-backend = "hatchling.build"
|
|
4
|
+
|
|
5
|
+
[project]
|
|
6
|
+
name = "dr-docker"
|
|
7
|
+
version = "0.4.0"
|
|
8
|
+
description = "Docker runtime contracts and subprocess adapter"
|
|
9
|
+
readme = "README.md"
|
|
10
|
+
requires-python = ">=3.10"
|
|
11
|
+
license = { file = "LICENSE" }
|
|
12
|
+
authors = [{ name = "NL Stack" }]
|
|
13
|
+
keywords = ["docker", "runtime", "sandbox", "subprocess", "contracts"]
|
|
14
|
+
classifiers = [
|
|
15
|
+
"Development Status :: 4 - Beta",
|
|
16
|
+
"Intended Audience :: Developers",
|
|
17
|
+
"License :: OSI Approved :: MIT License",
|
|
18
|
+
"Programming Language :: Python :: 3",
|
|
19
|
+
"Programming Language :: Python :: 3.10",
|
|
20
|
+
"Programming Language :: Python :: 3.11",
|
|
21
|
+
"Programming Language :: Python :: 3.12",
|
|
22
|
+
"Typing :: Typed",
|
|
23
|
+
]
|
|
24
|
+
dependencies = [
|
|
25
|
+
"pydantic>=2.0,<3.0",
|
|
26
|
+
]
|
|
27
|
+
|
|
28
|
+
[project.urls]
|
|
29
|
+
Homepage = "https://github.com/drothermel/dr-docker"
|
|
30
|
+
Repository = "https://github.com/drothermel/dr-docker"
|
|
31
|
+
Issues = "https://github.com/drothermel/dr-docker/issues"
|
|
32
|
+
|
|
33
|
+
[dependency-groups]
|
|
34
|
+
dev = [
|
|
35
|
+
"pre-commit>=4.5.1",
|
|
36
|
+
"pytest>=8.0,<9.0",
|
|
37
|
+
"ruff>=0.5,<1.0",
|
|
38
|
+
"ty>=0.0.15",
|
|
39
|
+
]
|
|
40
|
+
|
|
41
|
+
[tool.pytest.ini_options]
|
|
42
|
+
testpaths = ["tests"]
|
|
43
|
+
markers = [
|
|
44
|
+
"docker: tests that require Docker daemon",
|
|
45
|
+
]
|
|
46
|
+
|
|
47
|
+
[tool.ruff]
|
|
48
|
+
line-length = 88
|
|
49
|
+
target-version = "py310"
|
|
50
|
+
|
|
51
|
+
[tool.hatch.build.targets.wheel]
|
|
52
|
+
packages = ["src/dr_docker"]
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
"""Typed Docker runtime contracts and subprocess adapter."""
|
|
2
|
+
|
|
3
|
+
from .adapters import RuntimeAdapter, RuntimePrimitiveError
|
|
4
|
+
from .docker_contract import (
|
|
5
|
+
DockerMount,
|
|
6
|
+
DockerRuntimeRequest,
|
|
7
|
+
DockerRuntimeResult,
|
|
8
|
+
ResourceLimits,
|
|
9
|
+
SecurityProfile,
|
|
10
|
+
TmpfsMount,
|
|
11
|
+
)
|
|
12
|
+
from .errors import ErrorCode, ErrorEnvelope
|
|
13
|
+
from .subprocess_adapter import SubprocessDockerAdapter
|
|
14
|
+
from .version import CONTRACT_VERSION, __version__
|
|
15
|
+
|
|
16
|
+
__all__ = [
|
|
17
|
+
"CONTRACT_VERSION",
|
|
18
|
+
"DockerMount",
|
|
19
|
+
"DockerRuntimeRequest",
|
|
20
|
+
"DockerRuntimeResult",
|
|
21
|
+
"ErrorCode",
|
|
22
|
+
"ErrorEnvelope",
|
|
23
|
+
"ResourceLimits",
|
|
24
|
+
"RuntimeAdapter",
|
|
25
|
+
"RuntimePrimitiveError",
|
|
26
|
+
"SecurityProfile",
|
|
27
|
+
"SubprocessDockerAdapter",
|
|
28
|
+
"TmpfsMount",
|
|
29
|
+
"__version__",
|
|
30
|
+
]
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
"""Internal helpers for strict JSON boundary validation."""
|
|
2
|
+
|
|
3
|
+
from __future__ import annotations
|
|
4
|
+
|
|
5
|
+
import math
|
|
6
|
+
|
|
7
|
+
from pydantic import JsonValue
|
|
8
|
+
|
|
9
|
+
|
|
10
|
+
def ensure_finite_json_value(value: JsonValue, *, path: str) -> None:
|
|
11
|
+
"""Reject non-finite numbers to preserve deterministic JSON contracts."""
|
|
12
|
+
|
|
13
|
+
if isinstance(value, float):
|
|
14
|
+
if not math.isfinite(value):
|
|
15
|
+
raise ValueError(f"{path} must not contain NaN or infinity")
|
|
16
|
+
return
|
|
17
|
+
|
|
18
|
+
if isinstance(value, list):
|
|
19
|
+
for index, item in enumerate(value):
|
|
20
|
+
ensure_finite_json_value(item, path=f"{path}[{index}]")
|
|
21
|
+
return
|
|
22
|
+
|
|
23
|
+
if isinstance(value, dict):
|
|
24
|
+
for key, item in value.items():
|
|
25
|
+
ensure_finite_json_value(item, path=f"{path}.{key}")
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
"""Adapter protocol and error type for runtime primitive consumers."""
|
|
2
|
+
|
|
3
|
+
from typing import Protocol, runtime_checkable
|
|
4
|
+
|
|
5
|
+
from .docker_contract import DockerRuntimeRequest, DockerRuntimeResult
|
|
6
|
+
from .errors import ErrorEnvelope
|
|
7
|
+
|
|
8
|
+
|
|
9
|
+
class RuntimePrimitiveError(Exception):
|
|
10
|
+
"""Raised when a primitive operation fails with a typed infra envelope."""
|
|
11
|
+
|
|
12
|
+
def __init__(self, error: ErrorEnvelope) -> None:
|
|
13
|
+
super().__init__(error.message)
|
|
14
|
+
self.error = error
|
|
15
|
+
|
|
16
|
+
|
|
17
|
+
@runtime_checkable
|
|
18
|
+
class RuntimeAdapter(Protocol):
|
|
19
|
+
"""Primitive Docker runtime executor."""
|
|
20
|
+
|
|
21
|
+
def execute_in_runtime(
|
|
22
|
+
self, request: DockerRuntimeRequest
|
|
23
|
+
) -> DockerRuntimeResult: ...
|