在Google Build期间在app.yaml文件中添加环境变量
我正在将Google Cloud Build与cloudbuild.yaml
一起使用,以下载app.yaml
文件,该文件包含基于Python
的应用程序的环境变量.用于初始部署的app.yaml
版本不包含用于安全保护的环境变量.
I'm using Google Cloud Build with cloudbuild.yaml
to download an app.yaml
file that includes environment variables for my Python
based app. The app.yaml
version used for the initial deployment does not contain the environment variables for security protection.
但是,这似乎不起作用,也没有检测到环境变量-因为app.yaml
似乎没有被覆盖.
However, it seems this isn't working and the environment variables aren't being detected - as the app.yaml
does not seem to be overwritten.
以下是我的cloudbuild.yaml
配置:
steps:
- name: gcr.io/cloud-builders/gsutil
args:
[
"cp",
"gs://<path to bucket>/app.yaml",
"app.yaml",
]
我知道App Engine
上应用程序的入口点是通过app.yaml
进入的,但我认为如果包含cloudBuild.yaml
,则将首先调用它,然后再调用app.yaml
.
I understand the entrypoint for an app on App Engine
is through app.yaml
but I thought that if cloudBuild.yaml
is included, this would be called first and then app.yaml
.
如果这不正确,我还能如何将环境变量附加到我的app.yaml文件中?
If this isn't correct how else can I append environment variables to my app.yaml file?
谢谢!
当您运行gcloud app deploy
时,部署过程不会考虑cloudbuild.yaml
文件,它将与您未填充的一起部署您的应用 app.yaml
文件.
When you run gcloud app deploy
, the deployment process won't take the cloudbuild.yaml
file into account and will deploy your app along with your unpopulated app.yaml
file.
要运行自定义构建步骤,您需要像以前一样创建一个cloudbuild.yaml文件,定义自定义构建步骤,然后添加一个构建步骤以运行deploy命令.就像这样:
To run a custom build step, you'll need to create a cloudbuild.yaml file as you did, define your custom build step and then add a build step to run the deploy command. That'd be something like this:
steps:
- name: gcr.io/cloud-builders/gsutil
args:
[
"cp",
"gs://<path to bucket>/app.yaml",
"app.yaml",
]
- name: 'gcr.io/cloud-builders/gcloud'
args: ['app', 'deploy']
然后,您将通过发出以下命令来运行构建(在运行gcloud app deploy
的目录中):
You'll then run the build by issuing the following command (in the same directory where you'd have run the gcloud app deploy
one):
gcloud builds submit --config cloudbuild.yaml .
这将:
- 将当前目录上传到Cloud Build实例
- 从CB实例上的该目录中运行gsutil命令,以检索由环境变量填充的
app.yaml
文件 - 从Cloud Build实例将代码部署到App Engine
- Upload the current directory to the Cloud Build instance
- run the gsutil command from within that directory on the CB instance to retrieve the
app.yaml
file populated with your environment variables - deploy your code to App Engine from the Cloud Build instance