Skip to content

Support reading config from stdin - #1488

Merged
aanand merged 1 commit into
docker:masterfrom
dnephin:config_from_stdin
Jul 3, 2015
Merged

Support reading config from stdin#1488
aanand merged 1 commit into
docker:masterfrom
dnephin:config_from_stdin

Conversation

@dnephin

Copy link
Copy Markdown

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.

Comment threadcompose/config.py Outdated

Copy link
Copy Markdown

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:

defresolve_config_details(base_dir, filename):
iffilename=='-':
returnConfigDetails(yaml.safe_load(sys.stdin), os.getcwd(), None)
iffilenameisNone:
file_path=find_config_file(base_dir)
else:
file_path=os.path.join(base_dir, filename)
returnConfigDetails(load_yaml(file_path), os.path.dirname(file_path), file_path)
deffind_config_file(base_dir):
(candidates, path) =find_candidates_in_parent_dirs(SUPPORTED_FILENAMES, base_dir)
# ...

Copy link
Copy Markdown
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

aanm commented Jun 1, 2015

Copy link
Copy Markdown

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
Copy Markdown
Author

@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
Copy Markdown

@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
Copy Markdown
Author

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

@aanm

aanm commented Jun 1, 2015

Copy link
Copy Markdown

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

count=0
whiletrue;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
Copy Markdown

@aanm For environment variable interpolation, see #1377.

@dnephindnephin mentioned this pull request Jun 4, 2015
@aanandaanand mentioned this pull request Jun 10, 2015
@dnephin
dnephinforce-pushed the config_from_stdin branch 2 times, most recently from cb28737 to 4c0736eCompareJune 14, 2015 20:29
@dnephin

Copy link
Copy Markdown
Author

Updated the docs, and cleaned up get_config_path()

@dnephindnephin mentioned this pull request Jul 3, 2015
@dnephin
dnephinforce-pushed the config_from_stdin branch from 4c0736e to 37bd76aCompareJuly 3, 2015 02:05
Signed-off-by: Daniel Nephin <dnephin@gmail.com>
@dnephin
dnephinforce-pushed the config_from_stdin branch from 37bd76a to ae96fc0CompareJuly 3, 2015 02:16
@dnephin

Copy link
Copy Markdown
Author

Rebased again! Should be ready

@aanand

Copy link
Copy Markdown

LGTM

aanand added a commit that referenced this pull request Jul 3, 2015
@aanand
aanand merged commit db7e512 into docker:masterJul 3, 2015
@aanandaanand added this to the 1.4.0 milestone Jul 3, 2015
@dnephin
dnephin deleted the config_from_stdin branch July 3, 2015 14:23
infraAnchor pushed a commit to infraAnchor/compose that referenced this pull request Mar 6, 2026
Bumps [github.com/prometheus/common](https://github.com/prometheus/common) from 0.66.1 to 0.67.2.
- [Release notes](https://github.com/prometheus/common/releases)
- [Changelog](https://github.com/prometheus/common/blob/main/CHANGELOG.md)
- [Commits](prometheus/common@v0.66.1...v0.67.2)
---
updated-dependencies:
- dependency-name: github.com/prometheus/common
dependency-version: 0.67.2
dependency-type: direct:production
update-type: version-update:semver-minor
...
Signed-off-by: dependabot[bot] <support@github.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
Sign up for freeto 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

@dnephin@aanm@aanand@GordonTheTurtle