-
Notifications
You must be signed in to change notification settings - Fork 1.9k
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
Conversation
Codecov Report
@@ 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 |
I would have added a test but I'm pretty new at go and don't see a clean way to mock /dev/stdin. |
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.
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 -`. |
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.
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
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.
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" |
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.
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)
dcc15b8
to
72662e6
Compare
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) { |
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.
Wondering if this should just take an io.Reader
in both cases @dnephin wdyt?
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.
Ya, that sounds like a good idea
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.
I did not do that, because it needs the filename in the return.
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.
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 -`. |
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.
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).
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.
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 |
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.
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()))
}
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.
SGTM
@mmariani can you take care of @thaJeztah's comment (and squash your commits) ? 👼
c86c765
to
ac16f26
Compare
Signed-off-by: Marco Mariani <marco.mariani@alterway.fr>
done, thanks for reminding. also updated to master |
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
As discussed in moby/moby#34036