Gcloud with cloudbuild 和 Django Postgres 导致 psycopg2 ImportError
Gcloud with cloudbuild and Django Postgres cause psycopg2 ImportError
我正在 App Engine 上构建基于 Django 的应用程序。我创建了一个 Postres CloudSql 实例。我使用 Cloud Build 触发器创建了一个 cloudbuild.yaml 文件。
django = v2.2
psycopg2 = v2.8.4
GAE 运行时:python37
cloudbuild.yaml:
steps:
- name: 'python:3.7'
entrypoint: python3
args: ['-m', 'pip', 'install', '-t', '.', '-r', 'requirements.txt']
- name: 'python:3.7'
entrypoint: python3
args: ['./manage.py', 'migrate', '--noinput']
- name: 'python:3.7'
entrypoint: python3
args: ['./manage.py', 'collectstatic', '--noinput']
- name: "gcr.io/cloud-builders/gcloud"
args: ["app", "deploy"]
timeout: "3000s"
deploymnet 运行正常,应用程序可以连接到数据库。但是当我尝试加载页面时,出现下一个错误:
“...将 psycopg2 导入为数据库文件“/srv/psycopg2/__init__.py”,第 50 行,在 from psycopg2._psycopg import (#noqa ImportError: libpython3.7m.so.1.0:无法打开共享对象文件:没有这样的文件或目录"
另一件有趣的事情是,如果我使用 'gcloud app deploy' 部署我的应用程序(不是通过 Cloud Build),一切正常我没有收到上述错误,我的应用程序可以与数据库通信。
我是 gcloud 的新手,所以我可能错过了一些基础知识。
但我的问题是:
-我的 cloudbuild.yaml 缺少什么来让它工作?
-我是否将我的依赖项安装到正确的位置?
-这个错误的前景与基于云构建的部署和手动部署有什么区别?
据我所知,您正在使用 Cloud Build 运行 gcloud app deploy
。
此命令将您的代码和配置文件提交到 App Engine。正如所解释的 here App Engine 运行s 在 Google 托管环境中自动处理 requirements.txt
文件中指定的依赖项的安装并执行您在 requirements.txt
中定义的入口点=12=]。这样做的好处是不必手动触发依赖项的安装。 cloudbuild 的前两个步骤不会影响 App Engine 的 运行 时间,因为它的配置在部署后由上述文件管理。
Cloud Build is to import source code from a variety of repositories and build binaries or images according to your specifications. It could be used to build Docker images and push them to a repository, download a file to be included in Docker build or package a Go binary an upload it to Cloud Storage. Furthermore the gcloud builder 的目的是通过构建管道 运行 gcloud 命令,例如创建帐户权限或配置防火墙规则,当这些是另一个操作成功所需的步骤时。
由于您不是在自动化构建管道,而是在尝试部署 App Engine 应用程序云构建不是您应该使用的产品。部署到 App Engine 的方法是简单地使用 运行 gcloud app deploy
命令,让 Google 的环境为您处理剩下的事情。
这个 Quickstart 不是准确描述了 OP 试图做的事情吗?
https://cloud.google.com/source-repositories/docs/quickstart-triggering-builds-with-source-repositories
我本人希望将 Django webapp 自动部署到 AppEngine“标准”实例。
我正在 App Engine 上构建基于 Django 的应用程序。我创建了一个 Postres CloudSql 实例。我使用 Cloud Build 触发器创建了一个 cloudbuild.yaml 文件。
django = v2.2
psycopg2 = v2.8.4
GAE 运行时:python37
cloudbuild.yaml:
steps:
- name: 'python:3.7'
entrypoint: python3
args: ['-m', 'pip', 'install', '-t', '.', '-r', 'requirements.txt']
- name: 'python:3.7'
entrypoint: python3
args: ['./manage.py', 'migrate', '--noinput']
- name: 'python:3.7'
entrypoint: python3
args: ['./manage.py', 'collectstatic', '--noinput']
- name: "gcr.io/cloud-builders/gcloud"
args: ["app", "deploy"]
timeout: "3000s"
deploymnet 运行正常,应用程序可以连接到数据库。但是当我尝试加载页面时,出现下一个错误: “...将 psycopg2 导入为数据库文件“/srv/psycopg2/__init__.py”,第 50 行,在 from psycopg2._psycopg import (#noqa ImportError: libpython3.7m.so.1.0:无法打开共享对象文件:没有这样的文件或目录"
另一件有趣的事情是,如果我使用 'gcloud app deploy' 部署我的应用程序(不是通过 Cloud Build),一切正常我没有收到上述错误,我的应用程序可以与数据库通信。
我是 gcloud 的新手,所以我可能错过了一些基础知识。 但我的问题是:
-我的 cloudbuild.yaml 缺少什么来让它工作?
-我是否将我的依赖项安装到正确的位置?
-这个错误的前景与基于云构建的部署和手动部署有什么区别?
据我所知,您正在使用 Cloud Build 运行 gcloud app deploy
。
此命令将您的代码和配置文件提交到 App Engine。正如所解释的 here App Engine 运行s 在 Google 托管环境中自动处理 requirements.txt
文件中指定的依赖项的安装并执行您在 requirements.txt
中定义的入口点=12=]。这样做的好处是不必手动触发依赖项的安装。 cloudbuild 的前两个步骤不会影响 App Engine 的 运行 时间,因为它的配置在部署后由上述文件管理。
Cloud Build is to import source code from a variety of repositories and build binaries or images according to your specifications. It could be used to build Docker images and push them to a repository, download a file to be included in Docker build or package a Go binary an upload it to Cloud Storage. Furthermore the gcloud builder 的目的是通过构建管道 运行 gcloud 命令,例如创建帐户权限或配置防火墙规则,当这些是另一个操作成功所需的步骤时。
由于您不是在自动化构建管道,而是在尝试部署 App Engine 应用程序云构建不是您应该使用的产品。部署到 App Engine 的方法是简单地使用 运行 gcloud app deploy
命令,让 Google 的环境为您处理剩下的事情。
这个 Quickstart 不是准确描述了 OP 试图做的事情吗? https://cloud.google.com/source-repositories/docs/quickstart-triggering-builds-with-source-repositories
我本人希望将 Django webapp 自动部署到 AppEngine“标准”实例。