Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add podman support #57

Merged
merged 1 commit into from
Jan 31, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading