ImageClient¶
- class baseten.sandbox.ImageClient¶
Bases:
objectImages that sandboxes are created from.
Pushes them from a build context or a registry, and finds and deletes them. Obtained from
SandboxClient.images.- Parameters:
context (ImageClientContext)
- cleanup()¶
Remove image versions that no sandbox uses.
- Return type:
- delete(*, name)¶
Delete an image and all its versions. Fails while a sandbox uses any version.
- delete_tag(*, name, tag)¶
Delete one version of an image, returning the image as it is afterwards.
Fails while a sandbox uses the version.
- get_info(*, name)¶
Get an image’s current record.
- list(*, name_prefix=None, sort=None, page_size=None)¶
List images, fetching further pages as iteration reaches them.
- Parameters:
- Return type:
- list_library()¶
List the built-in images available to every team.
- Return type:
- list_tags(*, name, name_prefix=None, sort=None, page_size=None)¶
List an image’s versions, fetching further pages as iteration reaches them.
- Parameters:
- Return type:
- logs(*, name, start_time=None, end_time=None)¶
Get the build log of an image’s latest build, including a failed one.
Oldest line first. Logs may take a short time to appear. Returns at most the 11,000 most recent lines in the range; narrow the range to see earlier ones.
- Parameters:
- Return type:
- push(*, name: str, builder: ImageBuilder, temp_file: bool | None = None, memory: int | None = None, volume: int | None = None, wait: bool = True, timeout: timedelta | None = datetime.timedelta(seconds=900), poll_interval: timedelta = datetime.timedelta(seconds=3)) ImageInfo¶
- push(*, name: str, registry_image: str, docker_config: str | None = None, memory: int | None = None, volume: int | None = None, wait: bool = True, timeout: timedelta | None = datetime.timedelta(seconds=900), poll_interval: timedelta = datetime.timedelta(seconds=3)) ImageInfo
- push(*, name: str, zip: bytes, memory: int | None = None, volume: int | None = None, wait: bool = True, timeout: timedelta | None = datetime.timedelta(seconds=900), poll_interval: timedelta = datetime.timedelta(seconds=3)) ImageInfo
- push(*, name: str, directory: str, ignore_file_processor: Callable[[ImageIgnoreFileProcessorOptions], Callable[[ImageIgnoreFileOptions], bool]] | None = None, default_ignore_file: Callable[[ImageIgnoreFileOptions], bool] | None = None, temp_file: bool | None = None, memory: int | None = None, volume: int | None = None, wait: bool = True, timeout: timedelta | None = datetime.timedelta(seconds=900), poll_interval: timedelta = datetime.timedelta(seconds=3)) ImageInfo
- push(*, name: str, files: Mapping[str, str | bytes], memory: int | None = None, volume: int | None = None, wait: bool = True, timeout: timedelta | None = datetime.timedelta(seconds=900), poll_interval: timedelta = datetime.timedelta(seconds=3)) ImageInfo
Push an image, from a registry or from a build context built into one.
Takes exactly one source. Waits for the image to be ready to use unless wait is false. To create a sandbox from it, pass
<name>:latestas the sandbox’simage.A build context read from local files, from directory or a builder’s local files and directories, is zipped into an anonymous temporary file unless temp_file is false; any other is zipped in memory. It is uploaded in one attempt. If the upload fails, the image is left as the service has it, so push again or delete it.
- Parameters:
name (str) – Repository name. Pushing to an existing name adds a new version to it.
builder (ImageBuilder | None) – Source: a builder whose Dockerfile and files make up the build context.
registry_image (str | None) – Source: a registry image reference to import, including its registry host.
docker_config (str | None) – Serialized registry credentials for a private registry_image.
zip (bytes | None) – Source: a zip archive of the build context, with a
Dockerfileat its root.directory (str | None) – Source: a local directory holding the build context, with a
Dockerfileat its root. Files keep their permissions, a link to a file within the directory stores a copy of the file, a link to a file outside it fails the push, a link to a directory stores an empty directory, and a broken link is left out. Paths are left out as a.dockerignoreat the directory’s root says, read through ignore_file_processor, or else by default_ignore_file. The rootDockerfileand.dockerignoreare always kept, as Docker keeps them.ignore_file_processor (Callable[[ImageIgnoreFileProcessorOptions], Callable[[ImageIgnoreFileOptions], bool]] | None) – Parses the
.dockerignoreat the root of directory. Required if there is one; otherwise the push fails before anything is sent. This package has no.dockerignoreparser of its own.default_ignore_file (Callable[[ImageIgnoreFileOptions], bool] | None) – Filters directory when it has no
.dockerignore. Defaults todefault_image_ignore_file(). Passlambda _: Falseto push everything.files (Mapping[str, str | bytes] | None) – Source: build context files by relative path, with forward slashes. Must include
Dockerfile. A string is written as UTF-8, and files get mode 0644.temp_file (bool | None) – Whether to zip a directory or a builder with local files into a temporary file, rather than in memory. Defaults to true.
memory (int | None) – Memory in megabytes, from 1 to 32768, of the temporary environment that builds the build context or imports registry_image.
Noneuses the default size. Does not change the memory of sandboxes created from the image.volume (int | None) – Scratch disk in megabytes, from 0 to 131072, attached to the build environment for intermediate layers. Set it for a large image that runs out of space while building or importing.
Noneor 0 builds in memory, which is the default. Teams with HIPAA compliance enabled accept onlyNoneor 0.wait (bool) – Whether to return only once the image is ready to use.
timeout (timedelta | None) – How long to wait for the image.
Nonewaits with no limit. Processing continues regardless.poll_interval (timedelta) – How long between checks while waiting.
- Raises:
ImageUploadError – Uploading the build context failed.
ImageBuildError – The build failed, or the wait timed out.
- Return type:
- wait_built(*, name, timeout=datetime.timedelta(seconds=900), poll_interval=datetime.timedelta(seconds=3))¶
Wait for an image to be ready to use.
Checks the image’s current status, so right after pushing a new version of an image that was already built, this may return before the new version is processed; push with wait left on to avoid that.