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

Allow build --env option to be comma separated list. #1212

Merged
merged 2 commits into from
Aug 11, 2021

Conversation

kramarz
Copy link
Contributor

@kramarz kramarz commented Jun 18, 2021

Summary

According to help
(https://buildpacks.io/docs/tools/pack/cli/pack_build/) it should
already be this way.

Before

only --env KEY1=VAL1 --env KEY2=VAL2 syntax is allowed

After

also --env KEY1=VAL1,KEY2=VAL2 syntax is allowed

Documentation

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

@kramarz kramarz requested a review from a team as a code owner June 18, 2021 09:00
@github-actions github-actions bot added the type/enhancement Issue that requests a new feature or improvement. label Jun 18, 2021
@github-actions github-actions bot added this to the 0.20.0 milestone Jun 18, 2021
Copy link
Member

@dfreilich dfreilich left a comment

Choose a reason for hiding this comment

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

Thanks for the fix!

@github-actions github-actions bot added the type/chore Issue that requests non-user facing changes. label Jun 25, 2021
@kramarz
Copy link
Contributor Author

kramarz commented Jun 25, 2021

So acceptance test have detected some inconsistency. Currently syntax like this one works:
--env "ENV1_CONTENTS=\"Env1 Layer Contents From Command Line\"" and after the change it will no longer work.

On the other hand it really differs only if user pass quotation marks to the command (escaped them in shell) so they would get stripped by flags library - they could just omit quotes in that case.

--env "ENV1_CONTENTS=Env1 Layer Contents From Command Line" and
--env "\"ENV1_CONTENTS=Env1 Layer Contents From Command Line\"" would still work.

I have changed acceptance test to avoid that first syntax.

@@ -1482,7 +1482,7 @@ func testAcceptance(
"build", repoName,
"-p", filepath.Join("testdata", "mock_app"),
"--env", "DETECT_ENV_BUILDPACK=true",
"--env", `ENV1_CONTENTS="Env1 Layer Contents From Command Line"`,
"--env", `"ENV1_CONTENTS=Env1 Layer Contents From Command Line"`,
Copy link
Member

Choose a reason for hiding this comment

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

I'm a little concerned by this new change. I can't see this as expected behaviour from a user's perspective. What's the purpose of quoting the key and value?

I would have expected the following to work.

--env 'KEY_1=VAL1,KEY_2="VAL 2"'
key value
KEY_1 VAL1
KEY_2 VAL 2

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Ok, I have tried implementing that, but this is way more complicated then I thought it will be - library does not support it so we have to parse it on our own.

@jromero
Copy link
Member

jromero commented Jun 28, 2021

@kramarz Unfortunately this implementation is clashing with being able to provide Windows paths in environment variable hence why tests are failing.

Here are the relevant logs from the test outputs:

image

@kramarz
Copy link
Contributor Author

kramarz commented Jul 4, 2021

Right, we don't want to break such use cases. What about different approach to escaping?

Original solution with using StringSliceVarP was using CSV syntax for escaping commas and quotation marks, but you have suggested to not use include keys in quotes. I have now changed that so we would keep CSV escaping rules, but only for the value.

--env 'KEY_1=VAL1,KEY_2="Super, ""luxurious"" truck"'
key value
KEY_1 VAL1
KEY_2 Super, "luxurious" truck

Please let me know if you have any suggestions for this issue.

it("sets flag variables", func() {
mockClient.EXPECT().
Build(gomock.Any(), EqBuildOptionsWithEnv(map[string]string{
"KEY1": `VALUE"`,
Copy link
Member

Choose a reason for hiding this comment

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

I'm a bit confused by this - why is it matching

`VALUE"` and not `VALUE""`

?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

"" escapes " - it is the same as in CSV specification. The same escaping is used for other flags: buildpack and tag since they use StringSliceVarP. I just wanted to be consistent with what is already being used.

Sorry for delay - I was on holiday. I see there are some errors about missing tests - I ll try to add them this week.

@jromero
Copy link
Member

jromero commented Sep 18, 2021

@kramarz, seems like we have some use cases that were broken by this change. We had to revert it. The use cases brought up the fact that this may be harder to resolve than originally expected. I believe that the right path forward would be not to support (and therefore not mention) env vars to be listed together in a single flag.

See #1288 and #1289

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