bazelbuild / bazelbuild/rules_docker
Double quote character silently breaks container_run_and_commit
- Dominant language
- Starlark
- Stars
- 1.1k
- Forks
- 689
- PR merge metrics
- No merged PRs in 30d
Description
# 🐞 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
```starlark
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
Contributor guide
Assessment
This issue has not been assessed yet.