-
Notifications
You must be signed in to change notification settings - Fork 545
bake: keep escaped interpolation in print output #3097
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
Merged
Merged
Conversation
This file contains hidden or 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
crazy-max
commented
Apr 8, 2025
bake/bake.go
Outdated
Comment on lines
737
to
770
func (t *Target) MarshalJSON() ([]byte, error) { | ||
tgt := *t | ||
esc := func(s string) string { | ||
return strings.ReplaceAll(strings.ReplaceAll(s, "${", "$${"), "%{", "%%{") | ||
} | ||
|
||
tgt.Annotations = slices.Clone(t.Annotations) | ||
for i, v := range tgt.Annotations { | ||
tgt.Annotations[i] = esc(v) | ||
} | ||
|
||
if tgt.DockerfileInline != nil { | ||
escaped := esc(*tgt.DockerfileInline) | ||
tgt.DockerfileInline = &escaped | ||
} | ||
|
||
tgt.Labels = make(map[string]*string, len(t.Labels)) | ||
for k, v := range t.Labels { | ||
if v != nil { | ||
escaped := esc(*v) | ||
tgt.Labels[k] = &escaped | ||
} | ||
} | ||
|
||
tgt.Args = make(map[string]*string, len(t.Args)) | ||
for k, v := range t.Args { | ||
if v != nil { | ||
escaped := esc(*v) | ||
tgt.Args[k] = &escaped | ||
} | ||
} | ||
|
||
return json.Marshal(tgt) | ||
} |
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 don't really like it but didn't find a way to achieve that during context evaluation with hcl.
900f2a2
to
19bd077
Compare
tonistiigi
reviewed
Apr 8, 2025
Signed-off-by: CrazyMax <[email protected]>
19bd077
to
a91db7c
Compare
tonistiigi
approved these changes
Apr 8, 2025
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.
fixes #2613
The interpolation and directive introductions are escaped by doubling their leading characters. The
${
sequence is escaped as$${
and the%{
sequence is escaped as%%{
.When the definition is parsed, the escape sequence is removed but we need to keep it as we expect a valid input when printing the definition with
--print
.