Skip to content

Commit

Permalink
Containers step: new runtime option to configuration (#896)
Browse files Browse the repository at this point in the history
* pyenv: fixes #849

* feat: adds `uv` python manager step

* moved new uv step from unix to generic

* containers step: added container runtime option to config

* documented breaking change

---------

Co-authored-by: Lucas Parzianello <[email protected]>
  • Loading branch information
lucaspar and lucaspar authored Sep 1, 2024
1 parent ca8558d commit 1958fe1
Show file tree
Hide file tree
Showing 4 changed files with 36 additions and 3 deletions.
3 changes: 3 additions & 0 deletions BREAKINGCHANGES_dev.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
# Containers step

+ New default behavior: Docker is the runtime selected by default. This can be overridden by setting the `container.runtime` option in the configuration TOML to "podman".
2 changes: 2 additions & 0 deletions config.example.toml
Original file line number Diff line number Diff line change
Expand Up @@ -244,6 +244,8 @@
[containers]
# Specify the containers to ignore while updating (Wildcard supported)
# ignored_containers = ["ghcr.io/rancher-sandbox/rancher-desktop/rdx-proxy:latest", "docker.io*"]
# Specify the runtime to use for containers (default: "docker", allowed values: "docker", "podman")
# runtime = "podman"

[lensfun]
# If disabled, Topgrade invokes `lensfun‑update‑data` without root priviledge,
Expand Down
29 changes: 28 additions & 1 deletion src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ use std::fs::{write, File};
use std::io::Write;
use std::path::{Path, PathBuf};
use std::process::Command;
use std::{env, fs};
use std::{env, fmt, fs};

use clap::{Parser, ValueEnum};
use clap_complete::Shell;
Expand Down Expand Up @@ -181,6 +181,7 @@ pub struct Include {
pub struct Containers {
#[merge(strategy = crate::utils::merge_strategies::vec_prepend_opt)]
ignored_containers: Option<Vec<String>>,
runtime: Option<ContainerRuntime>,
}

#[derive(Deserialize, Default, Debug, Merge)]
Expand Down Expand Up @@ -287,6 +288,22 @@ pub enum ArchPackageManager {
Yay,
}

#[derive(Clone, Copy, Debug, Deserialize)]
#[serde(rename_all = "snake_case")]
pub enum ContainerRuntime {
Docker,
Podman,
}

impl fmt::Display for ContainerRuntime {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
match self {
ContainerRuntime::Docker => write!(f, "docker"),
ContainerRuntime::Podman => write!(f, "podman"),
}
}
}

#[derive(Deserialize, Default, Debug, Merge)]
#[serde(deny_unknown_fields)]
pub struct Linux {
Expand Down Expand Up @@ -885,6 +902,16 @@ impl Config {
.and_then(|containers| containers.ignored_containers.as_ref())
}

/// The preferred runtime for container updates (podman / docker).
pub fn containers_runtime(&self) -> ContainerRuntime {
self.config_file
.containers
.as_ref()
.unwrap()
.runtime
.unwrap_or(ContainerRuntime::Docker) // defaults to a popular choice
}

/// Tell whether the specified step should run.
///
/// If the step appears either in the `--disable` command line argument
Expand Down
5 changes: 3 additions & 2 deletions src/steps/containers.rs
Original file line number Diff line number Diff line change
Expand Up @@ -120,8 +120,9 @@ fn list_containers(crt: &Path, ignored_containers: Option<&Vec<String>>) -> Resu
}

pub fn run_containers(ctx: &ExecutionContext) -> Result<()> {
// Prefer podman, fall back to docker if not present
let crt = require("podman").or_else(|_| require("docker"))?;
// Check what runtime is specified in the config
let container_runtime = ctx.config().containers_runtime().to_string();
let crt = require(container_runtime)?;
debug!("Using container runtime '{}'", crt.display());

print_separator("Containers");
Expand Down

0 comments on commit 1958fe1

Please sign in to comment.