在Google Build期间在app.yaml文件中添加环境变量 [英] Add environment variable in app.yaml file during Google Build

查看:90
本文介绍了在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

这篇关于在Google Build期间在app.yaml文件中添加环境变量的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