[Autoscaler] Precisely match docker HOME (#12020)

* [Autoscaler] Precisely match docker HOME

The current grep will match any env variable keyed by HOME. This will
include some unwanted variables like PYTHONHOME, PROJECT_HOME, etc.
Depending on the order of the environment variable, the subsequent
docker setup command might fail.

* fstring
This commit is contained in:
Simon Mo 2020-11-15 11:49:50 -08:00 committed by GitHub
parent 8b3f79f307
commit ac9610b19d
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -669,8 +669,7 @@ class DockerCommandRunner(CommandRunnerInterface):
if user_pos > -1:
if self.home_dir is None:
self.home_dir = self.ssh_command_runner.run(
"docker exec {} env | grep HOME | cut -d'=' -f2".format(
self.container_name),
f"docker exec {self.container_name} printenv HOME",
with_output=True).decode("utf-8").strip()
if any_char: