Uh oh!
There was an error while loading. Please reload this page.
Support inline default values for interpolation - #3108
Conversation
| if named is not None: | ||
| if ':-' in named: | ||
| var, _, default = named.partition(':-') | ||
| return mapping.get(var, default) |
There was a problem hiding this comment.
These 3 lines are the only real substantial modifications.
I also cut out the arg/kwarg handling and just replaced it with a mapping arg, since that's how we use it.
aanand
commented
Mar 15, 2016
Nice. Maybe we should support |
dreyks
commented
Apr 1, 2016
oh, this is just what all of us need =) any hope this will be merged soon? |
marcellodesales
commented
Sep 18, 2016
What about using environment variables in key names? Like in: version: '2'services:
postgres: {image: 'postgres:9.6'}redis: {image: 'redis:3.2.3'}web_server:
build: ../sources/myappdepends_on: [postgres]env_file: ../env/$ENV.envlinks: [postgres]volumes:
- myapp_${ENV}_source:/source
- myapp_nginx_socks:/tmp/sockssidekiq:
build: ../sources/myappcommand: bundle exec sidekiq -e $ENV -c 2 -q default -q carrierwavedepends_on: [postgres, redis]env_file: ../env/$ENV.envlinks: [postgres, redis]volumes_from: [web_server]volumes:
myapp_${ENV}_db: {external: true}myapp_${ENV}_source: {external: true}myapp_nginx_socks: {external: true}For values it seems to be working right, but for keys it throws a syntax error:
BTW, is this on latest version? I'm getting variables interpolated with a fresh installed $ docker-compose -v
docker-compose version 1.8.0, build f3628c7 |
dnephin
commented
Sep 19, 2016
@marcellodesales I think we're going to try and get this into the next release for the v2.1 file format. #3653 adds the v2.1 file format, so once that is merged I can rebase this and change it to only apply to the new format. |
dnephin
commented
Sep 19, 2016
Variables are not support in keys. Generally I think this is a bad idea, it leads to a lot of extra complexity. In your case (and in just about every case so far where this has been requested), it is better to use the The discussion of variables in keys is not really relevant to this PR, so please open a new issue if you feel this is a necessary addition. |
marcellodesales
commented
Sep 26, 2016
@dnephin Sounds good... I can definitely be up to QA this... I reallllllly need it! |
shin-
left a comment
There was a problem hiding this comment.
This needs to be rebased, but code LGTM
aanand
commented
Sep 29, 2016
I'd still like to support |
b00a451 to
f1aec1dComparednephin
commented
Sep 29, 2016
Ok, rebased, added the |
Signed-off-by: Daniel Nephin <dnephin@docker.com>
f1aec1d to
fe08be6CompareThis feature was not supported previously, but was added in docker/compose#3108
hadim
commented
Oct 5, 2016
Nice addition guys ! I am testing it at the moment the master git code and docker-engine 1.12 and it seems to work great except for volumes defaut values : I get the following error : Am I missing something or is that a bug ? Thanks |
shin-
commented
Oct 5, 2016
@hadim Looks like a bug - do you mind creating a separate issue for it? Thank you for your help! |
hadim
commented
Oct 5, 2016
Sure. |
This feature was not supported previously, but was added in docker/compose#3108
This feature was not supported previously, but was added in docker/compose#3108
glensc
commented
Oct 20, 2016
i proposed new syntax for 2.1 here: that shouldn't add complexity as keys can be still not interpolated and makes syntax more similar to other definitions. |
AlJohri
commented
Aug 9, 2017
@shin- With this config: I'm getting this error: Am I doing something wrong? |
shin-
commented
Aug 9, 2017
@AlJohri please share the output of |
tmack8001
commented
Oct 8, 2018
I also get this same issue where defaults aren't supported... and my docker-compose version is the latest non release candidate, 1.22.0. I'm trying to add an environment variable and default into the "docker_host" of the image. but I get the following error while executing |
shin-
commented
Oct 8, 2018
https://docs.docker.com/compose/compose-file/compose-file-v2/#variable-substitution Default values only with v2.1 or above. |
tmack8001
commented
Oct 8, 2018
ah thanks @shin- 👍 I was still referring to v2 🤕 |
Implements part of #2441 to support inline default values.
I have no idea how robust this is, but it's a start.