-
Notifications
You must be signed in to change notification settings - Fork 65
Ability to use variables in Linuxkit configuration? #163
Comments
This has come up before, and it is still unclear what the best answer is and we don't really want to commit to a templating system too early. For many use cases, you can use Yaml aliases. For example the bit below reuses the capabilities between two services:
I am not sure you can template strings with aliases in yaml though. You may be better off just using a file from the host, you can do
and just put the right IPs in on the host. |
You can also put just the dynamic bit in a separate file which you generate at build time (using whatever you would have used to set the variables) and then do |
I didn't find the previous discussions about that (that's why I opened a new issue).
YAML value aliases are good but as you mentioned string concatenation is not possible.
That's a good idea, but unfortunately my configuration is spread across Another solution that came to my mind is to use a custom metadata server (kinda like with AWS or GCP platforms) and write configuration at runtime. This will slowdown the overall boot time and I would be forced to have an dedicated and available IP/service everywhere. It's not really practical. What do you think about a new tool to generate a templated config? So that we don't integrate it to the core and you can just stop maintaining at some point if it turns out to be a bad idea. |
I'm not sure if you are adding or modify services, but to clarify, you can add entirely new services in the second/third yaml file, you just can't (easily) change the properties of a service defined in one yml file using a later (in moby command line order) file. The
Maybe
By coincidence I was looking for a YML equivalent of Perhaps it could provide the level of external templating needed? |
Sorry I meant modifying existing services, I could re-declare them in each additional file but it will be tedious to manage later. The metadata based on a file is not dynamic enough for me. Part of the issue is that in my case I will end up with one additional config file per machine, as I said before it would be tedious to manage. I will give yq a try, thanks. I will let you know. |
@ijc yq does only help you navigate in the YAML as an object. I cannot really implement a templating engine. I ended up implementing a metadata server (very similar to the AWS one). It's currently written in Bash and lives in its own image. I still have some configuration duplicated in the file but it's manageable. |
I have previously used https://github.com/wrouesnel/p2cli Then having rewritten the bash scripts to Python, I've switched to Jinja2 which is very similar but more complete. |
Should be moved to linuxkit repo. |
This is a feature request.
It would be great to have a variable system in the Linuxkit configuration file.
Of course an alternative is to use
sed
before building the image but I don't want to do that.- Use case
My VM is in a custom network where
1.2.3.4
is the ip of my host. As you can see in my example, a DNS server and a Docker registry are bind to that ip.linuxkit.yml:
My idea is to use a
variables
orargs
key in the configuration and then be able to reference them, like in the following example:linuxkit.yml:
Technically it could be a first pass during configuration parsing to "search and replace" these pattern. Another solution would be to replace them as you need to use the values but that would add unnecessary to every piece of the codebase.
If you don't want the replacement, you should be able to escape by adding a backslash before:
\${hostip}
.Edit:
i'm using a Docker daemon to be able to start arbitrary images dynamically in the VM. Not a weird hack.
- A picture of a cute animal (not mandatory but encouraged)
The text was updated successfully, but these errors were encountered: