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 --compose-file - as stdin #347

Merged
merged 1 commit into from
Aug 22, 2017
Merged

Conversation

mmariani
Copy link
Contributor

As discussed in moby/moby#34036

@codecov-io
Copy link

codecov-io commented Jul 18, 2017

Codecov Report

Merging #347 into master will increase coverage by 0.01%.
The diff coverage is 70.83%.

@@            Coverage Diff             @@
##           master     #347      +/-   ##
==========================================
+ Coverage   47.02%   47.04%   +0.01%     
==========================================
  Files         198      198              
  Lines       16336    16349      +13     
==========================================
+ Hits         7682     7691       +9     
- Misses       8260     8263       +3     
- Partials      394      395       +1

@mmariani
Copy link
Contributor Author

I would have added a test but I'm pretty new at go and don't see a clean way to mock /dev/stdin.

Copy link
Contributor

@dnephin dnephin left a comment

Choose a reason for hiding this comment

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

Thanks! this is a good start

@@ -57,6 +57,8 @@ Creating service vossibility_ghollector
Creating service vossibility_lookupd
```

The Compose file can also be provided as standard input with `--compose-file -`.
Copy link
Contributor

Choose a reason for hiding this comment

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

I think this would be better in the help text for the --compose-file flag. Something like

Path to a Compose file, use "-" to read from stdin

Copy link
Contributor

Choose a reason for hiding this comment

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

I agree, then it doesn't need to be specifically dealt with in the reference file at all, unless you wanted to add an example (which would probably be good to have).

if err != nil {
return details, err
if composefile == "-" && runtime.GOOS != "windows" {
composefile = "/dev/stdin"
Copy link
Contributor

Choose a reason for hiding this comment

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

I think we can make this easier to test, and supported on windows.

Instead of setting composefile = "/dev/stdin" here, only set WorkingDir.

You'll also need to pass dockerCli.In() as an io.Reader from deployCompose() where this is called, so we have access to it in getConfigFile().

In getConfigFile before calling ioutil.ReadFile() check if filename == "-" and use this instead to get the bytes:

bytes, err = ioutil.ReadAll(stdin)

@mmariani
Copy link
Contributor Author

this one should do, thanks

@@ -150,15 +159,24 @@ func buildEnvironment(env []string) (map[string]string, error) {
return result, nil
}

func getConfigFile(filename string) (*composetypes.ConfigFile, error) {
bytes, err := ioutil.ReadFile(filename)
func getConfigFile(filename string, stdin io.Reader) (*composetypes.ConfigFile, error) {
Copy link
Member

Choose a reason for hiding this comment

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

Wondering if this should just take an io.Reader in both cases @dnephin wdyt?

Copy link
Contributor

Choose a reason for hiding this comment

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

Ya, that sounds like a good idea

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I did not do that, because it needs the filename in the return.

Copy link
Member

Choose a reason for hiding this comment

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

Ah, I see; yes, we may have to refactor some things. None of these are exported functions, so I guess we can do that in a follow up.

@@ -57,6 +57,8 @@ Creating service vossibility_ghollector
Creating service vossibility_lookupd
```

The Compose file can also be provided as standard input with `--compose-file -`.
Copy link
Contributor

Choose a reason for hiding this comment

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

I agree, then it doesn't need to be specifically dealt with in the reference file at all, unless you wanted to add an example (which would probably be good to have).

@docker docker deleted a comment from GordonTheTurtle Aug 1, 2017
Copy link
Member

@thaJeztah thaJeztah left a comment

Choose a reason for hiding this comment

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

one nit, but LGTM otherwise; can you squash your commits? I think it's ok to keep the docs and code changes in the same commit

version: "3.0"
services:
foo:
image: alpine:3.5
Copy link
Member

Choose a reason for hiding this comment

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

Looks like the indentation got lost here. We're not testing if the content is actually parsed, so won't make a difference (currently); I see the other test also doesn't do this, but wondering if we should, e.g.;

diff --git a/cli/command/stack/deploy_composefile_test.go b/cli/command/stack/deploy_composefile_test.go
index 90d866a2..6e2a1f2c 100644
--- a/cli/command/stack/deploy_composefile_test.go
+++ b/cli/command/stack/deploy_composefile_test.go
@@ -37,15 +37,16 @@ func TestGetConfigDetailsStdin(t *testing.T) {
        content := `
 version: "3.0"
 services:
-foo:
-image: alpine:3.5
+  foo:
+    image: alpine:3.5
 `
        details, err := getConfigDetails("-", strings.NewReader(content))
        require.NoError(t, err)
        cwd, err := os.Getwd()
        require.NoError(t, err)
        assert.Equal(t, cwd, details.WorkingDir)
-       assert.Len(t, details.ConfigFiles, 1)
+       require.Len(t, details.ConfigFiles, 1)
+       assert.Equal(t, "3.0", details.ConfigFiles[0].Config["version"])
        assert.Len(t, details.Environment, len(os.Environ()))
 }

Copy link
Collaborator

@vdemeester vdemeester left a comment

Choose a reason for hiding this comment

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

SGTM
@mmariani can you take care of @thaJeztah's comment (and squash your commits) ? 👼

@mmariani mmariani force-pushed the stdin branch 3 times, most recently from c86c765 to ac16f26 Compare August 22, 2017 15:54
Signed-off-by: Marco Mariani <marco.mariani@alterway.fr>
@mmariani
Copy link
Contributor Author

done, thanks for reminding. also updated to master

Copy link
Contributor

@dnephin dnephin left a comment

Choose a reason for hiding this comment

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

LGTM

@dnephin dnephin merged commit 0d17ea2 into docker:master Aug 22, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

7 participants