Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/287.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
在GCP cloudbuild中安装python需求时出现问题_Python_Linux_Google Cloud Platform_Google Cloud Build - Fatal编程技术网

在GCP cloudbuild中安装python需求时出现问题

在GCP cloudbuild中安装python需求时出现问题,python,linux,google-cloud-platform,google-cloud-build,Python,Linux,Google Cloud Platform,Google Cloud Build,我正在尝试在cloudbuild中使用DirectRunner运行apache beam管道,通过这样做,我需要安装python脚本的要求,但我面临一些错误。 这是我cloudbuild.yaml的一部分 steps: - name: gcr.io/cloud-builders/gcloud entrypoint: 'bash' args: [ '-c', "gcloud secrets versions access latest --secret=env --for

我正在尝试在cloudbuild中使用DirectRunner运行apache beam管道,通过这样做,我需要安装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"
我该如何解决这个问题?我也在网上试过一些例子,但都不起作用


编辑:首先我在app engine上部署,然后在cloud build vm中下载repo,安装需求并尝试运行python脚本。我认为问题来自您的路径定义

'source /venv/bin/activate'

您使用完整路径定义,但它在云构建中不起作用。当前工作目录是
/workspace/
。如果使用相对路径,只需在路径前添加一个点,效果会更好

或者不。。。事实上,在一个步骤中就可以激活venv,在接下来的步骤中安装pip。从一个步骤到另一个步骤,运行时环境被卸载,并与另一个容器一起重新加载。因此,设置环境变量的
source
命令将在
pip
步骤中消失


此外,您的云构建环境是为构建和销毁而构建的。在这种情况下,您不需要使用venv,您可以像这样简化最后3个步骤


- name: 'gcr.io/$PROJECT_ID/dataflow-python3'
  entrypoint: '/bin/bash'
  args:
   - '-c'
   - |
       pip install -r ./dir1/dir2/requirements.txt
       python ./dir1/dir2/script.py --runner=DirectRunner


我认为这个问题来自于你的路径定义

'source /venv/bin/activate'

您使用完整路径定义,但它在云构建中不起作用。当前工作目录是
/workspace/
。如果使用相对路径,只需在路径前添加一个点,效果会更好

或者不。。。事实上,在一个步骤中就可以激活venv,在接下来的步骤中安装pip。从一个步骤到另一个步骤,运行时环境被卸载,并与另一个容器一起重新加载。因此,设置环境变量的
source
命令将在
pip
步骤中消失


此外,您的云构建环境是为构建和销毁而构建的。在这种情况下,您不需要使用venv,您可以像这样简化最后3个步骤


- name: 'gcr.io/$PROJECT_ID/dataflow-python3'
  entrypoint: '/bin/bash'
  args:
   - '-c'
   - |
       pip install -r ./dir1/dir2/requirements.txt
       python ./dir1/dir2/script.py --runner=DirectRunner


根据,安装需求后,您试图运行的script.py文件可能存在问题。你确定它是以与#相似的方式开始的吗/usr/bin/env python?你能分享完整的cloudbuild.yaml吗,或者在你的代码示例中指出第5步是什么?@guillaumeblaquiere我现在编辑了这个问题,它是完整的cloudbuild.yaml文件,因为它可能是安装需求后试图运行的script.py文件的问题。你确定它是以与#相似的方式开始的吗/usr/bin/env python?你能分享完整的cloudbuild.yaml吗,或者在你的代码示例中指出第5步是什么?@guillaumeblaquiere我编辑了这个问题,现在是完整的cloudbuild.yaml文件是的,成功了,tnx!!!是的,成功了,tnx!!!