使用 Google Cloud Build 部署到 Google App Engine 时,依赖项 (requirements.txt) 未正确安装
Dependencies (requirements.txt) not installing correctly when deploying to Google App Engine using Google Cloud Build
我在将我的应用程序部署到 Google App Engine (Python 2.7) 时遇到了一个奇怪的依赖问题。
我已经在 requirements.txt 文件中指定了我的依赖项:
Flask==1.0.2
werkzeug>=0.14
flask-cors
twilio
httplib2
gunicorn
Jinja2
google-cloud-ndb
exponent_server_sdk
当使用 requirements.txt 文件夹中的 pip 在本地安装时,这些在本地开发服务器上工作正常。
但是,当我部署到 App Engine 时,似乎尚未安装模块 exponent_server_sdk(导入错误:没有名为 exponent_server_sdk 的模块)。
我通常通过推送到 git 存储库进行部署,然后使用 Google Cloud Build ("gcr.io/cloud-builders/gcloud") 进行部署。我部署时没有错误,requirements.txt 文件中的其他依赖项工作正常,例如 twilio 或 Jinja2。
在调查这个问题的同时,我尝试使用 gcloud app deploy 直接从我的开发机器推送。当我这样做时,出于某种奇怪的原因,exponent_server_sdk 可用并且工作正常。
这种行为对我来说似乎很奇怪,我找不到任何遇到类似错误的人的文档。我想知道是否有人可以就可能导致此问题的原因或我可以查找错误的地方提供任何指导(例如 deployment/instance 启动期间安装 requirements.txt 文件的过程日志)。
回复评论:
我是运行标准环境。
我的 cloudbuild.yaml 看起来像这样:
steps:
- name: "gcr.io/cloud-builders/gcloud"
args: ["app", "deploy", "app.yaml", "dispatch.yaml", "service_1.yaml", "service_2.yaml", "service_3.yaml", "index.yaml"]
timeout: "1600s"
我遇到错误的服务的 .yaml 文件如下所示:
runtime: python27
api_version: 1
threadsafe: true
service: notifications
libraries:
- name: ssl
version: latest
handlers:
- url: /.*
script: notifications.app
对于(第一代)标准环境,部署过程不使用 requirements.txt
文件,库应该安装在您的应用程序中。来自 Copying a third-party library:
Use pip (version 6 or later) with the -t <directory>
flag to
copy the libraries into the folder you created in the previous step.
For example:
pip install -t lib/ <library_name>
是的,如果您愿意,可以使用 requirements.txt
文件在您的应用程序中进行安装,但部署过程不会使用该文件本身。
由于您不是直接从安装库的环境进行部署,因此您还必须将安装目录添加到 git 存储库中。
我在将我的应用程序部署到 Google App Engine (Python 2.7) 时遇到了一个奇怪的依赖问题。
我已经在 requirements.txt 文件中指定了我的依赖项:
Flask==1.0.2
werkzeug>=0.14
flask-cors
twilio
httplib2
gunicorn
Jinja2
google-cloud-ndb
exponent_server_sdk
当使用 requirements.txt 文件夹中的 pip 在本地安装时,这些在本地开发服务器上工作正常。
但是,当我部署到 App Engine 时,似乎尚未安装模块 exponent_server_sdk(导入错误:没有名为 exponent_server_sdk 的模块)。
我通常通过推送到 git 存储库进行部署,然后使用 Google Cloud Build ("gcr.io/cloud-builders/gcloud") 进行部署。我部署时没有错误,requirements.txt 文件中的其他依赖项工作正常,例如 twilio 或 Jinja2。
在调查这个问题的同时,我尝试使用 gcloud app deploy 直接从我的开发机器推送。当我这样做时,出于某种奇怪的原因,exponent_server_sdk 可用并且工作正常。
这种行为对我来说似乎很奇怪,我找不到任何遇到类似错误的人的文档。我想知道是否有人可以就可能导致此问题的原因或我可以查找错误的地方提供任何指导(例如 deployment/instance 启动期间安装 requirements.txt 文件的过程日志)。
回复评论:
我是运行标准环境。
我的 cloudbuild.yaml 看起来像这样:
steps:
- name: "gcr.io/cloud-builders/gcloud"
args: ["app", "deploy", "app.yaml", "dispatch.yaml", "service_1.yaml", "service_2.yaml", "service_3.yaml", "index.yaml"]
timeout: "1600s"
我遇到错误的服务的 .yaml 文件如下所示:
runtime: python27
api_version: 1
threadsafe: true
service: notifications
libraries:
- name: ssl
version: latest
handlers:
- url: /.*
script: notifications.app
对于(第一代)标准环境,部署过程不使用 requirements.txt
文件,库应该安装在您的应用程序中。来自 Copying a third-party library:
Use pip (version 6 or later) with the
-t <directory>
flag to copy the libraries into the folder you created in the previous step. For example:pip install -t lib/ <library_name>
是的,如果您愿意,可以使用 requirements.txt
文件在您的应用程序中进行安装,但部署过程不会使用该文件本身。
由于您不是直接从安装库的环境进行部署,因此您还必须将安装目录添加到 git 存储库中。