Add environment variable in app.yaml file during Google Build
Asked Answered
A

1

0

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.

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.

The following is my cloudbuild.yaml configuration:

steps:
 - name: gcr.io/cloud-builders/gsutil
args:
  [
    "cp",
    "gs://<path to bucket>/app.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.

If this isn't correct how else can I append environment variables to my app.yaml file?

Thanks!

Aretino answered 12/8, 2019 at 2:42 Comment(1)
Can you provide me some precision? When you use cloud build for deploying appengine, the first step is to download an environment dependant app.yaml file because it contains secrets and you can't commit them? And even if the download is in success, it don't override your existing app.yaml?Smedley
S
1

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.

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']

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 .

This will:

  • 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
Signpost answered 12/8, 2019 at 11:10 Comment(1)
Just to mention, as I tried this with a non-custom runtime, you cannot have app.yaml and cloudbuild.yaml in the same directory so if you are using a non-custom runtime you will need to move the app.yaml and other python files to a subdirectory and deploy with something like args: ["app", "deploy", "subdir/app.yaml"]Probably

© 2022 - 2024 — McMap. All rights reserved.