pub struct DockerfileTranslator { /* private fields */ }Expand description
Stateful translator from Instruction to BuildahCommand sequences.
Tracks the target OS and the most recent SHELL instruction so that
shell-form RUN / CMD / ENTRYPOINT use the correct shell for the
target platform:
- Linux, no SHELL override —
RUN cmd→buildah run -- /bin/sh -c "cmd" - Windows, no SHELL override —
RUN cmd→buildah run -- cmd.exe /S /C "cmd" - Any OS with
SHELL ["pwsh", "-Command"]— subsequentRUN cmdusesbuildah run -- pwsh -Command "cmd"
The translator is stateful because Dockerfile SHELL instructions persist
across subsequent RUN/CMD/ENTRYPOINT translations until another
SHELL replaces them. Callers that translate a multi-instruction stage
should reuse a single translator instance across the full instruction
stream.
This translator is designed to be shared between the buildah backend and the Phase L-4 HCS (Windows host compute service) backend, so neither needs to re-implement the shell-form / workdir branching.
Implementations§
Source§impl DockerfileTranslator
impl DockerfileTranslator
Sourcepub fn new(target_os: ImageOs) -> Self
pub fn new(target_os: ImageOs) -> Self
Create a new translator for a given target OS, with no SHELL override.
Sourcepub fn with_empty_src_dir(self, dir: PathBuf) -> Self
pub fn with_empty_src_dir(self, dir: PathBuf) -> Self
Point WORKDIR translation at an empty host directory used as the
source for buildah copy, which materializes the workdir in the
container rootfs without executing a process inside the container.
Without this, WORKDIR falls back to buildah run -- mkdir -p <dir>,
which fails on distroless / scratch images that lack a shell.
Production callers (the BuildahBackend’s build loop) should create
a TempDir for the lifetime of the build and pass its path here.
The translator does NOT own the directory’s lifecycle — callers
must keep it alive (and empty) until every translated WORKDIR
buildah copy command has finished executing.
Sourcepub fn with_host_network(self, on: bool) -> Self
pub fn with_host_network(self, on: bool) -> Self
Force every translated RUN instruction to use host networking.
When on is true, the translator overrides any per-instruction
network value (including None) with RunNetwork::Host before
emitting the buildah command. This mirrors the effect of Docker’s
docker build --network=host flag and bypasses buildah’s CNI /
netavark plumbing entirely. When on is false (the default),
per-instruction network values are passed through unchanged.
Sourcepub fn active_shell(&self) -> Vec<String>
pub fn active_shell(&self) -> Vec<String>
Return the current shell-form prefix: the SHELL override if one was
applied, else the OS default (/bin/sh -c on Linux, cmd.exe /S /C on
Windows).
Sourcepub fn set_shell_override(&mut self, shell: Vec<String>)
pub fn set_shell_override(&mut self, shell: Vec<String>)
Replace the translator’s SHELL override, matching the effect of a
Dockerfile SHELL ["…"] instruction on subsequent RUN/CMD/ENTRYPOINT
shell-form commands.
Sourcepub fn translate(
&mut self,
container: &str,
instruction: &Instruction,
) -> Vec<BuildahCommand>
pub fn translate( &mut self, container: &str, instruction: &Instruction, ) -> Vec<BuildahCommand>
Translate a single instruction into zero or more BuildahCommands.
Stateful: SHELL instructions update the translator’s shell override,
so subsequent RUN / CMD / ENTRYPOINT shell-form translations pick
up the new shell. WORKDIR emits an OS-appropriate pre-mkdir followed
by buildah config --workingdir.
Trait Implementations§
Source§impl Clone for DockerfileTranslator
impl Clone for DockerfileTranslator
Source§fn clone(&self) -> DockerfileTranslator
fn clone(&self) -> DockerfileTranslator
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read moreAuto Trait Implementations§
impl Freeze for DockerfileTranslator
impl RefUnwindSafe for DockerfileTranslator
impl Send for DockerfileTranslator
impl Sync for DockerfileTranslator
impl Unpin for DockerfileTranslator
impl UnsafeUnpin for DockerfileTranslator
impl UnwindSafe for DockerfileTranslator
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
Source§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§impl<T> IntoRequest<T> for T
impl<T> IntoRequest<T> for T
Source§fn into_request(self) -> Request<T>
fn into_request(self) -> Request<T>
T in a tonic::Request