diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 52c74a46..75d4925b 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -60,12 +60,6 @@ jobs: uses: Swatinem/rust-cache@v1.3.0 - name: Install Pack CLI uses: buildpacks/github-actions/setup-pack@v4.6.0 - - name: Configure Pack CLI - # Default to a small non-libc image for faster CI + to validate the static musl cross-compilation. - # Adjust pull-policy to prevent redundant image-pulling, which slows CI and risks hitting registry rate limits. - run: | - pack config default-builder cnbs/sample-builder:alpine - pack config pull-policy if-not-present - name: Run integration tests # Runs any tests annotated with the `#[ignore]` attribute (which in this repo, are all of the integration tests). run: cargo test -- --ignored @@ -73,4 +67,5 @@ jobs: run: cargo run --package libcnb-cargo -- libcnb package working-directory: ./examples/basics - name: Pack build using examples/basics - run: pack build example-basics --buildpack target/buildpack/debug/libcnb-examples_basics --path examples/ + # Uses a non-libc image to validate the static musl cross-compilation. + run: pack build example-basics --builder cnbs/sample-builder:alpine --buildpack target/buildpack/debug/libcnb-examples_basics --path examples/ diff --git a/libcnb-test/CHANGELOG.md b/libcnb-test/CHANGELOG.md index e0647b2a..e1ecd3b5 100644 --- a/libcnb-test/CHANGELOG.md +++ b/libcnb-test/CHANGELOG.md @@ -6,6 +6,7 @@ - Replaced `IntegrationTestContext::start_container` with `IntegrationTestContext::prepare_container`, allowing users to configure the container before starting it. Ports can now be exposed via `PrepareContainerContext::expose_port`. ([#346](https://github.com/Malax/libcnb.rs/pull/346)) - Added the ability to set environment variables for the container via `PrepareContainerContext::env` and `PrepareContainerContext::envs`. ([#346](https://github.com/Malax/libcnb.rs/pull/346)) - Switch from `libcnb-cargo` to the new `libcnb-package` crate for buildpack packaging, which improves compile times due to it not including CLI-related dependencies ([#362](https://github.com/Malax/libcnb.rs/pull/362)). +- Use `--pull-policy if-not-present` when running `pack build` ([#373](https://github.com/Malax/libcnb.rs/pull/373)). ## [0.2.0] 2022-02-28 diff --git a/libcnb-test/src/lib.rs b/libcnb-test/src/lib.rs index 93849c82..3e6e2bfe 100644 --- a/libcnb-test/src/lib.rs +++ b/libcnb-test/src/lib.rs @@ -17,7 +17,7 @@ mod util; pub use crate::container_context::{ ContainerContext, ContainerExecResult, PrepareContainerContext, }; -use crate::pack::PackBuildCommand; +use crate::pack::{PackBuildCommand, PullPolicy}; use bollard::image::RemoveImageOptions; use bollard::Docker; use std::collections::HashMap; @@ -233,8 +233,13 @@ impl IntegrationTest { let image_name = util::random_docker_identifier(); - let mut pack_command = - PackBuildCommand::new(&self.builder_name, temp_app_dir.path(), &image_name); + let mut pack_command = PackBuildCommand::new( + &self.builder_name, + temp_app_dir.path(), + &image_name, + // Prevent redundant image-pulling, which slows tests and risks hitting registry rate limits. + PullPolicy::IfNotPresent, + ); self.env.iter().for_each(|(key, value)| { pack_command.env(key, value); diff --git a/libcnb-test/src/pack.rs b/libcnb-test/src/pack.rs index 9813dfc0..590d1183 100644 --- a/libcnb-test/src/pack.rs +++ b/libcnb-test/src/pack.rs @@ -7,10 +7,11 @@ use tempfile::TempDir; #[derive(Clone, Debug)] pub(crate) struct PackBuildCommand { builder: String, - path: PathBuf, - image_name: String, buildpacks: Vec, env: BTreeMap, + image_name: String, + path: PathBuf, + pull_policy: PullPolicy, verbose: bool, } @@ -38,18 +39,32 @@ impl From for BuildpackReference { } } +#[derive(Clone, Debug)] +/// Controls whether Pack should pull images. +#[allow(dead_code)] +pub(crate) enum PullPolicy { + /// Always pull images. + Always, + /// Use local images if they are already present, rather than pulling updated images. + IfNotPresent, + /// Never pull images. If the required images are not already available locally the pack command will fail. + Never, +} + impl PackBuildCommand { pub fn new( builder: impl Into, path: impl Into, image_name: impl Into, + pull_policy: PullPolicy, ) -> PackBuildCommand { PackBuildCommand { builder: builder.into(), - path: path.into(), - image_name: image_name.into(), - buildpacks: vec![], + buildpacks: Vec::new(), env: BTreeMap::new(), + image_name: image_name.into(), + path: path.into(), + pull_policy, verbose: false, } } @@ -76,6 +91,12 @@ impl From for Command { pack_build_command.builder, String::from("--path"), pack_build_command.path.to_string_lossy().to_string(), + String::from("--pull-policy"), + match pack_build_command.pull_policy { + PullPolicy::Always => "always".to_string(), + PullPolicy::IfNotPresent => "if-not-present".to_string(), + PullPolicy::Never => "never".to_string(), + }, ]; for buildpack in pack_build_command.buildpacks { @@ -115,8 +136,6 @@ mod tests { fn from_pack_build_command_to_command() { let mut input = PackBuildCommand { builder: String::from("builder:20"), - path: PathBuf::from("/tmp/foo/bar"), - image_name: String::from("my-image"), buildpacks: vec![ BuildpackReference::Id(String::from("libcnb/buildpack1")), BuildpackReference::Path(PathBuf::from("/tmp/buildpack2")), @@ -125,6 +144,9 @@ mod tests { (String::from("ENV_FOO"), String::from("FOO_VALUE")), (String::from("ENV_BAR"), String::from("WHITESPACE VALUE")), ]), + image_name: String::from("my-image"), + path: PathBuf::from("/tmp/foo/bar"), + pull_policy: PullPolicy::IfNotPresent, verbose: true, }; @@ -141,6 +163,8 @@ mod tests { "builder:20", "--path", "/tmp/foo/bar", + "--pull-policy", + "if-not-present", "--buildpack", "libcnb/buildpack1", "--buildpack",