如何使用云构建将环境变量传递给 app.yaml [英] How to pass environment variables to the app.yaml using cloud build

查看:19
本文介绍了如何使用云构建将环境变量传递给 app.yaml的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的 CI/CD 的最后一步是使用 gcloud app deploy 进行部署,但我无法使用我的环境变量提交 app.yaml,因此如何使用传递 env 变量的 cloud build 进行部署,请执行 app.yaml?

The final step of my CI/CD is the deployment using gcloud app deploy, but I can't commit the app.yaml with my environment variables, so how to deploy using cloud build passing the env variables do the app.yaml?

这是我的 cloudbuild.yaml

Here is my cloudbuild.yaml

steps:
- name: "gcr.io/cloud-builders/gcloud"
  args: ["app", "deploy"]
timeout: "1800s"

推荐答案

一个简单的选择是将您的环境变量列在 Cloud Storage 的文件(甚至 app.yaml 文件本身)中.然后您可以使用 cloud-builders/gsutil 在像这样的构建步骤:

One easy option is to have your environment variables listed in a file (or even the app.yaml file itself) in Cloud Storage. You can then use the cloud-builders/gsutil to retrieve this file in a build step like this:

steps:
- name: gcr.io/cloud-builders/gsutil
  args: ['cp', 'gs://mybucket/env_vars.txt', 'env_vars.txt']

这会将文件复制到/workspace 目录.然后,下一个构建步骤可以使用环境变量填充 app.yaml 文件(或者甚至只是将检索到的 app.yaml 文件复制到正确的路径).下一步也是最后一步是您提到的部署应用程序的步骤.

This will copy the file to the /workspace directory. The next build step can then populate the app.yaml file with the environment variables (or even just copy the retrieved app.yaml file to the correct path). The next and final step would the one you mentioned to deploy the app.

请注意,在 Cloud Build 环境中执行时,命令是使用 凭据执行的项目的构建器服务帐户.您需要向该服务帐号授予对 Cloud Storage 上文件的访问权限.

Note that, when executed in the Cloud Build environment, commands are executed with credentials of the builder service account for the project. You'll need to grant access to the file on Cloud Storage to that service account.

这篇关于如何使用云构建将环境变量传递给 app.yaml的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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