-
Notifications
You must be signed in to change notification settings - Fork 5.2k
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
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Nice. Maybe we should support |
oh, this is just what all of us need =) any hope this will be merged soon? |
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/myapp
depends_on: [postgres]
env_file: ../env/$ENV.env
links: [postgres]
volumes:
- myapp_${ENV}_source:/source
- myapp_nginx_socks:/tmp/socks
sidekiq:
build: ../sources/myapp
command: bundle exec sidekiq -e $ENV -c 2 -q default -q carrierwave
depends_on: [postgres, redis]
env_file: ../env/$ENV.env
links: [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 |
@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. |
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. |
@dnephin Sounds good... I can definitely be up to QA this... I reallllllly need it! |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This needs to be rebased, but code LGTM
I'd still like to support |
b00a451
to
f1aec1d
Compare
Ok, rebased, added the |
Signed-off-by: Daniel Nephin <[email protected]>
f1aec1d
to
fe08be6
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
This feature was not supported previously, but was added in docker/compose#3108
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 |
@hadim Looks like a bug - do you mind creating a separate issue for it? Thank you for your help! |
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
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. |
@shin- With this config: I'm getting this error: Am I doing something wrong? |
@AlJohri please share the output of |
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
|
https://docs.docker.com/compose/compose-file/compose-file-v2/#variable-substitution Default values only with v2.1 or above. |
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.