0

I am trying to add Cloud Build on top of my App Engine Flask app. Everything works, but for some reason, I can't access the substitution variables I declared in the trigger. Env vars are still being fetched from app.yaml. And they are parsed literally, not as variables. When I remove it from app.yaml Python throws a NoneType error.

[Trigger][1]: https://i.stack.imgur.com/Ii6Jv.png

[App.yaml][2]: https://i.stack.imgur.com/bg646.png

runtime: python310
instance_class: F4
automatic_scaling:
max_instances: 8
env_variables:
  _CONFIG_TYPE: ${_CONFIG_TYPE}

[cloudbuild][3] https://i.stack.imgur.com/jo0PN.png

steps:
- name: 'gcr.io/google.com/cloudsdktool/cloud-sdk'
  entrypoint: 'bash'
  args: ['-c', 'gcloud config set app/cloud_build_timeout 1600 && gcloud app deploy']

timeout: '1600s'
substitutions:
  _CONFIG_TYPE: ${_CONFIG_TYPE}

joachim
  • 1
  • 1

1 Answers1

0

It won't work because gcloud app deploy command start a new Cloud Build, behind the scene, to build a container with your code and to deploy it. Your env var will change anything

The solution is to perform a bash replacement, with sed for instance.

app.yaml file

runtime: python310
instance_class: F4
automatic_scaling:
max_instances: 8
env_variables:
  _CONFIG_TYPE: ##_CONFIG_TYPE##

Cloud Build Step with env var usage

steps:
- name: 'gcr.io/google.com/cloudsdktool/cloud-sdk'
  entrypoint: 'bash'
  env-vars:
   - CONFIG_TYPE: ${_CONFIG_TYPE}
  args: 
   - '-c'
   - |
      sed -i "s/##_CONFIG_TYPE##/$${CONFIG_TYPE}/g" app.yaml
      gcloud config set app/cloud_build_timeout 1600
      gcloud app deploy

timeout: '1600s'
substitutions:
  _CONFIG_TYPE: ${_CONFIG_TYPE}

Cloud Build Step without env var usage

steps:
- name: 'gcr.io/google.com/cloudsdktool/cloud-sdk'
  entrypoint: 'bash'
  args: 
   - '-c'
   - |
      sed -i "s/##_CONFIG_TYPE##/${_CONFIG_TYPE}/g" app.yaml
      gcloud config set app/cloud_build_timeout 1600
      gcloud app deploy

timeout: '1600s'
substitutions:
  _CONFIG_TYPE: ${_CONFIG_TYPE}

guillaume blaquiere
  • 66,369
  • 2
  • 47
  • 76