Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 19 additions & 0 deletions .github/workflows/contract.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
# @generated by Hollywood. Do not edit by hand.

name: Generated API contract
on:
push: {}
pull_request: {}
permissions:
contents: read
jobs:
contract:
runs-on: ubuntu-24.04
steps:
- uses: actions/checkout@34e114876b0b11c390a56381ad16ebd13914f8d5
- name: Test contract guard
run: python3 scripts/test-contract.py
shell: bash
- name: Verify pinned public operations
run: python3 scripts/check-contract.py
shell: bash
2 changes: 2 additions & 0 deletions .github/workflows/sdk-ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@ jobs:
python-version: "3.11"
- run: python -m pip install --upgrade build
- run: python -m build
- run: python -m pip install dist/*.whl pytest pytest-asyncio
- run: python -m pytest tests -q
# Verification only, never auto-fix: the SDK is generated formatted, so a diff here means
# either hand-edited custom code or a regenerate that was not committed. ruff is pinned to
# the release that produced these bytes, since a formatter minor can change them.
Expand Down
48 changes: 48 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ The full API of this library can be found in [api.md](./api.md).

- [Installation](#installation)
- [Usage](#usage)
- [Image import](#image-import)
- [API Reference](./api.md)
- [Async](#async)
- [Authentication](#authentication)
Expand All @@ -31,6 +32,53 @@ pip install dedalus-sdk

<br />

## Image import

```python
from dedalus_sdk import Dedalus
from dedalus_sdk.images import import_image, poll_image

with Dedalus() as client:
ready = import_image(client, "my-app.tar", name="my-app", platform="linux/amd64")

# Return after upload and registration, then wait later.
accepted = import_image(client, "my-app.tar", wait=False)
image = poll_image(client, accepted["image_id"])
```

Async clients use `async_import_image` and `async_poll_image` with the same options:

```python
from dedalus_sdk import AsyncDedalus
from dedalus_sdk.images import async_import_image

async with AsyncDedalus() as client:
ready = await async_import_image(client, "my-app.tar")
```

The helpers stream a `docker save` archive, register it, and wait for readiness by
default. Set `wait=False` to return after registration. `timeout` defaults to 3,600
seconds for the import and `poll_interval` defaults to 2 seconds. `on_progress`
receives each observed image. `ImagePreparationError.image` preserves the image ID
on terminal failure or polling deadline expiry; timeout or task cancellation does
not cancel server preparation.

The synchronous helper checks its deadline between I/O operations, uses the
remaining budget for request inactivity timeouts, and disables automatic API
retries. The async helper enforces its deadline with task cancellation and retains
the client's retry policy. Use the same `idempotency_key` when retrying an import
with unchanged input.

Archives must be regular, nonempty files of at most 5 GiB. Storage uploads use a
separate HTTP client without API credentials. The helpers require the image API
to be deployed and enabled for your organization; they do not bypass access controls.

Custom image imports currently require an Ubuntu 24.04 `linux/amd64` Docker-save
archive. On Apple silicon, build or pull with `--platform linux/amd64` before
saving the archive. The image provides the filesystem; container entrypoint,
CMD, environment, working directory, and user settings are not applied. Start
processes using Machine exec or SSH after the Machine reaches running.

## Usage

```python
Expand Down
202 changes: 202 additions & 0 deletions api-contract.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,202 @@
{
"source_sha": "9f8d54f123e81b8bc7252f855c52ecbf7cc8ae42",
"spec_sha256": "c0b2db893e3017c5c83c14375e6085581584641f617ee7ea1305ab80e9b50421",
"operations": [
{
"method": "GET",
"path": "/v1/images",
"bodyParams": []
},
{
"method": "POST",
"path": "/v1/images",
"bodyParams": [
"credential_ref",
"name",
"platform",
"source"
]
},
{
"method": "POST",
"path": "/v1/images/uploads",
"bodyParams": [
"platform",
"sha256",
"size_bytes"
]
},
{
"method": "DELETE",
"path": "/v1/images/{image_id}",
"bodyParams": []
},
{
"method": "GET",
"path": "/v1/images/{image_id}",
"bodyParams": []
},
{
"method": "PATCH",
"path": "/v1/images/{image_id}",
"bodyParams": [
"name"
]
},
{
"method": "GET",
"path": "/v1/machines",
"bodyParams": []
},
{
"method": "POST",
"path": "/v1/machines",
"bodyParams": [
"autosleep",
"image_id",
"memory_mib",
"storage_gib",
"vcpu"
]
},
{
"method": "DELETE",
"path": "/v1/machines/{machine_id}",
"bodyParams": []
},
{
"method": "GET",
"path": "/v1/machines/{machine_id}",
"bodyParams": []
},
{
"method": "PATCH",
"path": "/v1/machines/{machine_id}",
"bodyParams": [
"autosleep",
"storage_gib"
]
},
{
"method": "GET",
"path": "/v1/machines/{machine_id}/autoresizing",
"bodyParams": []
},
{
"method": "PATCH",
"path": "/v1/machines/{machine_id}/autoresizing",
"bodyParams": [
"cpu",
"cpu_max_vcpu",
"memory",
"memory_max_mib"
]
},
{
"method": "GET",
"path": "/v1/machines/{machine_id}/executions",
"bodyParams": []
},
{
"method": "POST",
"path": "/v1/machines/{machine_id}/executions",
"bodyParams": [
"command",
"cwd",
"env",
"stdin",
"timeout_ms"
]
},
{
"method": "DELETE",
"path": "/v1/machines/{machine_id}/executions/{execution_id}",
"bodyParams": []
},
{
"method": "GET",
"path": "/v1/machines/{machine_id}/executions/{execution_id}",
"bodyParams": []
},
{
"method": "GET",
"path": "/v1/machines/{machine_id}/executions/{execution_id}/events",
"bodyParams": []
},
{
"method": "GET",
"path": "/v1/machines/{machine_id}/executions/{execution_id}/logs",
"bodyParams": []
},
{
"method": "POST",
"path": "/v1/machines/{machine_id}/executions/{execution_id}/logs/token",
"bodyParams": []
},
{
"method": "GET",
"path": "/v1/machines/{machine_id}/executions/{execution_id}/output",
"bodyParams": []
},
{
"method": "POST",
"path": "/v1/machines/{machine_id}/reboot",
"bodyParams": []
},
{
"method": "POST",
"path": "/v1/machines/{machine_id}/resize",
"bodyParams": [
"memory_mib",
"vcpu"
]
},
{
"method": "POST",
"path": "/v1/machines/{machine_id}/sleep",
"bodyParams": []
},
{
"method": "GET",
"path": "/v1/machines/{machine_id}/ssh",
"bodyParams": []
},
{
"method": "POST",
"path": "/v1/machines/{machine_id}/ssh",
"bodyParams": [
"public_key"
]
},
{
"method": "DELETE",
"path": "/v1/machines/{machine_id}/ssh/{session_id}",
"bodyParams": []
},
{
"method": "GET",
"path": "/v1/machines/{machine_id}/ssh/{session_id}",
"bodyParams": []
},
{
"method": "POST",
"path": "/v1/machines/{machine_id}/wake",
"bodyParams": []
},
{
"method": "GET",
"path": "/v1/organization/autoresizing",
"bodyParams": []
},
{
"method": "PATCH",
"path": "/v1/organization/autoresizing",
"bodyParams": [
"cpu",
"cpu_max_vcpu",
"memory",
"memory_max_mib"
]
}
]
}
24 changes: 24 additions & 0 deletions ci/contract.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
import { command, workflow } from '@dedalus-labs/hollywood';

// Generate with Hollywood 0.0.5; this workflow never publishes packages.
export const contractCI = workflow({
name: 'Generated API contract',
on: { push: {}, pull_request: {} },
permissions: { contents: 'read' },
jobs: {
contract: {
'runs-on': 'ubuntu-24.04',
steps: [
{ uses: 'actions/checkout@34e114876b0b11c390a56381ad16ebd13914f8d5' },
{
name: 'Test contract guard',
run: command({ file: 'python3', args: ['scripts/test-contract.py'] }),
},
{
name: 'Verify pinned public operations',
run: command({ file: 'python3', args: ['scripts/check-contract.py'] }),
},
],
},
},
});
12 changes: 12 additions & 0 deletions generation-provenance.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
{
"source_spec_sha": "9f8d54f123e81b8bc7252f855c52ecbf7cc8ae42",
"source_spec_sha256": "c0b2db893e3017c5c83c14375e6085581584641f617ee7ea1305ab80e9b50421",
"generator_version": "0.38.0",
"build_version": "0.1.16",
"configuration_sha256": "10d2f59b8a69dce627060e1104eac425cec104dd90d3177c08a29a902cb48875",
"operation_count": 31,
"generated_commit": "bc3e12c4dd8d4d0557b5e2847049a2ecc7df21df",
"download_sha256": null,
"integration_base": "scalar-next",
"published_package": false
}
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[project]
name = "dedalus-sdk"
version = "0.1.0" # x-release-please-version
version = "0.6.0" # x-release-please-version
description = "Create, run, and manage Dedalus Machines."
readme = "README.md"
license = "Apache-2.0"
Expand Down
34 changes: 34 additions & 0 deletions scripts/check-contract.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
#!/usr/bin/env python3
"""Compare generated operations with the independently pinned public API contract."""

import json
from collections import Counter
from pathlib import Path


def check(contract, manifest):
expected = {(op["method"], op["path"]): op for op in contract["operations"]}
counts = Counter((op["method"].upper(), op["path"]) for op in manifest["operations"])
errors = []
for key in sorted(expected.keys() - counts.keys()):
errors.append(f"missing operation: {key}")
for key in sorted(counts.keys() - expected.keys()):
errors.append(f"obsolete operation: {key}")
for key, count in counts.items():
if count != 1:
errors.append(f"duplicate operation: {key}")
for op in manifest["operations"]:
key = (op["method"].upper(), op["path"])
if key in expected and sorted(op.get("bodyParams", [])) != expected[key]["bodyParams"]:
errors.append(f"request fields differ: {key}")
return errors


if __name__ == "__main__":
root = Path(__file__).resolve().parents[1]
contract = json.loads((root / "api-contract.json").read_text())
manifest = json.loads((root / "scalar-sdk.manifest.json").read_text())
errors = check(contract, manifest)
if errors:
raise SystemExit("\n".join(errors))
print(f"Contract verified: {len(contract['operations'])} operations; source {contract['source_sha']}")
Loading
Loading