Files
zulip/tools/circleci/generate-dockerfiles
Greg Price f995ad1ed5 circleci: Simplify Dockerfile templating a bit.
Injecting the generated-file warning into the settings dict felt a
little unnecessarily magical.  A warning like this is always going
to be at the top; the way it might differ between files is mainly
if the syntax for a comment varies, and in that case a simple
substitution like we're doing in this template wouldn't be enough
to express the difference anyway.  So, embrace the hardcoding.

Now, the template and the images.yml entry have a very simple
relationship: the keys in one are exactly the keys in the other.
That's good for people quickly and confidently understanding it.
2018-01-31 10:53:13 -08:00

26 lines
713 B
Python
Executable File

#!/usr/bin/env python3
import os
import yaml
if __name__ == "__main__":
os.chdir(os.path.abspath(os.path.dirname(__file__)))
with open("Dockerfile.template") as f:
docker_template = f.read()
with open("images.yml") as f:
dockerfile_settings = yaml.safe_load(f)
for distro in dockerfile_settings:
dockerfile_path = "images/{}/Dockerfile".format(distro)
os.makedirs(os.path.dirname(dockerfile_path), exist_ok=True)
with open(dockerfile_path, "w") as f:
f.write("""\
# THIS IS A GENERATED FILE. DO NOT EDIT.
# See template: tools/circleci/Dockerfile.template
""")
f.write(docker_template.format_map(dockerfile_settings[distro]))