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

Add option to keep empty environment variable keys in normalization

Open edwardrf opened this issue 1 year ago • 4 comments

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.

edwardrf avatar May 31 '24 20:05 edwardrf

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 ?

ndeloof avatar Jun 01 '24 05:06 ndeloof

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 avatar Jun 03 '24 18:06 edwardrf

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

edwardrf avatar Jun 19 '24 17:06 edwardrf

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 avatar Jul 04 '24 06:07 ndeloof

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

ndeloof avatar Jul 08 '24 12:07 ndeloof

Thank you!

edwardrf avatar Jul 08 '24 17:07 edwardrf