Skip to main content

DockerfileTranslator

Struct DockerfileTranslator 

Source
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 overrideRUN cmdbuildah run -- /bin/sh -c "cmd"
  • Windows, no SHELL overrideRUN cmdbuildah run -- cmd.exe /S /C "cmd"
  • Any OS with SHELL ["pwsh", "-Command"] — subsequent RUN cmd uses buildah 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

Source

pub fn new(target_os: ImageOs) -> Self

Create a new translator for a given target OS, with no SHELL override.

Source

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.

Source

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.

Source

pub fn target_os(&self) -> ImageOs

Return the target OS this translator emits commands for.

Source

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).

Source

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.

Source

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

Source§

fn clone(&self) -> DockerfileTranslator

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for DockerfileTranslator

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> FromRef<T> for T
where T: Clone,

Source§

fn from_ref(input: &T) -> T

Converts to this type from a reference to the input type.
Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self>

Converts 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 more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

Converts 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
Source§

impl<T> IntoRequest<T> for T

Source§

fn into_request(self) -> Request<T>

Wrap the input message T in a tonic::Request
Source§

impl<L> LayerExt<L> for L

Source§

fn named_layer<S>(&self, service: S) -> Layered<<L as Layer<S>>::Service, S>
where L: Layer<S>,

Applies the layer to a service and wraps it in Layered.
Source§

impl<T> PolicyExt for T
where T: ?Sized,

Source§

fn and<P, B, E>(self, other: P) -> And<T, P>
where T: Sized + Policy<B, E>, P: Policy<B, E>,

Create a new Policy that returns Action::Follow only if self and other return Action::Follow. Read more
Source§

fn or<P, B, E>(self, other: P) -> Or<T, P>
where T: Sized + Policy<B, E>, P: Policy<B, E>,

Create a new Policy that returns Action::Follow if either self or other returns Action::Follow. Read more
Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more