rules_docker
rules_docker copied to clipboard
Double quote character silently breaks container_run_and_commit
🐞 bug report
Affected Rule
container_run_and_commit
Is this a regression?
No
Description
Adding a command that contains a "
character leads to templating failure in the generated .build
file. This can lead to silent failure of the build with later commands not run, since the remaining commands after the "
are passed to the run command.
🔬 Minimal Reproduction
container_run_and_commit(
commands = [
"echo step 1",
"echo \"step 2\"",
"false",
],
base = ":some base image"
)
Note it depends on there being a space character between the double quotes in the command, so just echo \"2\"
does not reproduce this.
🔥 Exception or Error
The above example should fail due to the false
command and print 'step 1' and 'step 2'. However the build silently succeeds as nothing beyond the "step
in the second command is run. If you look at the .build
file generated, the double quote is not escaped so the command to sh
is truncated and the rest of the commands are passed as args and generally ignored.
The bug is here: https://github.com/bazelbuild/rules_docker/blob/06525377af957581828ce6c05385015c299b7c0f/docker/util/run.bzl#L474-L476
I don't think the $"
is doing what it is intending to do here and I'm not even sure that's a valid construct compared to $'
🌍 Your Environment
Operating System:
Ubuntu 18.04.5 LTS
Output of bazel version
:
Build label: 4.1.0
Build target: bazel-out/k8-opt/bin/src/main/java/com/google/devtools/build/lib/bazel/BazelServer_deploy.jar
Build time: Fri May 21 11:11:34 2021 (1621595494)
Build timestamp: 1621595494
Build timestamp as int: 1621595494
Rules_docker version:
0.17.0
Anything else relevant?
N/A
Similarly, any command with a newline in will break the templating.
This issue has been automatically marked as stale because it has not had any activity for 180 days. It will be closed if no further activity occurs in 30 days. Collaborators can add an assignee to keep this open indefinitely. Thanks for your contributions to rules_docker!
Not aware that this has been fixed
We've also just encountered this. This seems a severe bug mainly because it fails silently!
bazel version
Bazelisk version: v1.11.0
Build label: 5.0.0
Build target: bazel-out/k8-opt/bin/src/main/java/com/google/devtools/build/lib/bazel/BazelServer_deploy.jar
Build time: Wed Jan 19 14:08:54 2022 (1642601334)
Build timestamp: 1642601334
Build timestamp as int: 1642601334
rules_docker-0.23.0
This issue has been automatically marked as stale because it has not had any activity for 180 days. It will be closed if no further activity occurs in 30 days. Collaborators can add an assignee to keep this open indefinitely. Thanks for your contributions to rules_docker!
Not stale
It also fails for simple commands like: export TEST=test && echo $TEST
sh -c $"export TEST=test && echo $TEST"
sh: TEST=test: command not found
Is that by design?
This issue has been automatically marked as stale because it has not had any activity for 180 days. It will be closed if no further activity occurs in 30 days. Collaborators can add an assignee to keep this open indefinitely. Thanks for your contributions to rules_docker!
.
Also facing the same issue!