-
Notifications
You must be signed in to change notification settings - Fork 14
WIP Initial support for parametrization of descriptor files #116
base: master
Are you sure you want to change the base?
Conversation
This looks pretty good. I think it would also be beneficial to be able to specify these through a properties file. Using a file that's committed with the image.yaml, would provide a place where all the "externals" could be defined, so folks wanting to override some or all know what's been parameterized (e.g. properties section of a pom). I think supporting both command line options and properties file is good, with the options taking precedent over what's in any file. For something like community vs product images, there could be a centos.properties and a rhel.properties. Organizing in this way means the image.yaml contains all the structural elements of the image (scripts, artifacts, etc.), while the properties files identify the specifics (which artifacts, which base image, etc.). |
I think I'm ok with adding support for properties file. Stay tuned. |
This seems weird to me dogen is based on jinja templates - so why second layer of parametrization? |
k, v = param.split("=", 1) | ||
params[k] = v | ||
|
||
args.params = params |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this is very hacky - you should not mess with args object and store your values here.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Right. I guess the problem is that argparse doesn't support a dict directly. I could leave validation and just pass what I've got via CLI, but I guess I wanted to have the validation as close as possible to where argparse does it. I'm open for suggestions.
self.cfg = yaml.safe_load(stream) | ||
content = stream.read() | ||
|
||
for k, v in six.iteritems(self.params): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
in python 2.7 we don need six for this. do we support python 2.6 and so?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We don't support 2.6.
|
||
generator = Generator(self.log, self.args) | ||
generator.configure() | ||
generator.render_from_template() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this code is copy pasted multiple times maybe it should be extracted to common setUp method
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Probably a good idea, yes.
@l-d-j Let's leave it here for a bit. We will see if supporting something like this is a good idea. We need some real use cases so we can make the correct decision. Until then this won't be merged. I'm happy to a discussion about this when we have some more information. |
@goldmann +1 on tracking it and discussing it here. I still think we should look at jinja inheritance and include statements and try to solve via jinja. |
Here are some "real" use cases that we've received from teams migrating to dogen:
As stated above, the yaml describes the basic structure and content of the image and the parameters allow for substitution of minor details. From a maintenance perspective, e.g. updating artifact versions, this would entail a change to the properties file, without having to change the yaml itself. With respect to managing a template for this kind of stuff, I'd start to wonder why I'm using this over just managing a Dockerfile directly. I know docker; now I need to learn dogen and jinja. The templates raise another issue in that, since we are using dogen to generate the Dockerfile, it means that the version of dogen needs to be specific to the version of the source in order to maintain repeatability of builds. |
@rcernich Regarding first use case - you can take a look at this idea: #117 (comment). Additional requirements are:
|
Related to #104.
Consider following descriptor file:
If you execute dogen with this new argument:
dogen will generate this Dockerfile:
If it is run without the
--param
switch it uses default values: