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 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 · 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 more