From f44b7ab476c989d23026152451469bca4fa78dd3 Mon Sep 17 00:00:00 2001 From: Luca Visentin Date: Wed, 31 Jan 2024 11:09:50 +0100 Subject: [PATCH] feat: add podman support --- src/commands/package.rs | 5 +++-- src/commands/run.rs | 9 +++++---- src/options.rs | 31 +++++++++++++++++++++++++++++++ 3 files changed, 39 insertions(+), 6 deletions(-) diff --git a/src/commands/package.rs b/src/commands/package.rs index 1e4df37..6d16c1f 100644 --- a/src/commands/package.rs +++ b/src/commands/package.rs @@ -43,7 +43,8 @@ pub fn package_pipe(config: KerblamTomlOptions, pipe: Pipe, package_name: &str) log::debug!("Building initial context..."); let sigint_rec = setup_ctrlc_hook().expect("Failed to setup SIGINT hook!"); - let base_container = executor.build_env(sigint_rec)?; + let backend: String = config.execution.backend.clone().into(); + let base_container = executor.build_env(sigint_rec, &backend)?; log::debug!("Base container name: {base_container:?}"); // We now start from this new docker and add our own layers, copying the @@ -98,7 +99,7 @@ pub fn package_pipe(config: KerblamTomlOptions, pipe: Pipe, package_name: &str) log::debug!("Packaging..."); // Build this new container and tag it... - let res = Command::new("docker") + let res = Command::new(&backend) .args([ "build", "--no-cache", diff --git a/src/commands/run.rs b/src/commands/run.rs index 7d19738..6f572f5 100644 --- a/src/commands/run.rs +++ b/src/commands/run.rs @@ -129,8 +129,9 @@ impl Executor { let mut cleanup: Vec = vec![]; let command_args = if self.env.is_some() { - let runtime_name = self.build_env(signal_receiver.clone())?; - let mut partial: Vec = stringify![vec!["docker", "run", "-it"]]; + let backend: String = config.execution.backend.clone().into(); + let runtime_name = self.build_env(signal_receiver.clone(), &backend)?; + let mut partial: Vec = stringify![vec![&backend, "run", "-it"]]; // We need to bind-mount the same data dirs as specified in the options let mounts = generate_bind_mount_strings(config); for mount in mounts { @@ -185,7 +186,7 @@ impl Executor { } /// Build the context of this executor and return its tag. - pub fn build_env(&self, signal_receiver: Receiver) -> Result { + pub fn build_env(&self, signal_receiver: Receiver, backend: &str) -> Result { let mut cleanup: Vec = vec![]; if self.env.is_none() { @@ -207,7 +208,7 @@ impl Executor { let dockerfile_path = dockerfile_path.as_os_str().to_string_lossy().to_string(); let builder = || { - Command::new("docker") + Command::new(backend) // If the `self.env` path is not UTF-8 I'll eat my hat. .args([ "build", diff --git a/src/options.rs b/src/options.rs index bf2fef7..4a31ace 100644 --- a/src/options.rs +++ b/src/options.rs @@ -62,6 +62,37 @@ pub struct KerblamTomlOptions { pub meta: Option, pub data: Option, pub code: Option, + #[serde(default)] + pub execution: ExecutionOptions, +} + +#[allow(dead_code)] +#[derive(Debug, Deserialize, Clone, Default)] +pub struct ExecutionOptions { + #[serde(default)] + pub backend: ContainerBackend, +} + +#[derive(Deserialize, Debug, Clone)] +#[serde(rename_all = "lowercase")] +pub enum ContainerBackend { + Docker, + Podman, +} + +impl Default for ContainerBackend { + fn default() -> Self { + Self::Docker + } +} + +impl Into for ContainerBackend { + fn into(self) -> String { + match self { + Self::Docker => "docker".into(), + Self::Podman => "podman".into(), + } + } } pub fn parse_kerblam_toml(toml_file: impl AsRef) -> Result {