Advertisement
jensens

Untitled

Jan 18th, 2022
551
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  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
Advertisement
Advertisement
RAW Paste Data Copied
Advertisement