[英]How can I pass a variable from github actions workflow to a GAE app.yaml file?
I have a django project I want to put into maintenance mode before I update (migrate) the database.我有一个 django 项目,我想在更新(迁移)数据库之前将其置于维护模式。
So, my github workflow所以,我的 github 工作流程
My question is, I am trying to use a single app.yaml file for both deploys.我的问题是,我正在尝试对两个部署使用一个 app.yaml 文件。 To pass the MAINTENANCE_MODE variable from github actions workflow to the app.yaml file, how can I do this?
要将 MAINTENANCE_MODE 变量从 github 操作工作流传递到 app.yaml 文件,我该怎么做?
I know you can import secrets like so:我知道你可以像这样导入秘密:
runtime: python38
instance_class: F2
env_variables:
DB_URL: $ {{ secrets.DB_URL }}
But I don't know how to modify a secret in the workflow.但我不知道如何修改工作流程中的秘密。 Perhaps its not a secret but some other type of variable one can set in the workflow and access in the app.yaml?
也许这不是秘密,而是可以在工作流中设置并在应用程序中访问的其他类型的变量。yaml?
So it appears that Google App Engine's yaml files do not support dynamic environment variable substitution.因此,Google App Engine 的 yaml 文件似乎不支持动态环境变量替换。 Static substitution (like using github's secrets) works, because github compiles the file with the github environment variable before the workflow runs, but there's no clear way to modify a file with a variable that is going to change during a workflow.
Static 替换(如使用 github 的秘密)有效,因为 github 使用 github 编译文件,在工作流运行之前更改工作流环境变量。
A method however that does work is to compile a new GAE yaml file during the workflow.然而,一种可行的方法是在工作流期间编译一个新的 GAE yaml 文件。 Here's what I came up with in the end...
这是我最后想到的......
- name: Put in Maintenance mode
run: |
MAINTENANCE_MODE=1 envsubst < app_eng_staging.yml.template > app.yaml
cat app.yaml
gcloud app deploy --project staging-project --quiet
- name: Collectstatic and migrate
env:
RUNNING_ENVIRONMENT: 'Staging_Server'
DJANGO_DEBUG: 'False'
run: |
pipenv run python manage.py collectstatic --noinput
pipenv run python manage.py migrate
- name: Turn off Maintenance and Deploy
run: |
MAINTENANCE_MODE=0 envsubst < app_eng_staging.yml.template > app.yaml
gcloud app deploy --project staging-project --quiet
The trick is to use the linux envsubst command.诀窍是使用 linux envsubst命令。 We start with a app_eng_staging.yml.template file, which looks like so:
我们从一个 app_eng_staging.yml.template 文件开始,它看起来像这样:
runtime: python38
instance_class: F2
env_variables:
RUNNING_ENVIRONMENT: 'Staging_Server'
StagingServerDB: $ {{ secrets.STAGINGSERVER_DB }}
MAINTENANCE_MODE: ${MAINTENANCE_MODE}
FRONTEND_URL: $ {{ secrets.STAGING_FRONTEND_URL }}
envsubst then populates ${MAINTENANCE_MODE} with the value 1 and the result is saved to a new file app.yaml. envsubst 然后用值 1 填充 ${MAINTENANCE_MODE},并将结果保存到新文件 app.yaml。
After we finish working with out database migration, we can use envsubst to create a new app.yaml with MAINTENANCE_MODE set to zero (off), and re-deploy.完成数据库迁移后,我们可以使用 envsubst 创建一个新的 app.yaml 并将 MAINTENANCE_MODE 设置为零(关闭),然后重新部署。
Neat huh?整齐吧?
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.