compose-spec / compose-go

Reference library for parsing and loading Compose YAML files
https://compose-spec.io
Apache License 2.0
350 stars 109 forks source link

Add option to keep empty environment variable keys in normalization #634

Closed edwardrf closed 2 months ago

edwardrf commented 3 months ago

In #589, the normalisation logic strips off any environment variables that does not have a value in config, however, i my use case, I am still interested in any empty environment variables names that has been set, which i'll resolve the value at a later stage, so I am implementing an naive option to allow me keep them during normalisation, please let me know if there is a better way of doing it. Currently, I have to load the project twice, use the one without normalisation to detect those empty environment variables.

ndeloof commented 3 months ago

please clarify your use case. a key-only environment variable is resolved based on user's environment, and ignored otherwise. Why not just populate the project environment with all usable values ?

edwardrf commented 3 months ago

We use the key-only environment variable in 2 ways:

  1. Validation and suggestion: in our tool, we provide warning and suggestions to the user if there are anything in their compose file could be a mistake.
  2. Supply values when needed: our tool will figure out an external source for the value to be supplied at deployment time based on the users need.

The current behaviour of silently dropping them prevented us from doing either. An alternative solution is to return the dropped keys via a different way, like another return value or structured warning message.

edwardrf commented 2 months ago

Any suggestions? I am open to an alternative approach if there is a recommendation.

ndeloof commented 2 months ago

Actually this is a bug to remove empty variable from container environment, as empty has a special meaning to "remove" variable (see https://github.com/docker/compose/issues/11962)

ndeloof commented 2 months ago

Closing as https://github.com/compose-spec/compose-go/pull/654 has been merged

edwardrf commented 2 months ago

Thank you!