Skip to content

Commit

Permalink
feat: add podman support
Browse files Browse the repository at this point in the history
  • Loading branch information
MrHedmad committed Jan 31, 2024
1 parent 38e5a33 commit f44b7ab
Show file tree
Hide file tree
Showing 3 changed files with 39 additions and 6 deletions.
5 changes: 3 additions & 2 deletions src/commands/package.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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",
Expand Down
9 changes: 5 additions & 4 deletions src/commands/run.rs
Original file line number Diff line number Diff line change
Expand Up @@ -129,8 +129,9 @@ impl Executor {
let mut cleanup: Vec<PathBuf> = vec![];

let command_args = if self.env.is_some() {
let runtime_name = self.build_env(signal_receiver.clone())?;
let mut partial: Vec<String> = 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<String> = 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 {
Expand Down Expand Up @@ -185,7 +186,7 @@ impl Executor {
}

/// Build the context of this executor and return its tag.
pub fn build_env(&self, signal_receiver: Receiver<bool>) -> Result<String> {
pub fn build_env(&self, signal_receiver: Receiver<bool>, backend: &str) -> Result<String> {
let mut cleanup: Vec<PathBuf> = vec![];

if self.env.is_none() {
Expand All @@ -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",
Expand Down
31 changes: 31 additions & 0 deletions src/options.rs
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,37 @@ pub struct KerblamTomlOptions {
pub meta: Option<Meta>,
pub data: Option<DataOptions>,
pub code: Option<CodeOptions>,
#[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<String> 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<Path>) -> Result<KerblamTomlOptions> {
Expand Down

0 comments on commit f44b7ab

Please sign in to comment.