Advertisement
jensens

Untitled

Jan 18th, 2022
798
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.62 KB | None | 0 0
  1. import os
  2. import yaml
  3.  
  4. # prefix all environment variables like so:
  5. # after prefix a valid cookiecutter-zope-instance key is needed
  6. PREFIX = "INSTANCE_"
  7.  
  8. # load base instance.yaml
  9. with open("instance.yaml", "r") as fio:
  10.     instance = yaml.safe_load(fio)
  11. cfg = instance["default_context"]
  12.  
  13. # set values from enviroment
  14. for envkey, value in os.environ.items():
  15.     if not envkey.startswith(PREFIX):
  16.         continue
  17.     key = envkey[len(PREFIX):].lower()
  18.     print(f"Set from env {envkey}: {key}={value}")
  19.     cfg[key] = value
  20.  
  21.  
  22. # write file
  23. with open("dockerinstance.yaml", "w") as fio:
  24.     yaml.dump(instance, fio)
  25.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement