Skip to content

Commit

Permalink
Merge pull request #314 from jprendes/simple-api-windows
Browse files Browse the repository at this point in the history
Simple api on Windows
  • Loading branch information
Mossaka committed Sep 19, 2023
2 parents 36e2399 + cb94bee commit c2c6d14
Show file tree
Hide file tree
Showing 29 changed files with 87 additions and 355 deletions.
222 changes: 11 additions & 211 deletions Cargo.lock

Large diffs are not rendered by default.

24 changes: 12 additions & 12 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -20,26 +20,26 @@ homepage = "https://github.com/containerd/runwasi"

[workspace.dependencies]
anyhow = "1.0"
cap-std = "1.0"
chrono = { version = "0.4", default-features = false, features = ["clock"] }
containerd-shim = "0.5.0"
containerd-shim-wasm = { path = "crates/containerd-shim-wasm" }
containerd-shim-wasm-test = { path = "crates/containerd-shim-wasm-test" }
serde = "1.0"
serde_json = "1.0"
crossbeam = { version = "0.8.2", default-features = false }
env_logger = "0.10"
libc = "0.2.147"
libcontainer = { version = "0.2", default-features = false }
log = "0.4"
tar = "0.4"
containerd-shim = "0.5.0"
ttrpc = "0.8.0"
chrono = { version = "0.4", default-features = false, features = ["clock"] }
nix = "0.26"
cap-std = "1.0"
thiserror = "1.0"
libc = "0.2.147"
oci-spec = { version = "0.6.1", features = ["runtime"] }
serde = "1.0"
serde_json = "1.0"
sha256 = "1.4.0"
libcontainer = { version = "0.2", default-features = false }
windows-sys = { version = "0.48" }
crossbeam = { version = "0.8.2", default-features = false }
tar = "0.4"
thiserror = "1.0"
ttrpc = "0.8.0"
wat = "*" # Use whatever version wasmtime will make us pull
windows-sys = { version = "0.48" }

[profile.release]
panic = "abort"
3 changes: 0 additions & 3 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,9 @@ ifeq ($(TARGET),release)
RELEASE_FLAG = --release
endif

FEATURES_wasm = --features libcontainer_default
FEATURES_wasmedge =
WARNINGS = -D warnings
ifeq ($(OS), Windows_NT)
# need to disable libcontainer
FEATURES_wasm =
# need to turn off static/standalone for wasm-edge
FEATURES_wasmedge = --no-default-features
# turn of warnings until windows is fully supported #49
Expand Down
11 changes: 2 additions & 9 deletions crates/containerd-shim-wasm/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,8 @@ wat = { workspace = true }

[target.'cfg(unix)'.dependencies]
caps = "0.5"
dbus = { version = "*", optional = true }
libcontainer = { workspace = true, optional = true, default-features = false }
dbus = { version = "*", features = ["vendored"] }
libcontainer = { workspace = true, features = ["libseccomp", "systemd", "v1", "v2"]}
nix = { workspace = true }

[target.'cfg(windows)'.dependencies]
Expand All @@ -43,12 +43,5 @@ ttrpc-codegen = { version = "0.4.2", optional = true }
tempfile = "3.8"

[features]
default = []
libcontainer_default = ["libcontainer/default", "dbus/vendored"]
generate_bindings = ["ttrpc-codegen"]
generate_doc = []
libseccomp = ["libcontainer/libseccomp"]
systemd = ["libcontainer/systemd", "dbus/vendored"]
cgroupsv2 = ["libcontainer/v2"]
cgroupsv1 = ["libcontainer/v1"]
cgroupsv2_devices = ["libcontainer/cgroupsv2_devices"]
3 changes: 1 addition & 2 deletions crates/containerd-shim-wasm/src/container/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,6 @@

mod context;
mod engine;
mod executor;
mod instance;
mod path;

pub use context::{RuntimeContext, WasiEntrypoint};
Expand All @@ -22,3 +20,4 @@ pub use instance::Instance;
pub use path::PathResolve;

pub use crate::sandbox::stdio::Stdio;
use crate::sys::container::instance;
5 changes: 2 additions & 3 deletions crates/containerd-shim-wasm/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,10 @@
html_logo_url = "https://raw.githubusercontent.com/containerd/runwasi/e251de3307bbdc8bf3229020ea2ae2711f31aafa/art/logo/runwasi_logo_icon.svg"
)]

pub mod container;
pub mod sandbox;
pub mod services;

#[cfg_attr(unix, path = "sys/unix/mod.rs")]
#[cfg_attr(windows, path = "sys/windows/mod.rs")]
pub(crate) mod sys;

