1fa17d1822
Replaces the alpine:latest placeholder with a real claude-bottle agent image, converted into a .smolmachine artifact via an ephemeral local OCI registry. Why the registry hop: smolvm pack create only accepts OCI registry refs. Empirically it rejects docker-daemon://, oci-layout://, docker-archive: tarballs, and every other transport tested — the crane backend treats anything with a scheme prefix as a registry hostname. To convert a locally-built docker image into a .smolmachine we have to push it somewhere smolvm can pull from. Smallest path: bring up registry:2.8.3 bound to 127.0.0.1:<random>, docker tag + docker push into it, smolvm pack create --image localhost:<port>/claude-bottle:<id>, tear down the registry. The .smolmachine is cached under ~/.cache/claude-bottle/smolmachines/ keyed by the docker image ID (first 16 hex chars of the sha256), so a Dockerfile change picks up a new image ID and invalidates the cache. Unchanged rebuilds skip the whole build → registry → pack pipeline. This puts `docker build` in smolmachines prepare (the docker backend defers it to launch). Necessary because pack_create needs the image ID to derive the cache key, and prepare is the only hook ahead of launch that runs once per slug. Adds: - claude_bottle/backend/docker/util.py: image_id / tag / push helpers (thin docker CLI wrappers). - claude_bottle/backend/smolmachines/local_registry.py: ephemeral_registry() context manager; pins registry:2.8.3 by digest, binds 127.0.0.1::5000 (loopback-only), force-removes on exit. Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
80 lines
2.6 KiB
Python
80 lines
2.6 KiB
Python
"""Unit: image_id / tag / push helpers in
|
|
claude_bottle.backend.docker.util (PRD 0023 chunk 4c additions).
|
|
|
|
Tests mock `subprocess.run` and assert on argv shape + parsing.
|
|
The actual docker round-trip is covered by the chunk 4c
|
|
integration smoke."""
|
|
|
|
from __future__ import annotations
|
|
|
|
import subprocess
|
|
import unittest
|
|
from unittest.mock import patch
|
|
|
|
from claude_bottle.backend.docker import util as docker_mod
|
|
|
|
|
|
def _ok(stdout: str = "", stderr: str = "") -> subprocess.CompletedProcess:
|
|
return subprocess.CompletedProcess(
|
|
args=[], returncode=0, stdout=stdout, stderr=stderr,
|
|
)
|
|
|
|
|
|
def _fail(stderr: str = "boom") -> subprocess.CompletedProcess:
|
|
return subprocess.CompletedProcess(
|
|
args=[], returncode=1, stdout="", stderr=stderr,
|
|
)
|
|
|
|
|
|
class TestImageId(unittest.TestCase):
|
|
def test_strips_trailing_newline(self):
|
|
# docker image inspect --format ... emits a trailing newline.
|
|
with patch.object(
|
|
docker_mod.subprocess, "run",
|
|
return_value=_ok(stdout="sha256:abcdef\n"),
|
|
) as run:
|
|
self.assertEqual(
|
|
"sha256:abcdef", docker_mod.image_id("claude-bottle:latest")
|
|
)
|
|
argv = run.call_args.args[0]
|
|
self.assertEqual(
|
|
["docker", "image", "inspect", "--format", "{{.Id}}", "claude-bottle:latest"],
|
|
argv,
|
|
)
|
|
|
|
def test_dies_on_inspect_failure(self):
|
|
with patch.object(
|
|
docker_mod.subprocess, "run", return_value=_fail("No such image"),
|
|
), patch.object(
|
|
docker_mod, "die", side_effect=SystemExit("die"),
|
|
) as die:
|
|
with self.assertRaises(SystemExit):
|
|
docker_mod.image_id("missing:tag")
|
|
die.assert_called_once()
|
|
self.assertIn("missing:tag", die.call_args.args[0])
|
|
|
|
|
|
class TestTagPush(unittest.TestCase):
|
|
def test_tag_runs_docker_tag(self):
|
|
with patch.object(
|
|
docker_mod.subprocess, "run", return_value=_ok(),
|
|
) as run:
|
|
docker_mod.tag("claude-bottle:latest", "localhost:5000/cb:abc")
|
|
argv = run.call_args.args[0]
|
|
self.assertEqual(
|
|
["docker", "tag", "claude-bottle:latest", "localhost:5000/cb:abc"],
|
|
argv,
|
|
)
|
|
|
|
def test_push_runs_docker_push(self):
|
|
with patch.object(
|
|
docker_mod.subprocess, "run", return_value=_ok(),
|
|
) as run:
|
|
docker_mod.push("localhost:5000/cb:abc")
|
|
argv = run.call_args.args[0]
|
|
self.assertEqual(["docker", "push", "localhost:5000/cb:abc"], argv)
|
|
|
|
|
|
if __name__ == "__main__":
|
|
unittest.main()
|