在 Google Build 期间在 app.yaml 文件中添加环境变量

时间:2023-04-16
本文介绍了在 Google Build 期间在 app.yaml 文件中添加环境变量的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

问题描述

我正在使用带有 cloudbuild.yaml 的 Google Cloud Build 来下载一个 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 文件考虑并将您的应用与您的 unpopulated 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 文件,定义您的自定义构建步骤,然后添加一个构建步骤来运行部署命令.应该是这样的:

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

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

上一篇:如何为 Google App Engine 应用程序编写 `app.yaml` 文件? 下一篇:pyyaml:不带标签的倾销

相关文章