#[cfg(feature = "libcontainer")]
pub mod container;
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 @@ -43,7 +43,7 @@ pub enum Error {
#[error("{0}")]
Errno(#[from] nix::errno::Errno),
/// Errors from libcontainer
#[cfg(all(feature = "libcontainer", not(target_os = "windows")))]
#[cfg(unix)]
#[error("{0}")]
Libcontainer(#[from] libcontainer::error::LibcontainerError),
}
Expand Down
4 changes: 2 additions & 2 deletions crates/containerd-shim-wasm/src/sandbox/oci.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ fn parse_env(envs: &[String]) -> HashMap<String, String> {
.collect()
}

pub fn setup_prestart_hooks(hooks: &Option<oci_spec::runtime::Hooks>) -> Result<()> {
pub(crate) fn setup_prestart_hooks(hooks: &Option<oci_spec::runtime::Hooks>) -> Result<()> {
if let Some(hooks) = hooks {
let prestart_hooks = hooks.prestart().as_ref().unwrap();

Expand Down Expand Up @@ -55,7 +55,7 @@ pub fn setup_prestart_hooks(hooks: &Option<oci_spec::runtime::Hooks>) -> Result<
}
} else {
#[cfg(unix)]
hook_command.arg0(&hook.path().display().to_string());
hook_command.arg0(hook.path());
};

let envs: HashMap<String, String> = if let Some(env) = hook.env() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,7 @@ use libcontainer::workload::{
};
use oci_spec::runtime::Spec;

use crate::container::context::RuntimeContext;
use crate::container::engine::Engine;
use crate::container::PathResolve;
use crate::sandbox::Stdio;
use crate::container::{Engine, PathResolve, RuntimeContext, Stdio};

#[derive(Clone)]
enum InnerExecutor {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,11 @@ use libcontainer::syscall::syscall::SyscallType;
use nix::errno::Errno;
use nix::sys::wait::{waitid, Id as WaitID, WaitPidFlag, WaitStatus};

use crate::container::executor::Executor;
use crate::container::Engine;
use crate::sandbox::instance::{ExitCode, Wait};
use crate::sandbox::instance_utils::{determine_rootdir, get_instance_root, instance_exists};
use crate::sandbox::{Error as SandboxError, Instance as SandboxInstance, InstanceConfig, Stdio};
use crate::sys::container::executor::Executor;

static DEFAULT_CONTAINER_ROOT_DIR: &str = "/run/containerd";

Expand Down
2 changes: 2 additions & 0 deletions crates/containerd-shim-wasm/src/sys/unix/container/mod.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
mod executor;
pub mod instance;
5 changes: 2 additions & 3 deletions crates/containerd-shim-wasm/src/sys/unix/metrics.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
use anyhow::Result;
use containerd_shim::{self as shim};
use containerd_shim::cgroup::collect_metrics;
use containerd_shim::util::convert_to_any;
use protobuf::well_known_types::any::Any;
use shim::cgroup::collect_metrics;
use shim::util::convert_to_any;

pub fn get_metrics(pid: u32) -> Result<Any> {
let metrics = collect_metrics(pid)?;
Expand Down
1 change: 1 addition & 0 deletions crates/containerd-shim-wasm/src/sys/unix/mod.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
pub mod container;
pub mod metrics;
pub mod networking;
pub mod signals;
Expand Down
43 changes: 43 additions & 0 deletions crates/containerd-shim-wasm/src/sys/windows/container/instance.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
use std::marker::PhantomData;

use crate::container::Engine;
use crate::sandbox::instance::Wait;
use crate::sandbox::{Error as SandboxError, Instance as SandboxInstance, InstanceConfig};

pub struct Instance<E: Engine>(PhantomData<E>);

impl<E: Engine> SandboxInstance for Instance<E> {
type Engine = E;

fn new(_id: String, _cfg: Option<&InstanceConfig<Self::Engine>>) -> Self {
todo!();
}

/// Start the instance
/// The returned value should be a unique ID (such as a PID) for the instance.
/// Nothing internally should be using this ID, but it is returned to containerd where a user may want to use it.
fn start(&self) -> Result<u32, SandboxError> {
todo!();
}

/// Send a signal to the instance
fn kill(&self, _signal: u32) -> Result<(), SandboxError> {
todo!();
}

/// Delete any reference to the instance
/// This is called after the instance has exited.
fn delete(&self) -> Result<(), SandboxError> {
todo!();
}

/// Set up waiting for the instance to exit
/// The Wait struct is used to send the exit code and time back to the
/// caller. The recipient is expected to call function
/// set_up_exit_code_wait() implemented by Wait to set up exit code
/// processing. Note that the "wait" function doesn't block, but
/// it sets up the waiting channel.
fn wait(&self, _waiter: &Wait) -> Result<(), SandboxError> {
todo!();
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
pub mod instance;
3 changes: 1 addition & 2 deletions crates/containerd-shim-wasm/src/sys/windows/metrics.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
use anyhow::Result;
use containerd_shim::{self as shim};
use containerd_shim::util::convert_to_any;
use oci_spec::runtime;
use protobuf::well_known_types::any::Any;
use shim::util::convert_to_any;

pub fn get_metrics(pid: u32) -> Result<Any> {
// Create empty message for now
Expand Down
1 change: 1 addition & 0 deletions crates/containerd-shim-wasm/src/sys/windows/mod.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
pub mod container;
pub mod metrics;
pub mod networking;
pub mod signals;
Expand Down
5 changes: 1 addition & 4 deletions crates/containerd-shim-wasmedge/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -6,17 +6,14 @@ edition.workspace = true
[dependencies]
anyhow = { workspace = true }
containerd-shim = { workspace = true }
containerd-shim-wasm = { workspace = true, features = ["libcontainer_default"] }
containerd-shim-wasm = { workspace = true }
log = { workspace = true }
oci-spec = { workspace = true, features = ["runtime"] }
ttrpc = { workspace = true }

wasmedge-sdk = { version = "0.12.1" }
wasmedge-sys = "*"

[target.'cfg(unix)'.dependencies]
libcontainer = { workspace = true }

[dev-dependencies]
containerd-shim-wasm-test = { workspace = true }
libc = { workspace = true }
Expand Down
28 changes: 0 additions & 28 deletions crates/containerd-shim-wasmedge/src/instance_windows.rs

This file was deleted.

2 changes: 0 additions & 2 deletions crates/containerd-shim-wasmedge/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
#[cfg_attr(unix, path = "instance_linux.rs")]
#[cfg_attr(windows, path = "instance_windows.rs")]
pub mod instance;

pub use instance::WasmEdgeInstance;
Expand Down
5 changes: 1 addition & 4 deletions crates/containerd-shim-wasmer/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ edition.workspace = true
[dependencies]
anyhow = { workspace = true }
containerd-shim = { workspace = true }
containerd-shim-wasm = { workspace = true, features = ["libcontainer_default"] }
containerd-shim-wasm = { workspace = true }
log = { workspace = true }
oci-spec = { workspace = true, features = ["runtime"] }
ttrpc = { workspace = true }
Expand All @@ -16,9 +16,6 @@ wasmer = { version = "4.1.2" }
wasmer-compiler = { version = "4.1.2", features = ["compiler"] }
wasmer-wasix = { version = "0.12.0" }

[target.'cfg(unix)'.dependencies]
libcontainer = { workspace = true }

[dev-dependencies]
containerd-shim-wasm-test = { workspace = true }
serial_test = "*"
Expand Down
28 changes: 0 additions & 28 deletions crates/containerd-shim-wasmer/src/instance_windows.rs

This file was deleted.

2 changes: 0 additions & 2 deletions crates/containerd-shim-wasmer/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
#[cfg_attr(unix, path = "instance_linux.rs")]
#[cfg_attr(windows, path = "instance_windows.rs")]
pub mod instance;

pub use instance::WasmerInstance;
Expand Down
5 changes: 1 addition & 4 deletions crates/containerd-shim-wasmtime/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ edition.workspace = true
[dependencies]
anyhow = { workspace = true }
containerd-shim = { workspace = true }
containerd-shim-wasm = { workspace = true, features = ["libcontainer_default"] }
containerd-shim-wasm = { workspace = true }
log = { workspace = true }
oci-spec = { workspace = true, features = ["runtime"] }
ttrpc = { workspace = true }
Expand All @@ -28,9 +28,6 @@ wasmtime = { version = "11.0", default-features = false, features = [
wasmtime-wasi = { version = "11.0", features = ["exit"] }
wasi-common = "11.0"

[target.'cfg(unix)'.dependencies]
libcontainer = { workspace = true }

[dev-dependencies]
containerd-shim-wasm-test = { workspace = true }
serial_test = "*"
Expand Down
28 changes: 0 additions & 28 deletions crates/containerd-shim-wasmtime/src/instance_windows.rs

This file was deleted.

2 changes: 0 additions & 2 deletions crates/containerd-shim-wasmtime/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
#[cfg_attr(unix, path = "instance_linux.rs")]
#[cfg_attr(windows, path = "instance_windows.rs")]
pub mod instance;

pub use instance::WasmtimeInstance;
Expand Down

0 comments on commit c2c6d14

Please sign in to comment.