Skip to content

Commit

Permalink
Merge pull request #345 from jprendes:split-sandbox-shim
Browse files Browse the repository at this point in the history
[refactor] split sandbox shim
  • Loading branch information
cpuguy83 authored Oct 27, 2023
2 parents 5a0a47a + fa88237 commit 59cab2f
Show file tree
Hide file tree
Showing 17 changed files with 1,235 additions and 1,337 deletions.
2 changes: 2 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,7 @@ jobs:
name: ${{ matrix.runtime }}
needs: [build-ubuntu, test-image]
strategy:
fail-fast: false
matrix:
# 20.04 uses cgroupv1, 22.04 uses cgroupv2
os: ["ubuntu-20.04", "ubuntu-22.04"]
Expand Down Expand Up @@ -108,6 +109,7 @@ jobs:
name: ${{ matrix.runtime }}
needs: [build-ubuntu, test-image]
strategy:
fail-fast: false
matrix:
os: ["ubuntu-20.04", "ubuntu-22.04"]
runtime: ["wasmtime", "wasmedge", "wasmer"]
Expand Down
3 changes: 2 additions & 1 deletion crates/containerd-shim-wasm/src/sandbox/cli.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,8 @@ use containerd_shim::{parse, run, Config};
use ttrpc::Server;

use crate::sandbox::manager::Shim;
use crate::sandbox::{Instance, Local, ManagerService, ShimCli};
use crate::sandbox::shim::Local;
use crate::sandbox::{Instance, ManagerService, ShimCli};
use crate::services::sandbox_ttrpc::{create_manager, Manager};

pub mod r#impl {
Expand Down
2 changes: 1 addition & 1 deletion crates/containerd-shim-wasm/src/sandbox/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ pub enum Error {
Containerd(String),
}

pub type Result<T> = ::std::result::Result<T, Error>;
pub type Result<T, E = Error> = ::std::result::Result<T, E>;

impl From<Error> for ttrpc::Error {
fn from(e: Error) -> Self {
Expand Down
57 changes: 32 additions & 25 deletions crates/containerd-shim-wasm/src/sandbox/instance.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
//! Abstractions for running/managing a wasm/wasi instance.

use std::path::{Path, PathBuf};
use std::time::Duration;

use chrono::{DateTime, Utc};
Expand All @@ -16,74 +17,80 @@ pub struct InstanceConfig<Engine: Send + Sync + Clone> {
/// This should be cheap to clone.
engine: Engine,
/// Optional stdin named pipe path.
stdin: Option<String>,
stdin: PathBuf,
/// Optional stdout named pipe path.
stdout: Option<String>,
stdout: PathBuf,
/// Optional stderr named pipe path.
stderr: Option<String>,
stderr: PathBuf,
/// Path to the OCI bundle directory.
bundle: Option<String>,
bundle: PathBuf,
/// Namespace for containerd
namespace: String,
// /// GRPC address back to main containerd
containerd_address: String,
}

impl<Engine: Send + Sync + Clone> InstanceConfig<Engine> {
pub fn new(engine: Engine, namespace: String, containerd_address: String) -> Self {
pub fn new(
engine: Engine,
namespace: impl AsRef<str>,
containerd_address: impl AsRef<str>,
) -> Self {
let namespace = namespace.as_ref().to_string();
let containerd_address = containerd_address.as_ref().to_string();
Self {
engine,
namespace,
containerd_address,
stdin: None,
stdout: None,
stderr: None,
bundle: None,
stdin: PathBuf::default(),
stdout: PathBuf::default(),
stderr: PathBuf::default(),
bundle: PathBuf::default(),
}
}

/// set the stdin path for the instance
pub fn set_stdin(&mut self, stdin: String) -> &mut Self {
self.stdin = Some(stdin);
pub fn set_stdin(&mut self, stdin: impl AsRef<Path>) -> &mut Self {
self.stdin = stdin.as_ref().to_path_buf();
self
}

/// get the stdin path for the instance
pub fn get_stdin(&self) -> Option<String> {
self.stdin.clone()
pub fn get_stdin(&self) -> &Path {
&self.stdin
}

/// set the stdout path for the instance
pub fn set_stdout(&mut self, stdout: String) -> &mut Self {
self.stdout = Some(stdout);
pub fn set_stdout(&mut self, stdout: impl AsRef<Path>) -> &mut Self {
self.stdout = stdout.as_ref().to_path_buf();
self
}

/// get the stdout path for the instance
pub fn get_stdout(&self) -> Option<String> {
self.stdout.clone()
pub fn get_stdout(&self) -> &Path {
&self.stdout
}

/// set the stderr path for the instance
pub fn set_stderr(&mut self, stderr: String) -> &mut Self {
self.stderr = Some(stderr);
pub fn set_stderr(&mut self, stderr: impl AsRef<Path>) -> &mut Self {
self.stderr = stderr.as_ref().to_path_buf();
self
}

/// get the stderr path for the instance
pub fn get_stderr(&self) -> Option<String> {
self.stderr.clone()
pub fn get_stderr(&self) -> &Path {
&self.stderr
}

/// set the OCI bundle path for the instance
pub fn set_bundle(&mut self, bundle: String) -> &mut Self {
self.bundle = Some(bundle);
pub fn set_bundle(&mut self, bundle: impl AsRef<Path>) -> &mut Self {
self.bundle = bundle.as_ref().to_path_buf();
self
}

/// get the OCI bundle path for the instance
pub fn get_bundle(&self) -> Option<String> {
self.bundle.clone()
pub fn get_bundle(&self) -> &Path {
&self.bundle
}

/// get the wasm engine for the instance
Expand Down
2 changes: 1 addition & 1 deletion crates/containerd-shim-wasm/src/sandbox/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ pub mod sync;
pub use error::{Error, Result};
pub use instance::{Instance, InstanceConfig};
pub use manager::{Sandbox as SandboxService, Service as ManagerService};
pub use shim::{Cli as ShimCli, Local};
pub use shim::Cli as ShimCli;
pub use stdio::Stdio;

pub(crate) mod containerd;
Expand Down
Loading

0 comments on commit 59cab2f

Please sign in to comment.