-
Notifications
You must be signed in to change notification settings - Fork 7
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Fix shared layer logic #364
Merged
Merged
Conversation
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
There was a bug reported where deploying a Ruby application after modifying the Gemfile.lock would result in an error because we were skipping running `bundle install`. Debugging this lead me to find that we were returning the incorrect value from our shared cache logic (accidentally returning the currnt/now value rather than the old value). The idea behind `cached_layer_write_metadata` is to either return the old cached data or return a message stating why it couldn't be returned. It was accidentally returning the new/current value instead. I added a unit test to assert this behavior. While developing I used an integration test to debug the issue (given below). This commit fixes the integration test given below: ## Gemfile.lock cache invalidation integration reproduction ``` $ cargo test test_gemfile_lock_invalidates_cache -- --exact ``` ``` #[test] fn test_gemfile_lock_invalidates_cache() { let app_dir = tempfile::tempdir().unwrap(); fs_err::write( app_dir.path().join("Gemfile"), r#" source "https://rubygems.org" gem "rake" "#, ) .unwrap(); fs_err::write( app_dir.path().join("Gemfile.lock"), r" GEM remote: https://rubygems.org/ specs: rake (13.2.0) PLATFORMS ruby DEPENDENCIES rake ", ) .unwrap(); let mut config = amd_arm_builder_config("heroku/builder:24", &app_dir.path().to_string_lossy()); TestRunner::default().build( config.clone() .buildpacks([ BuildpackReference::CurrentCrate, ]), |context| { let stdout = context.pack_stdout.clone(); println!("{}", stdout); assert_contains!(stdout, "# Heroku Ruby Buildpack"); assert_contains!( stdout, r#"`BUNDLE_BIN="/layers/heroku_ruby/gems/bin" BUNDLE_CLEAN="1" BUNDLE_DEPLOYMENT="1" BUNDLE_GEMFILE="/workspace/Gemfile" BUNDLE_PATH="/layers/heroku_ruby/gems" BUNDLE_WITHOUT="development:test" bundle install`"# ); assert_contains!(stdout, "Installing rake"); fs_err::write( app_dir.path().join("Gemfile.lock"), r" GEM remote: https://rubygems.org/ specs: rake (13.2.1) PLATFORMS ruby DEPENDENCIES rake ", ) .unwrap(); context.rebuild( config.buildpacks([BuildpackReference::CurrentCrate]), |rebuild_context| { println!("{}", rebuild_context.pack_stdout); assert_contains!( rebuild_context.pack_stdout, r#"`BUNDLE_BIN="/layers/heroku_ruby/gems/bin" BUNDLE_CLEAN="1" BUNDLE_DEPLOYMENT="1" BUNDLE_GEMFILE="/workspace/Gemfile" BUNDLE_PATH="/layers/heroku_ruby/gems" BUNDLE_WITHOUT="development:test" bundle install`"# ); assert_contains!(rebuild_context.pack_stdout, "Installing rake"); }, ); }); } ```
schneems
force-pushed
the
schneems/gemfile-lock-digest-fix
branch
from
December 11, 2024 18:16
5e122ab
to
e37006b
Compare
schneems
changed the base branch from
main
to
schneems/cargo-fmt-clippy-dec-11
December 11, 2024 19:19
schneems
force-pushed
the
schneems/gemfile-lock-digest-fix
branch
from
December 11, 2024 19:22
e37006b
to
6c9c53a
Compare
schneems
force-pushed
the
schneems/gemfile-lock-digest-fix
branch
from
December 11, 2024 19:46
6c9c53a
to
e37006b
Compare
edmorley
approved these changes
Dec 11, 2024
Merged
heroku-linguist bot
added a commit
to heroku/cnb-builder-images
that referenced
this pull request
Dec 11, 2024
## heroku/ruby ### Fixed - A bug introduced in 4.0.0 would result in incorrectly skipping running `bundle install` when the `Gemfile` or `Gemfile.lock` or environment variables had changed. The bug is now fixed. ([#364](heroku/buildpacks-ruby#364))
heroku-linguist bot
added a commit
to heroku/cnb-builder-images
that referenced
this pull request
Dec 11, 2024
## heroku/ruby ### Fixed - A bug introduced in 4.0.0 would result in incorrectly skipping running `bundle install` when the `Gemfile` or `Gemfile.lock` or environment variables had changed. The bug is now fixed. ([#364](heroku/buildpacks-ruby#364)) Co-authored-by: heroku-linguist[bot] <136119646+heroku-linguist[bot]@users.noreply.github.com>
schneems
pushed a commit
to BrianBorge/buildpacks-ruby
that referenced
this pull request
Dec 13, 2024
## heroku/ruby ### Fixed - A bug introduced in 4.0.0 would result in incorrectly skipping running `bundle install` when the `Gemfile` or `Gemfile.lock` or environment variables had changed. The bug is now fixed. ([heroku#364](heroku#364)) Co-authored-by: heroku-linguist[bot] <136119646+heroku-linguist[bot]@users.noreply.github.com>
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a bug reported where deploying a Ruby application after modifying the Gemfile.lock would result in an error because we were skipping running
bundle install
. Debugging this lead me to find that we were returning the incorrect value from our shared cache logic (accidentally returning the currnt/now value rather than the old value).The idea behind
cached_layer_write_metadata
is to either return the old cached data or return a message stating why it couldn't be returned. It was accidentally returning the new/current value instead. This feature is used in most (nearly all) of the layers, likebuildpacks-ruby/buildpacks/ruby/src/layers/bundle_install_layer.rs
Lines 56 to 62 in a3f5834
buildpacks-ruby/buildpacks/ruby/src/layers/bundle_install_layer.rs
Lines 129 to 136 in a3f5834
I added a unit test to assert this behavior. While developing I used an integration test to debug the issue (given below).
This commit fixes the integration test given below:
Gemfile.lock cache invalidation integration reproduction