Metadata-Version: 2.4
Name: dr-docker
Version: 0.4.4
Summary: Docker runtime contracts and subprocess adapter
Project-URL: Homepage, https://github.com/drothermel/dr-docker
Project-URL: Repository, https://github.com/drothermel/dr-docker
Project-URL: Issues, https://github.com/drothermel/dr-docker/issues
Author: NL Stack
License: MIT License
        
        Copyright (c) 2026 Danielle Rothermel
        
        Permission is hereby granted, free of charge, to any person obtaining a copy
        of this software and associated documentation files (the "Software"), to deal
        in the Software without restriction, including without limitation the rights
        to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
        copies of the Software, and to permit persons to whom the Software is
        furnished to do so, subject to the following conditions:
        
        The above copyright notice and this permission notice shall be included in all
        copies or substantial portions of the Software.
        
        THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
        IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
        FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
        AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
        LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
        OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
        SOFTWARE.
License-File: LICENSE
Keywords: contracts,docker,runtime,sandbox,subprocess
Classifier: Development Status :: 4 - Beta
Classifier: Intended Audience :: Developers
Classifier: License :: OSI Approved :: MIT License
Classifier: Programming Language :: Python :: 3
Classifier: Programming Language :: Python :: 3.10
Classifier: Programming Language :: Python :: 3.11
Classifier: Programming Language :: Python :: 3.12
Classifier: Typing :: Typed
Requires-Python: >=3.10
Requires-Dist: pydantic<3.0,>=2.0
Description-Content-Type: text/markdown

# dr-docker

Reusable Docker execution contracts and adapters.

## Purpose

This repo provides Docker runtime contracts and a concrete subprocess adapter:
- Docker runtime request/result contracts with security and resource profiles
- Runtime adapter protocol
- Subprocess-based Docker adapter with stream capping and cidfile cleanup
- Worker helpers for mounted scripts/directories with reusable runtime policies
- Typed error envelopes

## Public Surface

```python
from dr_docker import (
    CONTRACT_VERSION,
    DockerMount,
    DockerRuntimeRequest,
    DockerRuntimeResult,
    ErrorCode,
    ErrorEnvelope,
    MountedWorker,
    ResourceLimits,
    RuntimeAdapter,
    RuntimePrimitiveError,
    SecurityProfile,
    SubprocessDockerAdapter,
    TmpfsMount,
    WorkerRuntimePolicy,
    __version__,
    build_mounted_worker_request,
    execute_batch_in_container,
    mount_worker_directory,
    mount_worker_file,
    run_batch_with_failure_isolation,
)
```

## Worker Support

`dr-docker` now includes a small worker-support layer for the common pattern of:
- starting from a reusable isolated runtime policy
- mounting a local worker file or directory into the container
- building a `DockerRuntimeRequest` with stdin, env, mounts, tmpfs, and resource limits already wired together

```python
from pathlib import Path

from dr_docker import (
    WorkerRuntimePolicy,
    build_mounted_worker_request,
    mount_worker_file,
)

worker = mount_worker_file(Path("worker.py"), mount_target="/sandbox")
worker = worker.with_path_command(
    entrypoint="python3",
    args_before_path=["-I"],
    working_dir="/tmp",
)

policy = WorkerRuntimePolicy.small_isolated().model_copy(
    update={"memory": "1g", "tmpfs_exec": True}
)

request = build_mounted_worker_request(
    image="python:3.12-slim",
    worker=worker,
    timeout_seconds=30,
    policy=policy,
    stdin_payload='{"job": "ping"}',
    env={"WORKER_MODE": "json"},
)
```

For optional worker-side JSON-over-stdin helpers, use `dr_docker.workers.json_stdio`. That module intentionally stays separate from the core Docker contract layer and includes bounded stdin reading, bounded stdout capture, container guards, and basic RLIMIT helpers.

## Contract Guarantees

- `DockerRuntimeResult(ok=False)` requires `error`
- Successful result envelopes must not include `error`
- Error envelopes are typed (`ErrorCode`) with non-empty message and JSON-safe details
- Supported `ErrorCode` values are `timeout`, `unavailable`, and `internal_error`

## Development

```bash
uv sync --group dev
uv run pytest -q
uv run ruff format --check
uv run ruff check
uv run ty check
```

## Publishing

```bash
cp .env.example .env
# set PYPI_API_TOKEN in .env
set -a; source .env; set +a
uv build
uvx twine check dist/*
uvx twine upload -u __token__ -p "$PYPI_API_TOKEN" dist/*
```
