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

Fixing an parsing error with the buildpacks to be flattened #2053

Merged
merged 2 commits into from
Feb 7, 2024

Conversation

jjbustamante
Copy link
Member

@jjbustamante jjbustamante commented Feb 6, 2024

Summary

Unfortunately with pack 0.33.0 I didn't realized spf13/cobra library was parsing a comma separated string input to created a []string already splited. As a consequence, when users tries to use the new --flatten flag implementation, when creating a builder, the group of buildpacks to be in the same layer was incorrectly created.

This PR changes the method use to parse the flag from spf13/cobra to be StringArrayVar which according to the documentation The value of each argument will not try to be separated by comma

Output

Before

See the original issue #2050 reported

After

pack builder create --verbose --config builder-22/builder.toml --flatten "heroku/gradle@4.1.0,heroku/java@4.1.0,heroku/jvm@4.1.0,heroku/maven@4.1.0,heroku/sbt@4.1.0,heroku/scala@4.1.0" builder-flattened

The logic to flattened is working as expected, using dive tool we can check the previous buildpack were put together in the same layer

Screenshot 2024-02-06 at 11 19 29 AM

Documentation

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

Related

Resolves #2050

@github-actions github-actions bot added the type/enhancement Issue that requests a new feature or improvement. label Feb 6, 2024
@github-actions github-actions bot added this to the 0.34.0 milestone Feb 6, 2024
@jjbustamante jjbustamante modified the milestones: 0.34.0, 0.33.1 Feb 6, 2024
@jjbustamante jjbustamante added type/bug Issue that reports an unexpected behaviour. and removed type/enhancement Issue that requests a new feature or improvement. labels Feb 6, 2024
@jjbustamante jjbustamante marked this pull request as ready for review February 6, 2024 16:45
@jjbustamante jjbustamante requested review from a team as code owners February 6, 2024 16:45
@natalieparellano
Copy link
Member

In func ParseFlattenBuildModules(buildpacksID []string, sep string) (FlattenModuleInfos, error) { can we not just get rid of sep entirely and expect a list? Then --flatten would have a nice parity with how we already handle lists like pack build --buildpack (note Repeat for each buildpack in order, or supply once by comma-separated list):

  -b, --buildpack strings            Buildpack to use. One of:
                                       a buildpack by id and version in the form of '<buildpack>@<version>',
                                       path to a buildpack directory (not supported on Windows),
                                       path/URL to a buildpack .tar or .tgz file, or
                                       a packaged buildpack image name in the form of '<hostname>/<repo>[:<tag>]'
                                     Repeat for each buildpack in order, or supply once by comma-separated list

It seems weird to sometimes expect commas and sometimes expect semicolons when providing list arguments to pack

@github-actions github-actions bot added the type/enhancement Issue that requests a new feature or improvement. label Feb 6, 2024
@github-actions github-actions bot modified the milestones: 0.33.1, 0.34.0 Feb 6, 2024
@jjbustamante
Copy link
Member Author

In func ParseFlattenBuildModules(buildpacksID []string, sep string) (FlattenModuleInfos, error) { can we not just get rid of sep entirely and expect a list? Then --flatten would have a nice parity with how we already handle lists like pack build --buildpack (note Repeat for each buildpack in order, or supply once by comma-separated list):

  -b, --buildpack strings            Buildpack to use. One of:
                                       a buildpack by id and version in the form of '<buildpack>@<version>',
                                       path to a buildpack directory (not supported on Windows),
                                       path/URL to a buildpack .tar or .tgz file, or
                                       a packaged buildpack image name in the form of '<hostname>/<repo>[:<tag>]'
                                     Repeat for each buildpack in order, or supply once by comma-separated list

It seems weird to sometimes expect commas and sometimes expect semicolons when providing list arguments to pack

Yeah, sorry for that, checking deeply the options in Cobra, I found that StringArrayVar was actually what I need!

@jjbustamante jjbustamante modified the milestones: 0.34.0, 0.33.1 Feb 6, 2024
@jjbustamante jjbustamante removed the type/enhancement Issue that requests a new feature or improvement. label Feb 6, 2024
@natalieparellano
Copy link
Member

LGTM. We might want to add an acceptance test to ensure there aren't any regressions later

Copy link

codecov bot commented Feb 6, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Comparison is base (30dcc15) 79.63% compared to head (572f869) 79.63%.

Additional details and impacted files

Impacted file tree graph

@@           Coverage Diff           @@
##             main    #2053   +/-   ##
=======================================
  Coverage   79.63%   79.63%           
=======================================
  Files         176      176           
  Lines       13214    13214           
=======================================
  Hits        10522    10522           
  Misses       2022     2022           
  Partials      670      670           
Flag Coverage Δ
os_linux 78.54% <100.00%> (-0.02%) ⬇️
os_macos 76.39% <100.00%> (ø)
os_windows 79.02% <100.00%> (ø)
unit 79.63% <100.00%> (ø)

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

@github-actions github-actions bot added type/enhancement Issue that requests a new feature or improvement. type/chore Issue that requests non-user facing changes. labels Feb 6, 2024
@github-actions github-actions bot modified the milestones: 0.33.1, 0.34.0 Feb 6, 2024
@@ -3315,6 +3364,157 @@ func createStackImage(dockerCli client.CommonAPIClient, repoName string, dir str
}))
}

func createFlattenBuilder(
Copy link
Member Author

Choose a reason for hiding this comment

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

I didn't want to invest a lot of time refactoring the setup for a builder creation, this method is very similar to create complex builder, maybe it is time to continue Javier's work on refactoring the tests

@jjbustamante jjbustamante modified the milestones: 0.34.0, 0.33.1 Feb 6, 2024
@jjbustamante jjbustamante removed the type/enhancement Issue that requests a new feature or improvement. label Feb 6, 2024
@jjbustamante jjbustamante removed the type/chore Issue that requests non-user facing changes. label Feb 6, 2024
@github-actions github-actions bot modified the milestones: 0.33.1, 0.34.0 Feb 6, 2024
@github-actions github-actions bot added type/enhancement Issue that requests a new feature or improvement. type/chore Issue that requests non-user facing changes. labels Feb 6, 2024
Using StringArrayVar

Signed-off-by: Juan Bustamante <jbustamante@vmware.com>
Signed-off-by: Juan Bustamante <jbustamante@vmware.com>

when("builder create", func() {
when("--flatten=<buildpacks>", func() {
it("should flatten together all specified buildpacks", func() {
Copy link
Member Author

Choose a reason for hiding this comment

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

The test correctly failed when using previous pack version to create the builder. That's the reason the error was reported.

@jjbustamante jjbustamante modified the milestones: 0.34.0, 0.33.1 Feb 7, 2024
@jjbustamante jjbustamante removed type/enhancement Issue that requests a new feature or improvement. type/chore Issue that requests non-user facing changes. labels Feb 7, 2024
@jjbustamante jjbustamante merged commit c45c3cf into main Feb 7, 2024
18 checks passed
@jjbustamante jjbustamante deleted the bugfix/jjbustamante/issue-2050 branch February 7, 2024 15:09
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
type/bug Issue that reports an unexpected behaviour.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

pack builder create --flatten doesn't flatten any layers
2 participants