rules_docker icon indicating copy to clipboard operation
rules_docker copied to clipboard

Double quote character silently breaks container_run_and_commit

Open aaliddell opened this issue 3 years ago • 10 comments

🐞 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

aaliddell avatar May 24 '21 12:05 aaliddell

Similarly, any command with a newline in will break the templating.

aaliddell avatar May 24 '21 12:05 aaliddell

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!

github-actions[bot] avatar Nov 21 '21 02:11 github-actions[bot]

Not aware that this has been fixed

aaliddell avatar Nov 21 '21 20:11 aaliddell

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

ham1 avatar Mar 04 '22 13:03 ham1

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!

github-actions[bot] avatar Sep 01 '22 03:09 github-actions[bot]

Not stale

aaliddell avatar Sep 01 '22 07:09 aaliddell

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?

achsvg avatar Oct 31 '22 09:10 achsvg

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!

github-actions[bot] avatar Apr 30 '23 02:04 github-actions[bot]

.

aaliddell avatar Apr 30 '23 22:04 aaliddell

Also facing the same issue!

Akash-Mair avatar Jun 12 '23 08:06 Akash-Mair