2017-11-28 2 views
1

Bazel genrule에서 gcloud를 실행하는 데 문제가 있습니다. 파이썬 경로와 관련된 문제처럼 보입니다.bazel genrule에서 gcloud 호출하기

genrule(
    name="foo", 
    outs=["bar"], 
    srcs=[":bar.enc"], 
    cmd="gcloud decrypt --location=global --keyring=foo --key=bar --plaintext-file [email protected] --ciphertext-file $(location bar.enc)" 
) 

는 예외입니다 :

ImportError: No module named traceback 

에서 :

try: 
    gcloud_main = _import_gcloud_main() 
    except Exception as err: # pylint: disable=broad-except 
    # We want to catch *everything* here to display a nice message to the user 
    # pylint:disable=g-import-not-at-top 
    import traceback 
    # We DON'T want to suggest `gcloud components reinstall` here (ex. as 
    # opposed to the similar message in gcloud_main.py), as we know that no 
    # commands will work. 
    sys.stderr.write(
     ('ERROR: gcloud failed to load: {0}\n{1}\n\n' 
     'This usually indicates corruption in your gcloud installation or ' 
     'problems with your Python interpreter.\n\n' 
     'Please verify that the following is the path to a working Python 2.7 ' 
     'executable:\n' 
     ' {2}\n\n' 
     'If it is not, please set the CLOUDSDK_PYTHON environment variable to ' 
     'point to a working Python 2.7 executable.\n\n' 
     'If you are still experiencing problems, please reinstall the Cloud ' 
     'SDK using the instructions here:\n' 
     ' https://cloud.google.com/sdk/\n').format(
      err, 
      '\n'.join(traceback.format_exc().splitlines()[2::2]), 
      sys.executable)) 
    sys.exit(1) 

내 질문

은 다음과 같습니다

  • 어떻게 genrule에서 나는 최고의 통화 gcloud합니까?
  • 파이썬 경로를 지정하는 데 필요한 매개 변수는 무엇입니까?
  • Bazel은 어떻게 차단합니까?

업데이트 : CLOUDSDK_PYTHON을 지정하여 실행할 수 있습니다.

답변

2

실제로는 bazel runs in a sandbox이므로 gcloud는 해당 종속성을 찾을 수 없습니다. 사실, 나는 gcloud을 전혀 호출 할 수 있다는 것에 놀랐습니다.

계속 진행하려면 gcloud을 bazel py_binary에 넣고 genherle의 tools 속성을 참조하십시오. cmdlocation으로 묶어야합니다. 결국, 당신은

genrule(
    name = "foo", 
    outs = ["bar"], 
    srcs = [":bar.enc"], 
    cmd = "$(location //third_party/google/gcloud) decrypt --location=global --keyring=foo --key=bar --plaintext-file [email protected] --ciphertext-file $(location bar.enc)", 
    tools = ["//third_party/google/gcloud"], 
) 

을해야합니다 그리고 당신은 third_party/google/gcloud/BUILD에 정의 (또는 어디에서든지 당신의 희망이, 난 그냥 나에게 의미가 경로 사용)이 뭔가를 얻기에 충분했다

py_binary(
    name = "gcloud", 
    srcs = ["gcloud.py"], 
    main = "gcloud.py", 
    visibility = ["//visibility:public"], 
    deps = [ 
     ":gcloud_sdk", 
    ], 
) 
py_library(
    name = "gcloud_sdk", 
    srcs = glob(
     ["**/*.py"], 
     exclude = ["gcloud.py"], 
     # maybe exclude tests and unrelated code, too. 
), 
    deps = [ 
    # Whatever extra deps are needed by gcloud to compile 
    ] 
) 
+0

을 대부분 일하고있다. py_library 규칙은 올바른 데이터를 얻기 위해 몇 가지 데이터 파일과 추가 작업이 필요합니다. –