From 7ee1bdc26e87ca6a702a3a10e068a4ad9e74448d Mon Sep 17 00:00:00 2001 From: Stephan Boyer Date: Mon, 3 Apr 2023 16:30:04 -0700 Subject: [PATCH] Fix a bug in `--force-image-pull` which would cause the flag to have no effect if the first task in the schedule is available in the local or remote cache Also, the flag has been renamed to `--force-all`. --- CHANGELOG.md | 5 +++++ Cargo.lock | 2 +- Cargo.toml | 2 +- README.md | 4 ++-- src/main.rs | 20 +++++++++++--------- src/runner.rs | 5 +++-- 6 files changed, 23 insertions(+), 15 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 6cf4f45..6cd74d2 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -5,6 +5,11 @@ All notable changes to this project will be documented in this file. The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/), and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html). +## [0.47.1] - 2023-04-03 + +### Added +- Fixed a bug in `--force-image-pull` which would cause the flag to have no effect if the first task in the schedule is available in the local or remote cache. Also, the flag has been renamed to `--force-all`. + ## [0.47.0] - 2023-04-03 ### Added diff --git a/Cargo.lock b/Cargo.lock index 47847ef..3906ce5 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -630,7 +630,7 @@ dependencies = [ [[package]] name = "toast" -version = "0.47.0" +version = "0.47.1" dependencies = [ "atty", "clap", diff --git a/Cargo.toml b/Cargo.toml index 1db47e3..5f7bd6e 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "toast" -version = "0.47.0" +version = "0.47.1" authors = ["Stephan Boyer "] edition = "2021" description = "Containerize your development and continuous integration environments." diff --git a/README.md b/README.md index 721bd0d..d0e0cc5 100644 --- a/README.md +++ b/README.md @@ -413,8 +413,8 @@ OPTIONS: --force ... Runs a task unconditionally, even if it’s cached - --force-image-pull - Pulls the base image unconditionally, even if it already exists locally + --force-all + Pulls the base image and runs all tasks unconditionally -h, --help Prints help information diff --git a/src/main.rs b/src/main.rs index 274978b..f8397ef 100644 --- a/src/main.rs +++ b/src/main.rs @@ -69,7 +69,7 @@ const LIST_OPTION: &str = "list"; const SHELL_OPTION: &str = "shell"; const TASKS_OPTION: &str = "tasks"; const FORCE_OPTION: &str = "force"; -const FORCE_IMAGE_PULL: &str = "force-image-pull"; +const FORCE_ALL_OPTION: &str = "force-all"; const OUTPUT_DIR_OPTION: &str = "output-dir"; // Set up the logger. @@ -166,7 +166,7 @@ pub struct Settings { spawn_shell: bool, tasks: Option>, forced_tasks: Vec, - force_image_pull: bool, + force_all: bool, output_dir: PathBuf, } @@ -259,9 +259,9 @@ fn settings() -> Result { .multiple(true), ) .arg( - Arg::with_name(FORCE_IMAGE_PULL) - .long(FORCE_IMAGE_PULL) - .help("Pulls the base image unconditionally, even if it already exists locally"), + Arg::with_name(FORCE_ALL_OPTION) + .long(FORCE_ALL_OPTION) + .help("Pulls the base image and runs all tasks unconditionally"), ) .arg( Arg::with_name(TASKS_OPTION) @@ -393,8 +393,8 @@ fn settings() -> Result { .collect::>() }); - // Read the force image pulling switch. - let force_image_pull = matches.is_present(FORCE_IMAGE_PULL); + // Read the force all switch. + let force_all = matches.is_present(FORCE_ALL_OPTION); Ok(Settings { toastfile_path, @@ -408,7 +408,7 @@ fn settings() -> Result { spawn_shell, tasks, forced_tasks, - force_image_pull, + force_all, output_dir, }) } @@ -548,8 +548,9 @@ fn run_tasks( ) -> (Result<(), Failure>, Option, Option) { // This variable will be `true` as long as we're executing tasks that have `cache: true`. As // soon as we encounter a task with `cache: false`, this variable will be permanently set to + // `false`. If the user provided the `--force-image-pull` flag, this variable will always be // `false`. - let mut caching_enabled = true; + let mut caching_enabled = !settings.force_all; // We start with the base image. let mut context = Some(runner::Context { @@ -592,6 +593,7 @@ fn run_tasks( toastfile, task_data, caching_enabled, + settings.force_all && i == 0, context.unwrap(), // Safe due to [ref:context_needed_if_not_final_task]. need_context || i != schedule.len() - 1, // [tag:context_needed_if_not_final_task] ); diff --git a/src/runner.rs b/src/runner.rs index 02e6cbf..7e467f8 100644 --- a/src/runner.rs +++ b/src/runner.rs @@ -50,6 +50,7 @@ pub fn run( toastfile: &Toastfile, task: &Task, caching_enabled: bool, + force_pull: bool, context: Context, need_context: bool, ) -> (Result<(), Failure>, Option) { @@ -206,8 +207,8 @@ pub fn run( }), ) } else { - // Pull the image if necessary. Force reading from the remote if configured - if settings.force_image_pull + // Pull the image if necessary. Force reading from the remote if configured. + if force_pull || !match docker::image_exists(&settings.docker_cli, &context.image, interrupted) { Ok(exists) => exists, Err(e) => return (Err(e), Some(context)),