App Engine: different app.yaml files based on environment

后端 未结 3 882
我寻月下人不归
我寻月下人不归 2021-02-20 08:48

I am currently migrating an application to Google App Engine that relies on environment variables for various external connections. It looks like the app.yaml file is where I s

相关标签:
3条回答
  • 2021-02-20 09:00

    I needed a solution for this that would work with a CD pipeline. I use Build Triggers on my git repositories. Using these, I can template the branch name I'm launching from into my cloudbuild.yaml file. My first build step is then to generate app.yaml from a shell script using the branch_name as a conditional value.

    # cloudbuild.yaml
    - name: 'ubuntu'
      args: ['bash', 'app.yaml.sh', '$BRANCH_NAME']
    
    0 讨论(0)
  • 2021-02-20 09:04

    app.yaml can set environment variables for the rest of the application, but it has no way to check them and do different things depending on their incoming values. Thus, you do need to present different app.yaml files to whatever deployment procedure you're using.

    As for the best way to prepare the right app.yaml as a preliminary step to GAE deployment, that's a subtler devops problem. Branches in your git or hg or whatever, as you mention, would work, but personally (maybe just bad luck?-) I've often found that the simpler my structure, the better, and branches intended to be long-lived (as opposed to temporary deviation intended to be soon merged back into the trunk) have given me the worse headaches.

    So, were it up to me, I'd have a preapp.yaml template (maybe jinja2, whatever) with the needed if/else logic, and prepare the right app.yaml from it, as the very first step of any deployment, with a simple Python script.

    Pretty much the kind of architecture used (for all kind of configuration files, and thus with more inevitable complications) for the currently-beta gcloud preview deployment-manager, see https://cloud.google.com/deployment-manager/ , so of course I could be biased towards the approach (but as I mentioned my bias comes essentially from previous bad deployment experiences:-).

    0 讨论(0)
  • 2021-02-20 09:21

    I just came across this issue for the same reason. I ended up creating aliases for each dev, and prod:

    alias dev-deploy='cat dev.yaml > app.yaml; gcloud app deploy dev.yaml; rm app.yaml'
    alias prod-deploy='cat prod.yaml > app.yaml; gcloud app deploy; rm app.yaml'
    
    0 讨论(0)
提交回复
热议问题