Skip to content

Commit

Permalink
update to the newest main branch from runwasi (#131)
Browse files Browse the repository at this point in the history
  • Loading branch information
Mossaka authored Aug 23, 2023
1 parent f66a8f3 commit 95e8047
Show file tree
Hide file tree
Showing 12 changed files with 51 additions and 236 deletions.
21 changes: 1 addition & 20 deletions containerd-shim-lunatic-v1/Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion containerd-shim-lunatic-v1/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ edition = "2021"

[dependencies]
containerd-shim = "0.4.0"
containerd-shim-wasm = { git = "https://github.com/containerd/runwasi", rev = "6287dff637b0ac96a43a6bbe2c7919f8b2f2cf27", features = ["cgroupsv2"] }
containerd-shim-wasm = { git = "https://github.com/containerd/runwasi", rev = "7850da82a86286f6fcf21e1c93390572ed73592d", features = ["cgroupsv2"] }
libcontainer = { version = "0.1", features = ["v2"], default-features = false }
nix = "0.26.2"
serde = "1.0.183"
Expand Down
40 changes: 10 additions & 30 deletions containerd-shim-lunatic-v1/src/main.rs
Original file line number Diff line number Diff line change
@@ -1,23 +1,22 @@
use std::{
fs::File,
io::{ErrorKind, Read},
os::fd::IntoRawFd,
path::{Path, PathBuf},
path::PathBuf,
sync::{Arc, Condvar, Mutex},
};

use containerd_shim::run;
use containerd_shim_wasm::{
libcontainer_instance::LibcontainerInstance,
sandbox::{
instance::ExitCode, instance_utils::maybe_open_stdio, Error, InstanceConfig, ShimCli,
instance::ExitCode,
instance_utils::{determine_rootdir, maybe_open_stdio},
Error, InstanceConfig, ShimCli,
},
};
use libcontainer::{
container::{builder::ContainerBuilder, Container},
syscall::syscall::create_syscall,
};
use serde::{Deserialize, Serialize};

use anyhow::{Context, Result};

Expand All @@ -38,30 +37,6 @@ pub struct Wasi {
stderr: String,
}

#[derive(Serialize, Deserialize)]
struct Options {
root: Option<PathBuf>,
}

fn determine_rootdir<P: AsRef<Path>>(bundle: P, namespace: String) -> Result<PathBuf, Error> {
let mut file = match File::open(bundle.as_ref().join("options.json")) {
Ok(f) => f,
Err(err) => match err.kind() {
ErrorKind::NotFound => {
return Ok(<&str as Into<PathBuf>>::into(DEFAULT_CONTAINER_ROOT_DIR).join(namespace))
}
_ => return Err(err.into()),
},
};
let mut data = String::new();
file.read_to_string(&mut data)?;
let options: Options = serde_json::from_str(&data)?;
Ok(options
.root
.unwrap_or(PathBuf::from(DEFAULT_CONTAINER_ROOT_DIR))
.join(namespace))
}

impl LibcontainerInstance for Wasi {
type Engine = ();

Expand All @@ -72,7 +47,12 @@ impl LibcontainerInstance for Wasi {
Wasi {
id,
exit_code: Arc::new((Mutex::new(None), Condvar::new())),
rootdir: determine_rootdir(bundle.as_str(), cfg.get_namespace()).unwrap(),
rootdir: determine_rootdir(
bundle.as_str(),
cfg.get_namespace().as_str(),
DEFAULT_CONTAINER_ROOT_DIR,
)
.unwrap(),
bundle,
stdin: cfg.get_stdin().unwrap_or_default(),
stdout: cfg.get_stdout().unwrap_or_default(),
Expand Down
21 changes: 1 addition & 20 deletions containerd-shim-slight-v1/Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion containerd-shim-slight-v1/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ Containerd shim for running Slight workloads.
chrono = "0.4"
clap = { version = "4.1", features = ["derive", "env"] }
containerd-shim = "0.4.0"
containerd-shim-wasm = { git = "https://github.com/containerd/runwasi", rev = "6287dff637b0ac96a43a6bbe2c7919f8b2f2cf27", features = ["cgroupsv2"]}
containerd-shim-wasm = { git = "https://github.com/containerd/runwasi", rev = "7850da82a86286f6fcf21e1c93390572ed73592d", features = ["cgroupsv2"]}
log = "0.4"
tokio = { version = "1", features = [ "full" ] }
tokio-util = { version = "0.7", features = [ "codec" ]}
Expand Down
47 changes: 8 additions & 39 deletions containerd-shim-slight-v1/src/main.rs
Original file line number Diff line number Diff line change
@@ -1,23 +1,17 @@
use std::fs::File;
use std::io::ErrorKind;
use std::io::Read;
use std::option::Option;
use std::path::Path;
use std::path::PathBuf;

use anyhow::{Context, Result};
use anyhow::Context;
use containerd_shim as shim;
use containerd_shim_wasm::libcontainer_instance::LibcontainerInstance;
use containerd_shim_wasm::libcontainer_instance::LinuxContainerExecutor;
use containerd_shim_wasm::sandbox::instance::ExitCode;
use containerd_shim_wasm::sandbox::instance_utils::maybe_open_stdio;
use containerd_shim_wasm::sandbox::instance_utils::{determine_rootdir, maybe_open_stdio};
use containerd_shim_wasm::sandbox::{error::Error, InstanceConfig, ShimCli};
use executor::SlightExecutor;
use libcontainer::container::builder::ContainerBuilder;
use libcontainer::container::Container;
use libcontainer::syscall::syscall::create_syscall;
use serde::Deserialize;
use serde::Serialize;
use std::os::fd::IntoRawFd;

mod executor;
Expand All @@ -34,43 +28,18 @@ pub struct Wasi {
rootdir: PathBuf,
}

#[derive(Serialize, Deserialize)]
struct Options {
root: Option<PathBuf>,
}

fn determine_rootdir<P: AsRef<Path>>(bundle: P, namespace: String) -> Result<PathBuf, Error> {
log::info!(
"determining rootdir for bundle: {}",
bundle.as_ref().display()
);
let mut file = match File::open(bundle.as_ref().join("options.json")) {
Ok(f) => f,
Err(err) => match err.kind() {
ErrorKind::NotFound => {
return Ok(<&str as Into<PathBuf>>::into(DEFAULT_CONTAINER_ROOT_DIR).join(namespace))
}
_ => return Err(err.into()),
},
};
let mut data = String::new();
file.read_to_string(&mut data)?;
let options: Options = serde_json::from_str(&data)?;
let path = options
.root
.unwrap_or(PathBuf::from(DEFAULT_CONTAINER_ROOT_DIR))
.join(namespace);
log::info!("youki root path is: {}", path.display());
Ok(path)
}

impl LibcontainerInstance for Wasi {
type Engine = ();
fn new_libcontainer(id: String, cfg: Option<&InstanceConfig<Self::Engine>>) -> Self {
log::info!(">>> new instance");
let cfg = cfg.unwrap();
let bundle = cfg.get_bundle().unwrap_or_default();
let rootdir = determine_rootdir(bundle.as_str(), cfg.get_namespace()).unwrap();
let rootdir = determine_rootdir(
bundle.as_str(),
cfg.get_namespace().as_str(),
DEFAULT_CONTAINER_ROOT_DIR,
)
.unwrap();
Wasi {
exit_code: Default::default(),
id,
Expand Down
21 changes: 1 addition & 20 deletions containerd-shim-spin-v1/Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion containerd-shim-spin-v1/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ Containerd shim for running Spin workloads.
chrono = "0.4"
clap = { version = "4.3", features = ["derive", "env"] }
containerd-shim = "0.4.0"
containerd-shim-wasm = { git = "https://github.com/containerd/runwasi", rev = "6287dff637b0ac96a43a6bbe2c7919f8b2f2cf27", features = ["cgroupsv2"]}
containerd-shim-wasm = { git = "https://github.com/containerd/runwasi", rev = "7850da82a86286f6fcf21e1c93390572ed73592d", features = ["cgroupsv2"]}
log = "0.4"
spin-trigger = { git = "https://github.com/fermyon/spin", tag = "v1.4.0" }
spin-app = { git = "https://github.com/fermyon/spin", tag = "v1.4.0" }
Expand Down
Loading

0 comments on commit 95e8047

Please sign in to comment.