compose-spec / compose-go

Reference library for parsing and loading Compose YAML files

Home Page:https://compose-spec.io

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

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

josegonzalez opened this issue · 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?

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

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