Commit 6a0fc9ed authored by eric pellegrini's avatar eric pellegrini
Browse files

merged the parameters within environment one

parent 3dcceca0
......@@ -27,7 +27,9 @@ class PackerTemplate:
self._packages_base_dir = packages_base_dir
self._templates_base_dir = templates_base_dir
self._parameters = yaml_node.get("parameters", {})
environment_file = os.path.join(self._templates_base_dir,self._name,"environment.yml")
# Fetch the 'packer' node
packer_node = yaml_node.get("packer", {})
......@@ -55,6 +57,25 @@ class PackerTemplate:
def _read_environment_file(self, environment_file):
"""Read YAML environemnt file and populate os.environ
environment_file: str
Path to the environment file.
if not os.path.exists(environment_file):
self._environment = {}
with open(environment_file, "r") as fin:
env = yaml.safe_load(fin)
for k,v in env.get("environment",{}).items():
self._environment[k] = str(v)
def _update_builder(self, builder: Dict[str,str]):
"""Update some fields of a builder.
......@@ -115,15 +136,6 @@ class PackerTemplate:
return self._name
def parameters(self) -> dict:
"""Returns the parameters of this :class:`PackerTemplate`.
This dictionary will be applied to Jinja 2 templates when creating the manifest json file.
return self._parameters
def postprocessors(self) -> list:
"""Returns the postprocessors of this :class:`PackerTemplate`.
......@@ -258,8 +270,7 @@ class PackerTemplate:
# Render the jinja2 templates with the parameters dictionary provided in the template file and the available environment variables
jinja_template = jinja2.Template(repr(node))
s = jinja_template.render(parameters=self._parameters, environment=os.environ)
s = jinja_template.render(environment=self._environment)
# Dump to the output file
with open(output_file, "w") as fout:
json.dump(yaml.safe_load(s), fout, **kwargs)
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment