ImageBuilder¶
- class baseten.sandbox.ImageBuilder¶
Bases:
objectAn image described as a Dockerfile and the files it copies in.
Push it with
ImageClient.push(). Start one withImageBuilder.from_registry().A builder never changes: each method returns a new builder with the instruction appended, so one builder can safely be the base of several. Invalid input raises
ValueErrorat the call that takes it.The Dockerfile it pushes ends by copying in the sandbox API binary and making it the entrypoint, unless the builder already did either, since a sandbox needs it running to be reached.
dockerfile()shows the Dockerfile exactly as pushed.- Parameters:
state (_BuilderState)
- add_file(destination, content, *, context_name=None, mode=420)¶
Add a file with the given content to the build context and append
COPY ["<name>", "<destination>"].The name is the file’s name in the context.
- Parameters:
destination (str) – Path of the file in the image.
content (str | bytes) – Content of the file. A string is written as UTF-8.
context_name (str | None) – Name in the build context. Defaults to the destination’s basename, with a suffix such as `` (1)`` if another entry already has that name.
mode (int) – Unix permission bits of the file in the image.
- Return type:
- add_local_dir(source_path, destination, *, context_name=None)¶
Add a local directory to the build context and append
COPY ["<name>", "<destination>"].The name is the directory’s name in the context. As with any
COPYof a directory, its contents are copied into the destination, not the directory itself. It is read when pushed, with files keeping their permissions, a link to a file within the directory stored as a copy of the file, a link to a file outside it failing the push, and a link to a directory stored as an empty directory. Everything in it is added: no.dockerignoreor default ignore rules apply.- Parameters:
- Return type:
- add_local_file(source_path, destination, *, context_name=None)¶
Add a local file to the build context and append
COPY ["<name>", "<destination>"].The name is the file’s name in the context. The file is read when pushed, keeping its permissions, and a symbolic link is read as the file it points to.
- Parameters:
- Return type:
- apt_install(*args)¶
Append an
apt-get installof the packages as one step.The step is
RUN apt-get update && apt-get install -y --no-install-recommends <args> && rm -rf /var/lib/apt/lists/*, so the package lists add nothing to the image.- Parameters:
args (str)
- Return type:
- arg(name, default=None)¶
Append
ARG <name>, orARG <name>="<default>"escaped as inenv().- Parameters:
- Return type:
- copy(source, destination)¶
Append
COPY ["<source>", "<destination>"], copying from the build context.- Parameters:
- Return type:
- dockerfile_lines(*lines)¶
Append each line verbatim.
For anything the other methods do not cover, such as comments,
CMD, or a heredoc. A line may contain newlines, and nothing is checked or escaped.- Parameters:
lines (str)
- Return type:
- entrypoint(*args)¶
Append
ENTRYPOINT ["<arg>", ...], in exec form.The image then runs this instead of the sandbox API binary, so it must start that itself for the sandbox to be reachable.
- Parameters:
args (str)
- Return type:
- env(variables)¶
Append
ENV <name>="<value>"for each variable."and\in the value are escaped.$is left as is, so the build expands variables in it, as in{"PATH": "/opt/bin:$PATH"}.- Parameters:
- Return type:
- classmethod from_registry(base_image, *, sandbox_api_image=None)¶
Start a builder from a registry image, as
FROM <base_image>.- Parameters:
- Return type:
- gem_install(*args)¶
Append
RUN gem install --no-document <args>.- Parameters:
args (str)
- Return type:
- go_install(*packages)¶
Append
RUN go install <package> && go install <package> ....One
go installper package, since one call can only install packages from a single module.- Parameters:
packages (str)
- Return type:
- label(labels)¶
Append
LABEL <key>="<value>"for each label, escaped as inenv().- Parameters:
- Return type:
- npm_install(*args)¶
Append
RUN npm install <args>.With no arguments, appends
RUN npm install, to install from the working directory’spackage.json.- Parameters:
args (str)
- Return type:
- pipx_install(*packages)¶
Append
RUN pipx install <package> && pipx install <package> ..., one per package.- Parameters:
packages (str)
- Return type:
- run_commands(*commands)¶
Append
RUN <command>for each command, in shell form.- Parameters:
commands (str)
- Return type: