feat: add variable interpolation in compose files#37
feat: add variable interpolation in compose files#37ganthern wants to merge 8 commits intok9withabone:mainfrom
Conversation
38bf45e to
9094470
Compare
Introduce the `Options::interpolate_vars()`
function to add name-value mappings that will be
used to replace variable placeholders in YAML
strings when `Compose` is constructed.
The behavior is unchanged if no variables are
given: strings containing placeholders are used
as-is and may lead to errors if they don't pass
validation (which is likely, since they'll contain
constructs like
`${FOO:-${BAR?missing foo & bar}}`
).
If any variables are given to `Options`, the
parser will be invoked and attempt to replace all
of the variables in the YAML source and throw an
error if it is unable to.
|
This is huge — this could be the step to migrating these massive self-hosted softwares (Immich, Nextcloud, Seafile, etc.) — and any homelab setup — from Docker compose to Podman Systemd. The code is mostly LGTM:
Just one problem: How do we escape a |
|
Yes, this is very needed because nowadays docker-compose is the usual choice for packaging complex software like this. In fact I would like to see podlet integrated with systemd in the same way quadlet is. So that one can adjust Hope somebody from the project can review this. |
|
Hello 👋
Thanks! Also thank you for the review (I completely agree with it) and the bug fix.
I could swear I thought about this (and/or checked against docker-compose) when I implemented this, but I'll do it again once I find the time and write it down this time. It's been a while :)
Thank you as well! Interesting thought, I didn't even consider keeping the docker-compose around. Probably because I'm not hosting many apps yet. |
- allow literal_string_with_formatting_args in interpolation test code - fix warning due to missing backticks
|
I had a look at escaping
I'd guess it would make most sense to adopt backslash escapes as the most familiar I haven't thought much about how that would interact with YAML escapes. |
Hey there 👋
I thought I'd take a crack at #3. My use case:
I wanted to install Immich in my homelab, which recommends the compose file method at the link. My lab uses quadlet files. Immich consists of several containers and uses variables for configuration in the compose file, which I was too lazy to convert by hand.
podletis almost there to do it automatically, but doesn't support interpolation becausecompose_spec_rsdoesn't (PR to podlet is incoming once/if this is accepted).Notes
nom,combineorpest.docker-composeorpodman-compose. I'm also not sure what the best way to go about this would be. It's likely there are differences in how whitespace is handled and maybe more.Intended usage
I was hoping to extend podlet to achieve a usage like
which is to say it's possible to replace variables given in one or multiple
.envfiles and the actual environment (--env -); with later sources overwriting earlier ones.So, there it is. Waiting for reviews and any guidance to get this merged!