Allow interpolation in label/env var names when using dict syntax
ahti opened this issue · comments
Currently, interpolation in label names only works when using the array of strings syntax, i.e. this works:
...
labels:
- "traefik.http.services.${COMPOSE_PROJECT_NAME}.loadbalancer.server.port=8080"
But this doesn't:
...
labels:
traefik.http.services.${COMPOSE_PROJECT_NAME}.loadbalancer.server.port: 8080
The spec is kind of vague about whether the second variation should work. It says "Values in a Compose file can be set by variables, and interpolated at runtime". Taken literally, keys to a dictionary aren't quite values. On the other hand, the keys in labels and env variables are used-defined content and not like the "normal" static keys for compose properties either.
Either way, since it is clearly useful to allow this (for labels and env variables at least) and one variation works already, I think it would be good for consistency if the other variation worked as well.
While not explicitly set by the specification, variable substitution only applies to VALUES, not yaml mapping KEYS.
Not doing so would introduce risks for duplicate keys after interpolation, which yaml parser should have detected already.
For environment variables/labels use-cases, the "list of string" syntax offers a pretty reasonable workaround, so the benefit vs risk changing this is pretty low.