[英]Cloud Build env variables not passed to Django app on GAE
I have a Django app running on Google AppEngine Standard environment.我有一个在 Google AppEngine 标准环境上运行的 Django 应用程序。 I've set up a cloud build trigger from my master branch in Github to run the following steps:
我已经从 Github 中的主分支设置了云构建触发器,以运行以下步骤:
steps:
- name: 'python:3.7'
entrypoint: python3
args: ['-m', 'pip', 'install', '--target', '.', '--requirement', 'requirements.txt']
- name: 'python:3.7'
entrypoint: python3
args: ['./manage.py', 'collectstatic', '--noinput']
- name: 'gcr.io/cloud-builders/gcloud'
args: ['app', 'deploy', 'app.yaml']
env:
- 'SHORT_SHA=$SHORT_SHA'
- 'TAG_NAME=$TAG_NAME'
I can see under the Execution Details tab on Cloud Build that the variables were actually set.我可以在 Cloud Build 的 Execution Details 选项卡下看到实际设置了变量。
The problem is, SHORT_SHA
and TAG_NAME
aren't accessible from my Django app (followed instructions at https://cloud.google.com/cloud-build/docs/configuring-builds/substitute-variable-values#using_user-defined_substitutions ).问题是,我的 Django 应用程序无法访问
SHORT_SHA
和TAG_NAME
(按照https://cloud.google.com/cloud-build/docs/configuring-builds/substitute-variable-values#using_user-defined_substitution的说明进行操作)。 But if I set them in my app.yaml file with hardcoded values under env_variables
, then my Django app can access those hardcoded values (and the values set in my build don't overwrite those hardcoded in app.yaml).但是,如果我在 app.yaml 文件中使用
env_variables
下的硬编码值设置它们,那么我的 Django 应用程序可以访问这些硬编码值(并且在我的构建中设置的值不会覆盖那些在 app.yaml 中硬编码的值)。
Why is this?为什么是这样? Am I accessing them/setting them incorrectly?
我是否访问它们/设置不正确? Should I be setting them in app.yaml somehow?
我应该以某种方式在 app.yaml 中设置它们吗?
I even printed the whole os.environ
dictionary in one of my views to see if they were just there with different names or something, but they're not present in there.我什至在我的一个视图中打印了整个
os.environ
字典,以查看它们是否只是用不同的名称或其他东西在那里,但它们不存在在那里。
Not the cleanest solution, but I used this medium post as a guidance to my solution.不是最干净的解决方案,但我使用这篇中等帖子作为我的解决方案的指导。 I hypothesize that
runserver
command isn't being passed those env variables, and that those variables are only used for the app deploy
command.我假设
runserver
命令没有被传递那些 env 变量,并且这些变量仅用于app deploy
命令。
.env
file in project dir.env
文件中.env
file in this step).env
文件中) - name: 'python:3.7'
entrypoint: python3
args: ['./create_env_file.py']
env:
- 'SHORT_SHA=$SHORT_SHA'
- 'TAG_NAME=$TAG_NAME'
app deploy
happensapp deploy
发生时,您的应用程序应该具有这些环境变量
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.