简体   繁体   English

如何在Google App Engine灵活部署步骤中运行Django迁移?

[英]How to run Django migrations in Google App Engine Flexible deployment step?

I have a Django app up and running in Google App Engine flexible. 我已经在Google App Engine flexible中启动并运行了Django应用。 I know how to run migrations using the cloud proxy or by setting the DATABASES value but I would like to automate running migrations by doing it in the deployment step. 我知道如何使用云代理或通过设置DATABASES值来运行迁移,但是我想通过在部署步骤中执行迁移来自动运行迁移。 However, there does not seem to be a way to run a custom script before or after the deployment. 但是,似乎没有办法在部署之前或之后运行自定义脚本。

The only way I've come up with is by doing it in the entrypoint command which you can set in the app.yaml : 我想出的唯一方法是在entrypoint命令中执行此操作,您可以在app.yaml进行设置:

entrypoint: bash -c 'python3 manage.py migrate --noinput && gunicorn -b :$PORT app.wsgi'  

This feels a lot like doing it wrong. 这感觉很像做错了。 A lot of Googling didn't provide a better answer. 很多谷歌搜索并没有提供更好的答案。

Defining the python3 manage.py migrate command in your app.yaml file will make it run every time a new instance is spawned and set up to serve traffic. 在app.yaml文件中定义python3 manage.py migrate命令将使其在每次生成新实例并设置为服务流量时运行。 Although technically this may not be an issue (no migration will happen if database schema hasn't changed) this isn't the right place to declare it. 尽管从技术上讲这可能不是问题(如果数据库架构未更改,则不会进行迁移),这不是声明它的正确位置。

You'd want this command to run once on every new version code push. 您希望此命令在每次新版本代码推送时运行一次。 This fits perfectly in a CI/CD approach. 这非常适合CI / CD方法。 There are several tutorials on the Google Cloud online documentation using Bitbucket Pipelines or Travis CI for example but you can use many other CI/CD solutions. 例如,在Google Cloud在线文档中有一些使用Bitbucket PipelinesTravis CI的教程,但是您可以使用许多其他CI / CD解决方案。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 GCP:Google App Engine 灵活 + Django 4.0.1 部署问题 - GCP: Google App Engine flexible + Django 4.0.1 problem on deployment 从 bitbucket 管道部署到谷歌应用引擎时如何运行 django 迁移? - How to run django migrations when deploying to google app engine from bitbucket pipeline? Django - Google App Engine 灵活 ENV 上的 SendMail - Django - SendMail on Google App Engine Flexible ENV 如何在有两个 Django 应用程序访问它的同时使用单个 PostGreSQL,这些应用程序在 Google App Engine 和 Google App Engine Flexible 中运行 - How to use a single PostGreSQL while having two Django Apps accessing it that are running in Google App Engine and Google App Engine Flexible 为什么google app engine柔性环境django出现502错误? - why 502 error in google app engine flexible environment django? 在 Google App Engine Flexible - Django 上安装 libmagickwand-dev - Install libmagickwand-dev on Google App Engine Flexible - Django Google App Engine Flexible 上的 Django:创建和删除文件 - Django on Google App Engine Flexible: create and remove files 使用 Django 在 Google App Engine Flexible 上永久重定向 http 到 https - Permanently Redirect http to https on Google App Engine Flexible with Django Django:在Google App Engine迁移过程中的关键错误 - Django: Key error during migrations in Google App Engine 如何在分叉的 Django 应用程序中运行迁移? - How to run migrations in a forked django app?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM