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

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

问题描述

我的CI/CD的最后一步是使用gcloud应用程序部署进行部署,但是我无法使用环境变量来提交app.yaml,因此如何使用通过环境变量传递环境变量的云构建来部署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天全站免登陆