Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 12 additions & 0 deletions tests/prepare/shell/data/multiline.fmf
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
provision:
how: container
prepare:
how: shell
script: |
test() {
echo "This is a multiline script"
}
test
execute:
how: tmt
script: "true"
7 changes: 7 additions & 0 deletions tests/prepare/shell/test.sh
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,13 @@ rlJournalStart
assert_image_mode
rlPhaseEnd

rlPhaseStartTest "Multiline Shell Scripts"
rlRun -s "tmt run -arvvv provision --how=$PROVISION_HOW $image_opt plans -n multiline"
rlAssertGrep "stdout: STEP 2/2: RUN <<'_TMT_BUILD_SCRIPT'" "$rlRun_LOG"
rlAssertGrep "stdout: This is a multiline script" "$rlRun_LOG"
assert_image_mode
rlPhaseEnd

# TODO: #4785 Preparing from a remote script is broken in Image Mode
if [ "$IMAGE_MODE" != "yes" ]; then
rlPhaseStartTest "Remote Script"
Expand Down
4 changes: 3 additions & 1 deletion tmt/guest/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -2907,7 +2907,9 @@ def collect_command(

# Add to the package manager's engine
self.package_manager.engine.open_containerfile_directives()
self.package_manager.engine.containerfile_directives.append(f"RUN {collected_command}")
self.package_manager.engine.containerfile_directives.append("RUN <<'_TMT_BUILD_SCRIPT'")
self.package_manager.engine.containerfile_directives.append(f"{collected_command}")
self.package_manager.engine.containerfile_directives.append("_TMT_BUILD_SCRIPT")
self.debug(f"Collected command for Containerfile: {collected_command}")

@property
Expand Down
2 changes: 1 addition & 1 deletion tmt/package_managers/bootc.py
Original file line number Diff line number Diff line change
Expand Up @@ -259,7 +259,7 @@ def build_container(self) -> Optional[CommandOutput]:
)
)
self.guest.execute(
ShellScript(f'cat <<EOF > {containerfile_path!s} \n{containerfile} \nEOF')
ShellScript(f'cat <<EOF > {containerfile_path!s}\n{containerfile}\nEOF')
Copy link
Copy Markdown
Member

@LecrisUT LecrisUT May 8, 2026

Choose a reason for hiding this comment

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

Iiuc what you want here is textwrap.deindent? Will look at it again when I have a fresh mind

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

not sure, I will take a look

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Ok, new day fresh mind. Why not guest.push these? There are so many other edge cases, e.g. what if the containerfile_directives contains

RUN cat <<EOF > /etc/profile.d/mpi.sh
module load mpi
EOF

looks like it will clash and end in a fun state.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

I will try, not originally my code, it was just causing me trouble due to the used spurious spaces.

)

self.debug(f"containerfile content: {containerfile}")
Expand Down