Skip to content
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

Mechanism for override file to **remove** element #284

Closed
ndeloof opened this issue Dec 1, 2022 · 4 comments
Closed

Mechanism for override file to **remove** element #284

ndeloof opened this issue Dec 1, 2022 · 4 comments

Comments

@ndeloof
Copy link
Collaborator

ndeloof commented Dec 1, 2022

What is the problem you're trying to solve
compose.yaml can be merged to override attributes, but there's no way to REMOVE an element

Describe the solution you'd like
Some way for user to explicitly define an key to REMOVE element in overridden compose model

An interesting proposal is to rely on yaml null syntax:

services:
  app:
    ports: ~

Using this, whenever the base compose file might define ports for app service, the merged model with such an explicit null attribute will have no port set.

@milas
Copy link
Member

milas commented Dec 1, 2022

For ShellCommand in compose-go, we ran into something sorta similar to this - if you wanted to clear the command set via CMD (or ENTRYPOINT) in the Dockerfile, it'd get lost during marshaling.

It now distinguishes between [] and nil, which is annoying in the Go code, but works. See compose-spec/compose-go#298.

I'm mentioning because it's almost the exact opposite semantically - if the user specifies [], we'll use that value, but if they provide null (either explicitly or implicitly by not setting the field), we ignore it.

We COULD do something similar for merging such that ports: [] overrides and "clears".

@milas
Copy link
Member

milas commented Dec 1, 2022

I wonder if during merging we need to have the original project in map[string]interface{} format handy and a helper like isFieldDefined("services.foo.ports") so we can only consider explicitly set fields.

@ndeloof
Copy link
Collaborator Author

ndeloof commented Dec 2, 2022

also see docker/compose#8699

@ndeloof
Copy link
Collaborator Author

ndeloof commented Dec 2, 2022

This indeed will require compose-go to distinguish a field being set to default value vs an explicit null assignment. We could manage this before yaml model is mapped to go structs, as a map[string]interface{} tree.
Anyway, proposal here is more to collect feedback on syntax and document this behavior

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants