-
Notifications
You must be signed in to change notification settings - Fork 18
Compose files templating improvements #122
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Conversation
Global values can also be written directly in config.yaml This makes behavior uniform across repos and stacks configuration
|
@m-adawi @sanzoghenzo Hey guys, is there anything I can do to make this progress forward ? Like, a companion PR on swarm-cd-example or something like that ? |
|
Hi @tgaugry, sorry for the delay! I still have to finish the review, but I kindly ask you to add a documentation of the new features in the readme file, so that I can better understand the choices you made in your edits. |
sanzoghenzo
left a comment
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.
OK, I think I understand your changes.
I don't use the WEB UI, so to me it is a bit much having to manage a "cache" directory (doesn't seem like a cache since it is recreated at each update without checking if anything changed - but that's just semantic and I get what you wanted to do 😉 ) and perform I/O operations just to be able to download the rendered compose file.
I'll leave to @m-adawi to decide, but couldn't this be turned into an on-demand API?
|
TBH, I don't use the web ui much either, but I think having a way to debug and compare template vs generated file is necessary. I agree that recreating everything each time is a bit silly - other than the disk io, it also hit registries which is a bit annoying. I wanted to also do a PR about that, but I just couldn't find the time. To me there is 3 alternatives:
To me the most feasible option is 2 - that way files can be checked either in the UI, or by mounting a volume. Any opinion @sanzoghenzo ? |
I agree, the output it useful when testing out new templates!
This would be a good compromise to have this PR merged quickly
No need to merge parts, just add a route for This can also be used without the web UI (via I'm fine with either solution, maybe we can do 2 and when you (or anyone else that wants to contribute) have more time you can try 3? |
I was thinking about this just today, I would like to test a templated stack locally without the need to spin up a swarmCD instance... I'm not saying that you need to do that 😅 , it's just a thought... I'll make this into an issue ASAP! |
|
I tinkered a bit yesterday, and you were right, solution 3 is not that complex - I was tricked by the function export rules from go (starting with an upper case letter vs not).
Honestly, with solution 3 I feel like a good chunk of the work is done for that. I'll go that route, and I'll see if I can find the time for #127 |
|
That should do the trick:
Current code is running on my setup, this is what I get in the UI: This is what you get when you have a bad template (intentionally removed "}}"): $ docker run -e LOG_LEVEL=debug -v $(pwd)/testdata:/data --rm -it swarm-cd:latest /app/template-gen --global /data/globals.yaml --valuefile /data/values.yml --templatefolder /data/template /data/compose_notemplate.yml
time=2025-10-26T12:32:36.435Z level=DEBUG msg="reading stack file..." stack="Template test" branch=nobranch
time=2025-10-26T12:32:36.435Z level=DEBUG msg="rendering template..." stack="Template test" branch=nobranch
time=2025-10-26T12:32:36.435Z level=DEBUG msg="Loading template folder..." stack="Template test" branch=nobranch
time=2025-10-26T12:32:36.435Z level=ERROR msg="Could not parse templates, trying to generate stack without them." stack="Template test" branch=nobranch error="template: volumes.tmpl:3: unexpected \"{\" in define clause"
---
version: '3.8'
services:
traefik:
image: traefik:v3.5
[SNIP] |
|
Looks good to me! I still didn't test it, though. @m-adawi have you any thought about this PR? should I proceed with the merge or do you want to try it first? |
|
Great, thanks for your time @sanzoghenzo ! For what it's worth, this is what I run currently in my homelab - haven't seen any weird behavior. Still, a second test would be nice. |

This PR add a few things related to compose file templating (see #19).
This adds :
A way to have common values for all stacks, instead of specifying the same variable over and over in each stack values_file. These can be specified either in the "global_values" field in config.yaml, or in a file named global.yaml (same behavior as the "stacks" variable. They can be overriden in stack values_file, if needs be.
You can now use sprig functions in compose.
You can use go templates defined in the "template" folder.
The web UI now shows original and generated files (if available)