pub struct BundleBuilder { /* private fields */ }Expand description
Builder for OCI container bundles
Creates the directory structure and config.json required for OCI-compliant container runtimes like runc or youki.
§Example
let dirs = zlayer_paths::ZLayerDirs::system_default();
let builder = BundleBuilder::new(dirs.bundles().join("mycontainer"))
.with_rootfs(dirs.rootfs().join("myimage"));
let bundle_path = builder.build(&container_id, &service_spec).await?;Implementations§
Source§impl BundleBuilder
impl BundleBuilder
Sourcepub fn new(bundle_dir: PathBuf) -> Self
pub fn new(bundle_dir: PathBuf) -> Self
Create a new BundleBuilder with the specified bundle directory
The bundle directory will be created if it doesn’t exist. The structure will be:
{bundle_dir}/
├── config.json
└── rootfs/ (symlink to actual rootfs or mount point)Sourcepub fn for_container(container_id: &ContainerId) -> Self
pub fn for_container(container_id: &ContainerId) -> Self
Create a BundleBuilder for a container in the default bundle location
Sourcepub fn with_rootfs(self, rootfs_path: PathBuf) -> Self
pub fn with_rootfs(self, rootfs_path: PathBuf) -> Self
Set the rootfs path (from unpacked image layers)
This path will be symlinked into the bundle as rootfs/
Sourcepub fn with_hostname(self, hostname: String) -> Self
pub fn with_hostname(self, hostname: String) -> Self
Set a custom hostname for the container
Sourcepub fn with_volume_paths(self, volume_paths: HashMap<String, PathBuf>) -> Self
pub fn with_volume_paths(self, volume_paths: HashMap<String, PathBuf>) -> Self
Set pre-resolved volume paths from StorageManager
These are used to map named/anonymous/S3 volumes to their host paths when building storage mounts in the OCI spec.
Sourcepub fn with_image_config(self, config: ImageConfig) -> Self
pub fn with_image_config(self, config: ImageConfig) -> Self
Set the OCI image configuration (entrypoint, cmd, env, workdir, user)
When set, the image config provides defaults for the container process that are used when the deployment spec doesn’t override them.
Sourcepub fn with_host_network(self, host_network: bool) -> Self
pub fn with_host_network(self, host_network: bool) -> Self
Enable host networking mode
When true, the container will NOT get its own network namespace and will
share the host’s network stack. This is equivalent to Docker’s --network host.
Use this when overlay networking is unavailable or not desired.
Sourcepub fn with_secrets_provider(self, provider: Arc<dyn SecretsProvider>) -> Self
pub fn with_secrets_provider(self, provider: Arc<dyn SecretsProvider>) -> Self
Set the secrets provider for resolving $S: prefixed environment variables
When set, environment variables with $S:secret-name syntax will be resolved
from this provider at bundle creation time.
Sourcepub fn with_deployment_scope(self, scope: String) -> Self
pub fn with_deployment_scope(self, scope: String) -> Self
Set the deployment scope for secret lookups
This is typically the deployment name and is used as the scope when
resolving $S: prefixed environment variables.
Sourcepub fn with_socket_mount(self, path: impl Into<String>) -> Self
pub fn with_socket_mount(self, path: impl Into<String>) -> Self
Set a host-side Unix socket path to bind-mount into the container at
the default ZLayer socket path (read-only).
Sourcepub fn bundle_dir(&self) -> &Path
pub fn bundle_dir(&self) -> &Path
Get the bundle directory path
Sourcepub async fn build(
&self,
container_id: &ContainerId,
spec: &ServiceSpec,
) -> Result<PathBuf>
pub async fn build( &self, container_id: &ContainerId, spec: &ServiceSpec, ) -> Result<PathBuf>
Build the OCI bundle from a ServiceSpec
Creates the bundle directory structure and generates config.json based on the provided service specification.
§Returns
The path to the bundle directory on success
§Errors
AgentError::CreateFailedif directory creation failsAgentError::InvalidSpecif the OCI spec generation fails
Sourcepub async fn build_spec_only(
&self,
container_id: &ContainerId,
spec: &ServiceSpec,
volume_paths: &HashMap<String, PathBuf>,
) -> Result<Spec>
pub async fn build_spec_only( &self, container_id: &ContainerId, spec: &ServiceSpec, volume_paths: &HashMap<String, PathBuf>, ) -> Result<Spec>
Render the OCI runtime spec without creating a bundle directory
or writing config.json.
Used by the WSL2 delegate runtime (runtimes/wsl2_delegate.rs):
the Windows host renders the spec, then streams the JSON into the
WSL distro filesystem where youki will consume it. The bundle
path passed to BundleBuilder::new is purely informational in
that flow; this method never touches the filesystem.
§Errors
Returns AgentError::InvalidSpec if the spec generation fails.
Sourcepub async fn write_config(
&self,
container_id: &ContainerId,
spec: &ServiceSpec,
) -> Result<PathBuf>
pub async fn write_config( &self, container_id: &ContainerId, spec: &ServiceSpec, ) -> Result<PathBuf>
Generate the OCI spec and write config.json to the bundle directory
Unlike build(), this does NOT create the bundle directory or set up rootfs.
Use this when the bundle directory and rootfs already exist (e.g., rootfs was
extracted directly by LayerUnpacker).
§Errors
Returns an error if the OCI spec cannot be built or config.json cannot be written.
§Returns
The path to the bundle directory on success
Trait Implementations§
Source§impl Clone for BundleBuilder
impl Clone for BundleBuilder
Source§fn clone(&self) -> BundleBuilder
fn clone(&self) -> BundleBuilder
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 BundleBuilder
impl !RefUnwindSafe for BundleBuilder
impl Send for BundleBuilder
impl Sync for BundleBuilder
impl Unpin for BundleBuilder
impl UnsafeUnpin for BundleBuilder
impl !UnwindSafe for BundleBuilder
Blanket Implementations§
Source§impl<'a, T, E> AsTaggedExplicit<'a, E> for Twhere
T: 'a,
impl<'a, T, E> AsTaggedExplicit<'a, E> for Twhere
T: 'a,
Source§impl<'a, T, E> AsTaggedImplicit<'a, E> for Twhere
T: 'a,
impl<'a, T, E> AsTaggedImplicit<'a, E> for Twhere
T: 'a,
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> FutureExt for T
impl<T> FutureExt for T
Source§fn with_context(self, otel_cx: Context) -> WithContext<Self>
fn with_context(self, otel_cx: Context) -> WithContext<Self>
Source§fn with_current_context(self) -> WithContext<Self>
fn with_current_context(self) -> WithContext<Self>
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> 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::RequestSource§impl<T> PolicyExt for Twhere
T: ?Sized,
impl<T> PolicyExt for Twhere
T: ?Sized,
Source§impl<T> ServiceExt for T
impl<T> ServiceExt for T
Source§fn propagate_header(self, header: HeaderName) -> PropagateHeader<Self>where
Self: Sized,
fn propagate_header(self, header: HeaderName) -> PropagateHeader<Self>where
Self: Sized,
Source§fn add_extension<T>(self, value: T) -> AddExtension<Self, T>where
Self: Sized,
fn add_extension<T>(self, value: T) -> AddExtension<Self, T>where
Self: Sized,
Source§fn map_request_body<F>(self, f: F) -> MapRequestBody<Self, F>where
Self: Sized,
fn map_request_body<F>(self, f: F) -> MapRequestBody<Self, F>where
Self: Sized,
Source§fn map_response_body<F>(self, f: F) -> MapResponseBody<Self, F>where
Self: Sized,
fn map_response_body<F>(self, f: F) -> MapResponseBody<Self, F>where
Self: Sized,
Source§fn compression(self) -> Compression<Self>where
Self: Sized,
fn compression(self) -> Compression<Self>where
Self: Sized,
Source§fn decompression(self) -> Decompression<Self>where
Self: Sized,
fn decompression(self) -> Decompression<Self>where
Self: Sized,
Source§fn trace_for_http(self) -> Trace<Self, SharedClassifier<ServerErrorsAsFailures>>where
Self: Sized,
fn trace_for_http(self) -> Trace<Self, SharedClassifier<ServerErrorsAsFailures>>where
Self: Sized,
Source§fn trace_for_grpc(self) -> Trace<Self, SharedClassifier<GrpcErrorsAsFailures>>where
Self: Sized,
fn trace_for_grpc(self) -> Trace<Self, SharedClassifier<GrpcErrorsAsFailures>>where
Self: Sized,
Source§fn follow_redirects(self) -> FollowRedirect<Self>where
Self: Sized,
fn follow_redirects(self) -> FollowRedirect<Self>where
Self: Sized,
Source§fn sensitive_headers(
self,
headers: impl IntoIterator<Item = HeaderName>,
) -> SetSensitiveRequestHeaders<SetSensitiveResponseHeaders<Self>>where
Self: Sized,
fn sensitive_headers(
self,
headers: impl IntoIterator<Item = HeaderName>,
) -> SetSensitiveRequestHeaders<SetSensitiveResponseHeaders<Self>>where
Self: Sized,
Source§fn sensitive_request_headers(
self,
headers: impl IntoIterator<Item = HeaderName>,
) -> SetSensitiveRequestHeaders<Self>where
Self: Sized,
fn sensitive_request_headers(
self,
headers: impl IntoIterator<Item = HeaderName>,
) -> SetSensitiveRequestHeaders<Self>where
Self: Sized,
Source§fn sensitive_response_headers(
self,
headers: impl IntoIterator<Item = HeaderName>,
) -> SetSensitiveResponseHeaders<Self>where
Self: Sized,
fn sensitive_response_headers(
self,
headers: impl IntoIterator<Item = HeaderName>,
) -> SetSensitiveResponseHeaders<Self>where
Self: Sized,
Source§fn override_request_header<M>(
self,
header_name: HeaderName,
make: M,
) -> SetRequestHeader<Self, M>where
Self: Sized,
fn override_request_header<M>(
self,
header_name: HeaderName,
make: M,
) -> SetRequestHeader<Self, M>where
Self: Sized,
Source§fn append_request_header<M>(
self,
header_name: HeaderName,
make: M,
) -> SetRequestHeader<Self, M>where
Self: Sized,
fn append_request_header<M>(
self,
header_name: HeaderName,
make: M,
) -> SetRequestHeader<Self, M>where
Self: Sized,
Source§fn insert_request_header_if_not_present<M>(
self,
header_name: HeaderName,
make: M,
) -> SetRequestHeader<Self, M>where
Self: Sized,
fn insert_request_header_if_not_present<M>(
self,
header_name: HeaderName,
make: M,
) -> SetRequestHeader<Self, M>where
Self: Sized,
Source§fn override_response_header<M>(
self,
header_name: HeaderName,
make: M,
) -> SetResponseHeader<Self, M>where
Self: Sized,
fn override_response_header<M>(
self,
header_name: HeaderName,
make: M,
) -> SetResponseHeader<Self, M>where
Self: Sized,
Source§fn append_response_header<M>(
self,
header_name: HeaderName,
make: M,
) -> SetResponseHeader<Self, M>where
Self: Sized,
fn append_response_header<M>(
self,
header_name: HeaderName,
make: M,
) -> SetResponseHeader<Self, M>where
Self: Sized,
Source§fn insert_response_header_if_not_present<M>(
self,
header_name: HeaderName,
make: M,
) -> SetResponseHeader<Self, M>where
Self: Sized,
fn insert_response_header_if_not_present<M>(
self,
header_name: HeaderName,
make: M,
) -> SetResponseHeader<Self, M>where
Self: Sized,
Source§fn set_request_id<M>(
self,
header_name: HeaderName,
make_request_id: M,
) -> SetRequestId<Self, M>where
Self: Sized,
M: MakeRequestId,
fn set_request_id<M>(
self,
header_name: HeaderName,
make_request_id: M,
) -> SetRequestId<Self, M>where
Self: Sized,
M: MakeRequestId,
Source§fn set_x_request_id<M>(self, make_request_id: M) -> SetRequestId<Self, M>where
Self: Sized,
M: MakeRequestId,
fn set_x_request_id<M>(self, make_request_id: M) -> SetRequestId<Self, M>where
Self: Sized,
M: MakeRequestId,
x-request-id as the header name. Read moreSource§fn propagate_request_id(
self,
header_name: HeaderName,
) -> PropagateRequestId<Self>where
Self: Sized,
fn propagate_request_id(
self,
header_name: HeaderName,
) -> PropagateRequestId<Self>where
Self: Sized,
Source§fn propagate_x_request_id(self) -> PropagateRequestId<Self>where
Self: Sized,
fn propagate_x_request_id(self) -> PropagateRequestId<Self>where
Self: Sized,
x-request-id as the header name. Read moreSource§fn catch_panic(self) -> CatchPanic<Self, DefaultResponseForPanic>where
Self: Sized,
fn catch_panic(self) -> CatchPanic<Self, DefaultResponseForPanic>where
Self: Sized,
500 Internal Server responses. Read moreSource§fn request_body_limit(self, limit: usize) -> RequestBodyLimit<Self>where
Self: Sized,
fn request_body_limit(self, limit: usize) -> RequestBodyLimit<Self>where
Self: Sized,
413 Payload Too Large responses. Read more