-
Notifications
You must be signed in to change notification settings - Fork 286
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: overwrite existing buildpacks correctly #1336
Conversation
Thanks so much for tackling this issue! A lot of us are on holiday, so please forgive us if you don't get a review until next week. |
It's okay @aemengo, have a nice holiday. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for the PR, @fatiiates! This definitely looks like it's on the right path. Is there any chance you could add a test for this case?
internal/builder/builder.go
Outdated
@@ -417,6 +417,37 @@ func addBuildpacks(logger logging.Logger, tmpDir string, image imgutil.Image, ad | |||
if existingBPInfo.LayerDiffID == diffID.String() { | |||
logger.Debugf("Buildpack %s already exists on builder with same contents, skipping...", style.Symbol(bpInfo.FullName())) | |||
continue | |||
} else { | |||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit: remove extra line
internal/builder/builder.go
Outdated
deletedMaps := map[string][]byte{ | ||
filepath.Join( | ||
cnbDir, | ||
"buildpacks", |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can you make that a file var
, similar to cnbDir
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I will deal with them ASAP.
internal/builder/builder.go
Outdated
style.Symbol(bpInfo.FullName()), | ||
) | ||
} | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit: Can you remove this line?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I changed that line, but I doubt I got it right :)
Hey @fatiiates - for tests, we would be looking for a unit test that tests this functionality. I would look for inspiration at these current tests on that part of the code, which test the contents of the layers saved: pack/internal/builder/builder_test.go Lines 639 to 752 in 4f04f34
Specifically, we should change it by adding a test which tries to add two buildpacks which have the same ID and version, but have different contents, and then verify that the contents of the 2nd buildpack, and not the 1st buildpack, are there. Does that make sense? |
Hey @dfreilich, thanks for the explanation. Everything is clearer now. And yes what you said makes perfect sense, that's how I'll do it. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Bumps [github.com/google/go-containerregistry](https://github.com/google/go-containerregistry) from 0.6.0 to 0.7.0. - [Release notes](https://github.com/google/go-containerregistry/releases) - [Changelog](https://github.com/google/go-containerregistry/blob/main/.goreleaser.yml) - [Commits](google/go-containerregistry@v0.6.0...v0.7.0) --- updated-dependencies: - dependency-name: github.com/google/go-containerregistry dependency-type: direct:production update-type: version-update:semver-minor ... Signed-off-by: dependabot[bot] <support@github.com> Signed-off-by: fatih <fatiiates@gmail.com>
…the builder correctly Signed-off-by: fatih <fatiiates@gmail.com>
Signed-off-by: fatih <fatiiates@gmail.com>
c554ee8
to
1ebf75f
Compare
Signed-off-by: fatih <fatiiates@gmail.com>
Signed-off-by: fatih <fatiiates@gmail.com>
Signed-off-by: fatih <fatiiates@gmail.com>
Signed-off-by: fatih <fatiiates@gmail.com>
Merged in by #1362. Thank you for the help, @fatiiates ! Sorry for the hold-up with it, we had to figure out how to deal with some cases of a Windows image, which took me a bit of time. |
It's okay, I saw the other PR you opened but I couldn't help because I have final exams. Good news that the bug has been fixed! Congrats to both of us! |
Summary
According to the issue, the --buildpack flag was not correctly overwriting the buildpack. So I created a whiteout layer to fix this. When it is understood that the buildpacks have the same ID and version, a tarball is created with that directory whiteout and added between these layers. Since it is added as a child layer from the newly added buildpack, only those in the same directory in the lower layer will appear as whiteout.
Output
Following the steps below, the files in the
ls
output should be completely new buildpack files passed as parameters in the --buildpack flag.git clone https://github.com/buildpacks/samples && cd samples
touch buildpacks/java-maven/buildpack-in-builder
pack builder create testcase --config builders/alpine/builder.toml
rm buildpacks/java-maven/buildpack-in-builder && touch buildpacks/java-maven/buildpack-local
echo -e '#!/usr/bin/env bash\nls -al "${CNB_BUILDPACK_DIR}"\nexit 1' > buildpacks/java-maven/bin/detect
pack build sample-app --builder testcase --buildpack buildpacks/java-maven/ --path apps/java-maven/ --verbose
Before
After
Documentation
Related
Resolves #1322