Skip to content
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 crash when loading buildpack from OCI archive with relative paths #1506

Conversation

phil9909
Copy link
Contributor

@phil9909 phil9909 commented Sep 2, 2022

Summary

  • tar files can be absolute (/my/path) or relative (my/path).
  • The OCI Image spec does not specify which style to use
  • Some tools (like skopeo for example) use the relative style
  • When reading buildpacks from an archive, pack assumes the absolute style

Output

Prepare

Download a buildpack with skopeo

skopeo copy docker://gcr.io/paketo-buildpacks/java oci-archive:java.cnb --format v2s2

Prepare some.jar as an executable jar file.

Before

$ pack build --builder paketobuildpacks/builder-jammy-buildpackless-base --buildpack java.cnb --path some.jar dev-null --trust-builder
latest: Pulling from paketobuildpacks/builder-jammy-buildpackless-base
Digest: sha256:5517fc3198bbfa84d3f31509c2bc3a14087e5aa718790bdfe9c561b0a19cf91b
Status: Image is up to date for paketobuildpacks/builder-jammy-buildpackless-base:latest
latest: Pulling from paketobuildpacks/run-jammy-base
Digest: sha256:36eddd3a51d37b4e11e7ff958b5c2568f4160e432dd526806a3940ec9369697b
Status: Image is up to date for paketobuildpacks/run-jammy-base:latest
ERROR: failed to build: downloading buildpack: extracting from file:///home/d060677/workspace/pack/java.cnb: reading buildpack: reading buildpack.toml: could not find entry path 'buildpack.toml': not exist

After

$ pack build --builder paketobuildpacks/builder-jammy-buildpackless-base --buildpack java.cnb --path some.jar dev-null --trust-builder                                                                                                                                          
latest: Pulling from paketobuildpacks/builder-jammy-buildpackless-base                                                                                                                                                                                                                                                                                
Digest: sha256:5517fc3198bbfa84d3f31509c2bc3a14087e5aa718790bdfe9c561b0a19cf91b                                                                                                                                                                                                                                                                       
Status: Image is up to date for paketobuildpacks/builder-jammy-buildpackless-base:latest                                                                                                                                                                                                                                                              
latest: Pulling from paketobuildpacks/run-jammy-base                                                                                                                                                                                                                                                                                                  
Digest: sha256:36eddd3a51d37b4e11e7ff958b5c2568f4160e432dd526806a3940ec9369697b                                                                                                                                                                                                                                                                       
Status: Image is up to date for paketobuildpacks/run-jammy-base:latest                                                                                                                                                                                                                                                                                
Restoring data for SBOM from previous image                                                                                                                                                                                                                                                                                                           
===> DETECTING                                                                                                                                                                                                                                                                                                                                        
6 of 24 buildpacks participating                                                                                                                                                                                                                                                                                                                      
paketo-buildpacks/ca-certificates   3.3.0                                                                                                                                                                                                                                                                                                             
paketo-buildpacks/bellsoft-liberica 9.6.1                                                                                                                                                                                                                                                                                                             
paketo-buildpacks/syft              1.18.0                                                                                                                                                                                                                                                                                                            
paketo-buildpacks/executable-jar    6.4.0                                                                                                                                                                                                                                                                                                             
paketo-buildpacks/dist-zip          5.3.0                                                                                                                                                                                                                                                                                                             
paketo-buildpacks/spring-boot       5.18.0
[...]
Successfully built image dev-null

Documentation

  • Should this change be documented?
    • Yes, see #___
    • No

@phil9909 phil9909 requested a review from a team as a code owner September 2, 2022 08:15
@github-actions github-actions bot added the type/enhancement Issue that requests a new feature or improvement. label Sep 2, 2022
@github-actions github-actions bot added this to the 0.28.0 milestone Sep 2, 2022
@phil9909 phil9909 force-pushed the fix-oci-archives-with-relative-paths branch 2 times, most recently from 4f14cc1 to 172c864 Compare September 2, 2022 08:20
Signed-off-by: Pavel Busko <pavel.busko@sap.com>
Signed-off-by: Philipp Stehle <philipp.stehle@sap.com>
Co-authored-by: Philipp Stehle <philipp.stehle@sap.com>
@phil9909 phil9909 force-pushed the fix-oci-archives-with-relative-paths branch from 172c864 to 75a0d6b Compare September 2, 2022 09:26
@codecov
Copy link

codecov bot commented Sep 2, 2022

Codecov Report

Merging #1506 (75a0d6b) into main (651b9a7) will increase coverage by 1.03%.
The diff coverage is 100.00%.

Impacted file tree graph

@@            Coverage Diff             @@
##             main    #1506      +/-   ##
==========================================
+ Coverage   80.24%   81.26%   +1.03%     
==========================================
  Files         154      154              
  Lines       10018    10021       +3     
==========================================
+ Hits         8038     8143     +105     
+ Misses       1499     1397     -102     
  Partials      481      481              
Flag Coverage Δ
os_linux 80.02% <100.00%> (+0.01%) ⬆️
os_macos 77.48% <100.00%> (+0.04%) ⬆️
os_windows 81.14% <100.00%> (+1.03%) ⬆️
unit 81.26% <100.00%> (+1.03%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

Copy link
Member

@jromero jromero left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This post/book section educated me a little further.

Thank you @phil9909. LGTM!

@jromero jromero merged commit 6b954ab into buildpacks:main Sep 9, 2022
@pbusko pbusko deleted the fix-oci-archives-with-relative-paths branch September 12, 2022 15:02
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
type/enhancement Issue that requests a new feature or improvement.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants