Skip to content

Conversation

@MTCoster
Copy link
Contributor

@MTCoster MTCoster commented Dec 8, 2025

Fixes #5383.

Tested locally using the following MCRE:

FROM debian:stable

RUN <<EOF
#!/usr/bin/bash
declare -r FOO=foo
EOF

RUN <<-EOF
#!/usr/bin/bash
	declare -r BAR=bar
EOF

RUN <<-EOF
	#!/usr/bin/bash
	declare -r BAZ=baz
EOF

Without this change, the final RUN causes building to fail with /bin/sh: 2: declare: not found since the shebang is not detected.

Copy link
Member

@jedevc jedevc left a comment

Choose a reason for hiding this comment

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

LGTM 🎉

Can you please add a test case to testRunShebangHeredoc in https://github.com/moby/buildkit/blob/master/frontend/dockerfile/dockerfile_heredoc_test.go#291 before we merge?

Comment on lines 306 to 314
RUN <<-EOF
#!/bin/awk -f
BEGIN {
print "hello" >> "/dest"
print "world" >> "/dest"
}
EOF
Copy link
Member

Choose a reason for hiding this comment

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

Can you write it to a different file, and update the assertions below as well.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

That's what I get for rushing 🤦 Should be fixed now.

@MTCoster MTCoster force-pushed the chomp-heredoc-shebang branch from 1ebb516 to bde29fe Compare December 9, 2025 10:54
Fixes: moby#5383
Signed-off-by: Matt Coster <opensource@mtcoster.net>
@MTCoster MTCoster force-pushed the chomp-heredoc-shebang branch from bde29fe to 2eadae2 Compare December 9, 2025 10:56
@jedevc jedevc merged commit 5d7009e into moby:master Dec 9, 2025
169 of 170 checks passed
@MTCoster MTCoster deleted the chomp-heredoc-shebang branch December 10, 2025 15:07
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

shebang not respected using heredoc with tabs stripped

2 participants