Skip to content
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 reading config from stdin #1488

Merged
merged 1 commit into from
Jul 3, 2015
Merged

Conversation

dnephin
Copy link

@dnephin dnephin commented May 30, 2015

Related to #1377

By supporting configuration from stdin, it becomes a lot easier for users with complex templating requirements to use a separate tool for templating, and pass the final config into docker-compose directly.

I wanted to ensure that the if filename == '-' check only happened in one place, so I had to refactor some of compose.cli.command. get_config_path was moved to compose.config to support this.


def get_config_path(base_dir, file_path):
if file_path:
return os.path.join(base_dir, file_path)
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think I'd find this bit of logic less confusing if it were moved into the function above. At that point, I think the functions' responsibilities are a bit better-separated, and they could also be renamed. Say:

def resolve_config_details(base_dir, filename):
    if filename == '-':
        return ConfigDetails(yaml.safe_load(sys.stdin), os.getcwd(), None)

    if filename is None:
        file_path = find_config_file(base_dir)
    else:
        file_path = os.path.join(base_dir, filename)

    return ConfigDetails(load_yaml(file_path), os.path.dirname(file_path), file_path)


def find_config_file(base_dir):
    (candidates, path) = find_candidates_in_parent_dirs(SUPPORTED_FILENAMES, base_dir)
    # ...

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I had just copied the old get_config_path() from Command, but now that we have another place to move it, I think that makes sense.

@aanm
Copy link

aanm commented Jun 1, 2015

So it won't be possible to use a compose-file and stdin at the same time? This would be interesting when people want to overwrite stuff from compose-file without creating a new file. Such as:

$cat my-compose.yml 
web:
  ports: 1234:5000
$ docker-compose up -f my-compose.yml --stdin-extends '{web: {ports: 5000:5000}}'

Which would result in running web with ports 5000:5000 instead of 1234.
(I know the format is wrong but you get the idea ;-) )

@dnephin
Copy link
Author

dnephin commented Jun 1, 2015

@aanm that's correct, the stdin would replace the file. I think this is pretty standard for unix utilities. If you need something from a file, it would be up to you to read the original file, and merge it into the final config you send to stdin.

@aanand
Copy link

aanand commented Jun 1, 2015

@aanm What you describe is interesting (and partly covered by the extends option), but orthogonal to the idea of reading input from stdin - it'd apply just as much in the case of having two files, rather than one file + stdin.

@dnephin Come to think of it, what's the behaviour of extends in config read from stdin? Looks like it'll resolve paths relative to the current directory, but that should be documented somewhere.

@dnephin
Copy link
Author

dnephin commented Jun 1, 2015

True, I should add that with the small doc change I made about using - for file.

@aanm
Copy link

aanm commented Jun 1, 2015

@aanand I thinking that could some some users problems when they want to scale
something like:

count=0
while true;
let count=count+1
docker-compose up -f my-compose.yml --stdin-extends '{web: {ports: $count:5000}}'
do

My point is too use environment variables has input for configuration in compose. I think that would solve some problems that users are getting.

@dnephin Does docker itself has this feature that you are PR?

@aanand
Copy link

aanand commented Jun 1, 2015

@aanm For environment variable interpolation, see #1377.

@dnephin dnephin mentioned this pull request Jun 4, 2015
@aanand aanand mentioned this pull request Jun 10, 2015
@dnephin dnephin force-pushed the config_from_stdin branch 2 times, most recently from cb28737 to 4c0736e Compare June 14, 2015 20:29
@dnephin
Copy link
Author

dnephin commented Jun 14, 2015

Updated the docs, and cleaned up get_config_path()

Signed-off-by: Daniel Nephin <dnephin@gmail.com>
@dnephin
Copy link
Author

dnephin commented Jul 3, 2015

Rebased again! Should be ready

@aanand
Copy link

aanand commented Jul 3, 2015

LGTM

aanand added a commit that referenced this pull request Jul 3, 2015
Support reading config from stdin
@aanand aanand merged commit db7e512 into docker:master Jul 3, 2015
@aanand aanand removed the in progress label Jul 3, 2015
@aanand aanand added this to the 1.4.0 milestone Jul 3, 2015
@dnephin dnephin deleted the config_from_stdin branch July 3, 2015 14:23
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants