diff --git a/CHANGELOG.md b/CHANGELOG.md index cadf0f1..527aa05 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -7,6 +7,10 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ## Unreleased +### Changed + +- Docker Client is initialized lazily so that some functionality of `Beaker` client can be used on systems without Docker. + ## [v0.2.3](https://github.com/allenai/beaker-py/releases/tag/v0.2.3) - 2021-12-09 ### Fixed diff --git a/beaker/client.py b/beaker/client.py index acd19b2..e83626a 100644 --- a/beaker/client.py +++ b/beaker/client.py @@ -28,7 +28,7 @@ class Beaker: def __init__(self, config: Config): self.config = config self.base_url = f"{self.config.agent_address}/api/{self.API_VERSION}" - self.docker = docker.from_env() + self._docker: Optional[docker.DockerClient] = None @property def user(self) -> str: @@ -44,6 +44,13 @@ def from_env(cls, **overrides) -> "Beaker": """ return cls(Config.from_env(**overrides)) + @property + def docker(self) -> docker.DockerClient: + if self._docker is None: + self._docker = docker.from_env() + assert self._docker is not None + return self._docker + @contextmanager def _session_with_backoff(self) -> requests.Session: session = requests.Session()