Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

hack/test-bazel-build-tarball: Pass args through to bazel build #125

Conversation

wking
Copy link
Member

@wking wking commented Aug 14, 2018

This allows callers to set build options if needed. The Prow tests need this to set HOME to avoid:

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'

The chain for that crash is:

  1. Bazel invokes build_tar via run_shell with use_default_shell_env=True, so only environment variables declared with --action_env are exposed to build_tar.
  2. Python sees $HOME is empty and falls back to pwd.getpwuid(os.getuid()).pw_dir.
  3. OpenShift Prow containers execute with arbitrary container-side UIDs, so the getpwuid call fails.

With this commit, Prow can setup --action_env to work around its arbitrary container-side UIDs. We'll probably need openshift/release#1185 to be merged and go live before we can land this PR, and we'll need this PR to land before we can land any other installer PRs.

This allows callers to set build options [1] if needed.  The Prow
tests need this to set HOME to avoid [2]:

  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'

The chain for that crash is:

1. Bazel invokes build_tar via run_shell with
   use_default_shell_env=True [3], so only environment variables
   declared with --action_env [1] are exposed to build_tar.
2. Python sees $HOME is empty and falls back to
   pwd.getpwuid(os.getuid()).pw_dir [4].
3. OpenShift Prow containers execute with arbitrary container-side
   UIDs [5], so the getpwuid call fails.

With this commit, Prow can setup --action_env to work around its
arbitrary container-side UIDs [6].

[1]: https://docs.bazel.build/versions/master/command-line-reference.html#build-options
[2]: https://storage.googleapis.com/origin-ci-test/pr-logs/pull/openshift_installer/123/ci-pull-openshift-installer-bazel-build-tarball/4/build-log.txt
[3]: https://github.com/bazelbuild/bazel/blob/0.16.1/tools/build_defs/pkg/pkg.bzl#L82-L89
[4]: https://github.com/python/cpython/blob/1f34aece28d143edb94ca202e661364ca394dc8c/Lib/posixpath.py#L260-L262
[5]: openshift/release#1178 (comment)
[6]: openshift/release#1185
@openshift-ci-robot openshift-ci-robot added approved Indicates a PR has been approved by an approver from all required OWNERS files. size/XS Denotes a PR that changes 0-9 lines, ignoring generated files. labels Aug 14, 2018
@wking
Copy link
Member Author

wking commented Aug 14, 2018

/retest

1 similar comment
@wking
Copy link
Member Author

wking commented Aug 14, 2018

/retest

@abhinavdahiya
Copy link
Contributor

/lgtm

@openshift-ci-robot openshift-ci-robot added the lgtm Indicates that a PR is ready to be merged. label Aug 14, 2018
@openshift-ci-robot
Copy link
Contributor

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: abhinavdahiya, wking

The full list of commands accepted by this bot can be found here.

The pull request process is described here

Needs approval from an approver in each of these files:
  • OWNERS [abhinavdahiya,wking]

Approvers can indicate their approval by writing /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

@openshift-merge-robot openshift-merge-robot merged commit fc01b3a into openshift:master Aug 14, 2018
@wking wking deleted the bazel-tarball-pass-build-arguments branch August 14, 2018 21:59
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
approved Indicates a PR has been approved by an approver from all required OWNERS files. lgtm Indicates that a PR is ready to be merged. size/XS Denotes a PR that changes 0-9 lines, ignoring generated files.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants