Skip to content

Commit

Permalink
Add option to ignore containers to pull
Browse files Browse the repository at this point in the history
  • Loading branch information
JakobFels committed Nov 24, 2023
1 parent c6d0539 commit e042d9b
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 2 deletions.
2 changes: 2 additions & 0 deletions config.example.toml
Original file line number Diff line number Diff line change
Expand Up @@ -223,3 +223,5 @@
# use_root = false

# containers = ["archlinux-latest"]
[containers]
# ignored_containers = ["ghcr.io/rancher-sandbox/rancher-desktop/rdx-proxy:latest"]
18 changes: 18 additions & 0 deletions src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -159,6 +159,13 @@ pub struct Include {
paths: Option<Vec<String>>,
}

#[derive(Deserialize, Default, Debug, Merge)]
#[serde(deny_unknown_fields)]
pub struct Containers {
#[merge(strategy = crate::utils::merge_strategies::vec_prepend_opt)]
ignored_containers: Option<Vec<String>>,
}

#[derive(Deserialize, Default, Debug, Merge)]
#[serde(deny_unknown_fields)]
pub struct Git {
Expand Down Expand Up @@ -411,6 +418,9 @@ pub struct ConfigFile {
#[merge(strategy = crate::utils::merge_strategies::inner_merge_opt)]
git: Option<Git>,

#[merge(strategy = crate::utils::merge_strategies::inner_merge_opt)]
containers: Option<Containers>,

#[merge(strategy = crate::utils::merge_strategies::inner_merge_opt)]
windows: Option<Windows>,

Expand Down Expand Up @@ -842,6 +852,14 @@ impl Config {
self.config_file.git.as_ref().and_then(|git| git.repos.as_ref())
}

/// The list of docker/podman containers to ignore.
pub fn containers_ignored_tags(&self) -> Option<&Vec<String>> {
self.config_file
.containers
.as_ref()
.and_then(|containers| containers.ignored_containers.as_ref())
}

/// Tell whether the specified step should run.
///
/// If the step appears either in the `--disable` command line argument
Expand Down
17 changes: 15 additions & 2 deletions src/steps/containers.rs
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,9 @@ impl Display for Container {

/// Returns a Vector of all containers, with Strings in the format
/// "REGISTRY/[PATH/]CONTAINER_NAME:TAG"
fn list_containers(crt: &Path) -> Result<Vec<Container>> {
///
/// Containers specified in `ignored_containers` will be filtered out.
fn list_containers(crt: &Path, ignored_containers: Option<&Vec<String>>) -> Result<Vec<Container>> {
debug!(
"Querying '{} image ls --format \"{{{{.Repository}}}}:{{{{.Tag}}}}/{{{{.ID}}}}\"' for containers",
crt.display()
Expand Down Expand Up @@ -83,6 +85,16 @@ fn list_containers(crt: &Path) -> Result<Vec<Container>> {
assert_eq!(split_res.len(), 2);
let (repo_tag, image_id) = (split_res[0], split_res[1]);

if let Some(ignored_containers) = ignored_containers {
if ignored_containers
.iter()
.any(|ignored_container| repo_tag.eq(ignored_container))
{
debug!("Skipping ignored container '{}'", line);
continue;
}
}

debug!(
"Querying '{} image inspect --format \"{{{{.Os}}}}/{{{{.Architecture}}}}\"' for container {}",
crt.display(),
Expand All @@ -109,7 +121,8 @@ pub fn run_containers(ctx: &ExecutionContext) -> Result<()> {

print_separator("Containers");
let mut success = true;
let containers = list_containers(&crt).context("Failed to list Docker containers")?;
let containers =
list_containers(&crt, ctx.config().containers_ignored_tags()).context("Failed to list Docker containers")?;
debug!("Containers to inspect: {:?}", containers);

for container in containers.iter() {
Expand Down

0 comments on commit e042d9b

Please sign in to comment.