Skip to content

Commit

Permalink
Merge pull request #465 from stepchowfun/fix-force-image-pull
Browse files Browse the repository at this point in the history
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
  • Loading branch information
stepchowfun authored Apr 3, 2023
2 parents 52f4419 + 7ee1bdc commit 7eda695
Show file tree
Hide file tree
Showing 6 changed files with 23 additions and 15 deletions.
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "toast"
version = "0.47.0"
version = "0.47.1"
authors = ["Stephan Boyer <stephan@stephanboyer.com>"]
edition = "2021"
description = "Containerize your development and continuous integration environments."
Expand Down
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -413,8 +413,8 @@ OPTIONS:
--force <TASK>...
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
Expand Down
20 changes: 11 additions & 9 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -166,7 +166,7 @@ pub struct Settings {
spawn_shell: bool,
tasks: Option<Vec<String>>,
forced_tasks: Vec<String>,
force_image_pull: bool,
force_all: bool,
output_dir: PathBuf,
}

Expand Down Expand Up @@ -259,9 +259,9 @@ fn settings() -> Result<Settings, Failure> {
.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)
Expand Down Expand Up @@ -393,8 +393,8 @@ fn settings() -> Result<Settings, Failure> {
.collect::<Vec<_>>()
});

// 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,
Expand All @@ -408,7 +408,7 @@ fn settings() -> Result<Settings, Failure> {
spawn_shell,
tasks,
forced_tasks,
force_image_pull,
force_all,
output_dir,
})
}
Expand Down Expand Up @@ -548,8 +548,9 @@ fn run_tasks(
) -> (Result<(), Failure>, Option<runner::Context>, Option<String>) {
// 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 {
Expand Down Expand Up @@ -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]
);
Expand Down
5 changes: 3 additions & 2 deletions src/runner.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<Context>) {
Expand Down Expand Up @@ -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)),
Expand Down

0 comments on commit 7eda695

Please sign in to comment.