【发布时间】:2021-04-30 12:33:12
【问题描述】:
我正在尝试在 cloudbuild 中使用 DirectRunner 运行 apache 光束管道,通过这样做我需要安装 python 脚本的要求,但我遇到了一些错误。
这是我的 cloudbuild.yaml 的一部分
steps:
- name: gcr.io/cloud-builders/gcloud
entrypoint: 'bash'
args: [ '-c', "gcloud secrets versions access latest --secret=env --format='get(payload.data)' | tr '_-' '/+' | base64 -d > .env" ]
id: GetSecretEnv
# - name: 'gcr.io/google.com/cloudsdktool/cloud-sdk'
# entrypoint: 'bash'
# args: ['-c', 'gcloud config set app/cloud_build_timeout 1600 && gcloud app deploy --quiet tweepy-to-pubsub/app.yaml']
- name: gcr.io/cloud-builders/gcloud
id: Access id_github
entrypoint: 'bash'
args: [ '-c', 'gcloud secrets versions access latest --secret=id_github> /root/.ssh/id_github' ]
volumes:
- name: 'ssh'
path: /root/.ssh
# Set up git with key and domain
- name: 'gcr.io/cloud-builders/git'
id: Set up git with key and domain
entrypoint: 'bash'
args:
- '-c'
- |
chmod 600 /root/.ssh/id_github
cat <<EOF >/root/.ssh/config
Hostname github.com
IdentityFile /root/.ssh/id_github
EOF
ssh-keyscan -t rsa github.com > /root/.ssh/known_hosts
volumes:
- name: 'ssh'
path: /root/.ssh
- name: 'gcr.io/cloud-builders/git'
# Connect to the repository
id: Connect and clone repository
dir: workspace
args:
- clone
- --recurse-submodules
- git@github.com:x/repo.git
volumes:
- name: 'ssh'
path: /root/.ssh
- name: 'gcr.io/$PROJECT_ID/dataflow-python3'
entrypoint: '/bin/bash'
args: [ '-c',
'source /venv/bin/activate' ]
- name: 'gcr.io/$PROJECT_ID/dataflow-python3'
entrypoint: '/bin/bash'
dir: workspace
args: ['pip', 'install','-r', '/dir1/dir2/requirements.txt']
- name: 'gcr.io/$PROJECT_ID/dataflow-python3'
entrypoint: 'python'
dir: workspace
args: [ 'dir1/dir2/script.py',
'--runner=DirectRunner' ]
timeout: "1600s"
没有安装要求的步骤,但我需要库,因为我有缺少库的 python 错误,并且在第二步(实际上是云构建的原始形式的第 5 步),云构建失败了错误
Step #5: Already have image (with digest): gcr.io/x/dataflow-python3
Step #5: import-im6.q16: unable to open X server `' @ error/import.c/ImportImageCommand/360.
Step #5: import-im6.q16: unable to open X server `' @ error/import.c/ImportImageCommand/360.
Step #5: /usr/local/bin/pip: line 5: from: command not found
Step #5: /usr/local/bin/pip: pip: line 7: syntax error near unexpected token `('
Step #5: /usr/local/bin/pip: pip: line 7: ` sys.argv[0] = re.sub(r'(-script\.pyw|\.exe)?$', '', sys.argv[0])'
我该如何解决这个问题?我也试过网上的一些例子,还是不行
编辑:首先我在应用引擎上部署,然后我在云构建 vm 中下载 repo,安装要求并尝试运行 python 脚本
【问题讨论】:
-
根据1,安装要求后您尝试运行的 script.py 文件可能存在问题。您确定它以与 #!/usr/bin/env python 类似的方式以正确的 shebang 字符开头吗?
-
您能否分享完整的 cloudbuild.yaml,或者在您的代码示例中指出第 5 步是什么?
-
@guillaumeblaquiere 我编辑了这个问题,现在它是完整的 cloudbuild.yaml 文件
标签: python linux google-cloud-platform google-cloud-build