I solved this by generating it in my custom entry point in a step like so:
./bin/python dockerinstance.py
make VENV=off VENV_FOLDER=. INSTANCE_YAML=dockerinstance.yaml instance
with dockerinstance.py a hacky script:
import os
import yaml
# prefix all environment variables like so:
# (after prefix a valid cookiecutter-zope-instance key is needed)
PREFIX = "INSTANCE_"
# load base instance.yaml
with open("instance.yaml", "r") as fio:
instance = yaml.safe_load(fio)
cfg = instance["default_context"]
# set values from enviroment
for envkey, value in os.environ.items():
if not envkey.startswith(PREFIX):
continue
key = envkey[len(PREFIX) :].lower()
print(f"Set from env {envkey}: {key}={value}")
cfg[key] = value
# write file
with open("dockerinstance.yaml", "w") as fio:
yaml.dump(instance, fio)
Then I can use environment variables in my docker swarm yaml file like so:
This is not thought all to the end, but as a rough plan something like this in an enhanced way should go into the mainline for cookiecutter-plone-starter at some point.