Skip to content

Commit

Permalink
Split shim module into smaller submodules.
Browse files Browse the repository at this point in the history
Signed-off-by: Jorge Prendes <[email protected]>
  • Loading branch information
jprendes committed Oct 23, 2023
1 parent 1d2cd19 commit 7d21b2e
Show file tree
Hide file tree
Showing 13 changed files with 1,245 additions and 1,330 deletions.
2 changes: 2 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,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 All @@ -84,6 +85,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
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,
stdin: None,
stdout: None,
stderr: None,
bundle: None,
stdin: PathBuf::default(),
stdout: PathBuf::default(),
stderr: PathBuf::default(),
bundle: PathBuf::default(),
containerd_address,
}
}

/// 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
Loading

0 comments on commit 7d21b2e

Please sign in to comment.