Containers step: new runtime option to configuration (#896)

* 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 <lucaspar@users.noreply.github.com>
This commit is contained in:
Lucas Parzianello
2024-09-01 03:35:23 -04:00
committed by GitHub
parent ca8558d9b4
commit 1958fe1e5b
4 changed files with 36 additions and 3 deletions

View File

@@ -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".

View File

@@ -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 `lensfunupdatedata` without root priviledge,

View File

@@ -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;
@@ -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)]
@@ -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 {
@@ -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

View File

@@ -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");