diff --git a/Cargo.lock b/Cargo.lock index c3eb43d..6866ebc 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -67,6 +67,15 @@ dependencies = [ "syn", ] +[[package]] +name = "container" +version = "0.1.0" +dependencies = [ + "lazy_static", + "oci-spec", + "unshare", +] + [[package]] name = "darling" version = "0.12.4" @@ -303,9 +312,7 @@ name = "run0" version = "0.1.0" dependencies = [ "clap", - "lazy_static", - "oci-spec", - "unshare", + "container", ] [[package]] diff --git a/Cargo.toml b/Cargo.toml index d11e5ae..edf69e5 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -6,6 +6,9 @@ authors = ["Polytech Montpellier - DevOps"] [dependencies] clap = { version = "3.0.5", features = ["derive"] } -lazy_static = "1.4.0" -oci-spec = "0.5.3" -unshare = { git = "https://github.com/virt-do/unshare", branch = "main" } +container = { path = "container" } + +[workspace] +members = [ + "container" +] \ No newline at end of file diff --git a/container/Cargo.toml b/container/Cargo.toml new file mode 100644 index 0000000..1d33220 --- /dev/null +++ b/container/Cargo.toml @@ -0,0 +1,10 @@ +[package] +name = "container" +version = "0.1.0" +edition = "2021" +authors = ["Polytech Montpellier - DevOps"] + +[dependencies] +lazy_static = "1.4.0" +oci-spec = "0.5.3" +unshare = { git = "https://github.com/virt-do/unshare", branch = "main" } \ No newline at end of file diff --git a/src/container/command.rs b/container/src/command.rs similarity index 100% rename from src/container/command.rs rename to container/src/command.rs diff --git a/src/container/environment.rs b/container/src/environment.rs similarity index 100% rename from src/container/environment.rs rename to container/src/environment.rs diff --git a/src/container/mod.rs b/container/src/lib.rs similarity index 98% rename from src/container/mod.rs rename to container/src/lib.rs index c33f846..4e04e01 100644 --- a/src/container/mod.rs +++ b/container/src/lib.rs @@ -2,8 +2,8 @@ use std::path::PathBuf; use oci_spec::runtime::Spec; -use crate::container::environment::Environment; use command::Command; +use environment::Environment; use mounts::Mounts; use namespaces::Namespaces; diff --git a/src/container/mounts.rs b/container/src/mounts.rs similarity index 91% rename from src/container/mounts.rs rename to container/src/mounts.rs index 54ed97d..1c6d034 100644 --- a/src/container/mounts.rs +++ b/container/src/mounts.rs @@ -1,4 +1,4 @@ -use crate::container::Error; +use crate::Error; use std::path::PathBuf; use std::process::Command; @@ -36,7 +36,7 @@ impl Mounts { /// Cleanup the mounts of a rootfs. /// This method should be called when a container has ended, to clean up the FS. - pub fn cleanup(&self, rootfs: PathBuf) -> Result<(), crate::container::Error> { + pub fn cleanup(&self, rootfs: PathBuf) -> Result<(), crate::Error> { for mount in &self.vec { let mut path = rootfs.clone(); path.push(&mount.source); @@ -48,9 +48,9 @@ impl Mounts { .code() { if code != 0 { - return Err(crate::container::Error::Unmount( - std::io::Error::from_raw_os_error(code), - )); + return Err(crate::Error::Unmount(std::io::Error::from_raw_os_error( + code, + ))); } } } diff --git a/src/container/namespaces.rs b/container/src/namespaces.rs similarity index 96% rename from src/container/namespaces.rs rename to container/src/namespaces.rs index 6d8539b..84f91e0 100644 --- a/src/container/namespaces.rs +++ b/container/src/namespaces.rs @@ -1,4 +1,4 @@ -use crate::container::Error; +use crate::Error; use oci_spec::runtime::{LinuxNamespace, LinuxNamespaceType}; use unshare::Namespace; @@ -16,7 +16,7 @@ impl Namespaces { /// Convert an `oci_spec::runtime::LinuxNamespaceType` to an `unshare::Namespace` /// It returns an error if the namespace is invalid, or if it does not match any pattern. #[allow(unreachable_patterns)] - fn from_oci_namespace(namespace: LinuxNamespaceType) -> crate::container::Result { + fn from_oci_namespace(namespace: LinuxNamespaceType) -> crate::Result { match namespace { LinuxNamespaceType::Cgroup => Ok(Namespace::Cgroup), LinuxNamespaceType::Ipc => Ok(Namespace::Ipc), diff --git a/src/cli/mod.rs b/src/cli/mod.rs index 087c3c7..8179f32 100644 --- a/src/cli/mod.rs +++ b/src/cli/mod.rs @@ -6,11 +6,11 @@ use clap::{Parser, Subcommand}; /// CLI related errors #[derive(Debug)] pub enum Error { - Run(crate::container::Error), + Run(container::Error), } -impl From for Error { - fn from(error: crate::container::Error) -> Self { +impl From for Error { + fn from(error: container::Error) -> Self { Self::Run(error) } } diff --git a/src/cli/run.rs b/src/cli/run.rs index 8dcd719..80204c3 100644 --- a/src/cli/run.rs +++ b/src/cli/run.rs @@ -1,6 +1,6 @@ -use crate::container::Container; use crate::{Handler, Result}; use clap::Args; +use container::Container; /// Arguments for our `RunCommand`. /// diff --git a/src/main.rs b/src/main.rs index eb151d7..ac9c96a 100644 --- a/src/main.rs +++ b/src/main.rs @@ -3,7 +3,6 @@ use clap::Parser; use crate::cli::{Cli, Handler, Result}; mod cli; -mod container; fn main() -> Result<()> { let cli: Cli = Cli::parse();