Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
openshift-installer-presubmits: Set HOME and USER for bazel-build-tar…
…ball OpenShift Prow containers execute with arbitrary container-side UIDs [1] for some security reason I don't understand. That makes it hard for Bazel to figure out where to put things, and we'd die with [2]: + bazel --output_base=/tmp build tarball Error: $USER is not set, and unable to look up name of current user: (error: 0): Success as Bazel [3]: 1. Checked $USER and found it unset. 2. Fell back to getpwuid(getuid()) and found no entry matching the arbitrary container-side UID. Setting USER is not sufficient; it results in errors like [4]: + USER=bazel-testing bazel --output_base=/tmp build tarball Error: mkdir('/.cache/bazel/_bazel_bazel-testing'): (error: 13): Permission denied as Bazel tries to expand its default ~/.cache/bazel [5]. Setting HOME addresses that, but then actions like tarball creation die with [6]: ERROR: /home/prow/go/src/github.com/openshift/installer/BUILD.bazel:106:1: error executing shell command: 'bazel-out/host/bin/external/bazel_tools/tools/build_defs/pkg/build_tar --flagfile=bazel-out/k8-fastbuild/bin/tf_bin.args' failed (Exit 1) Traceback (most recent call last): File "/usr/lib/python2.7/site.py", line 554, in <module> main() File "/usr/lib/python2.7/site.py", line 536, in main known_paths = addusersitepackages(known_paths) File "/usr/lib/python2.7/site.py", line 272, in addusersitepackages user_site = getusersitepackages() File "/usr/lib/python2.7/site.py", line 247, in getusersitepackages user_base = getuserbase() # this will also set USER_BASE File "/usr/lib/python2.7/site.py", line 237, in getuserbase USER_BASE = get_config_var('userbase') File "/usr/lib/python2.7/sysconfig.py", line 582, in get_config_var return get_config_vars().get(name) File "/usr/lib/python2.7/sysconfig.py", line 533, in get_config_vars _CONFIG_VARS['userbase'] = _getuserbase() File "/usr/lib/python2.7/sysconfig.py", line 210, in _getuserbase return env_base if env_base else joinuser("~", ".local") File "/usr/lib/python2.7/sysconfig.py", line 196, in joinuser return os.path.expanduser(os.path.join(*args)) File "/usr/lib/python2.7/posixpath.py", line 262, in expanduser userhome = pwd.getpwuid(os.getuid()).pw_dir KeyError: 'getpwuid(): uid not found: 1000130000' This is the same issue we saw for Bazel, but is now because of Python code [7]. Bazel's build_tar invocation uses run_shell with use_default_shell_env=True [8], so to get HOME set there as well we need to use --action_env [9] (I'm updating test-bazel-build-tarball.sh to pass that argument through to Bazel). [1]: #1178 (comment) [2]: https://storage.googleapis.com/origin-ci-test/pr-logs/pull/openshift_installer/123/ci-pull-openshift-installer-bazel-build-tarball/1/build-log.txt [3]: https://github.com/bazelbuild/bazel/blob/0.16.1/src/main/cpp/blaze_util_posix.cc#L654-L664 [4]: https://storage.googleapis.com/origin-ci-test/pr-logs/pull/openshift_installer/123/ci-pull-openshift-installer-bazel-build-tarball/3/build-log.txt [5]: https://docs.bazel.build/versions/master/output_directories.html#documentation-of-the-current-bazel-output-directory-layout [6]: https://storage.googleapis.com/origin-ci-test/pr-logs/pull/openshift_installer/123/ci-pull-openshift-installer-bazel-build-tarball/4/build-log.txt [7]: https://github.com/python/cpython/blob/1f34aece28d143edb94ca202e661364ca394dc8c/Lib/posixpath.py#L260-L262 [8]: https://github.com/bazelbuild/bazel/blob/0.16.1/tools/build_defs/pkg/pkg.bzl#L82-L89 [9]: https://docs.bazel.build/versions/master/command-line-reference.html#build-options
- Loading branch information