compose-go icon indicating copy to clipboard operation
compose-go copied to clipboard

Is there a way to marshal a golang compose project back into yaml?

Open josegonzalez opened this issue 3 years ago • 1 comments

I'd like to use this project to pre-process a compose file - basically inject some labels, verify configuration, etc. - before marshalling it back to yaml for use by docker compose. Is there a way to do that with compose-go?

josegonzalez avatar Apr 09 '22 18:04 josegonzalez

sure, you can use cli.ProjectFromOptions to load compose file(s) and interpolate variables, make changes to the compose model, then just use yaml.Mashall to get it back into a plain yaml tree

ndeloof avatar Apr 29 '22 13:04 ndeloof

See above. Additionally, here's a snippet docker/compose where it does exactly this: https://github.com/docker/compose/blob/a95cc4074a38a65c02e349ef284a9a4f28e2a0cc/pkg/compose/compose.go#L95-L104

milas avatar Sep 26 '22 16:09 milas