Merge pull request #2287 from thaJeztah/fix_quiet_push
Fix: docker push --quiet suppressing errors and exit code
This commit is contained in:
commit
e753eec764
@ -3,9 +3,11 @@ package image
|
|||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
"fmt"
|
"fmt"
|
||||||
|
"io/ioutil"
|
||||||
|
|
||||||
"github.com/docker/cli/cli"
|
"github.com/docker/cli/cli"
|
||||||
"github.com/docker/cli/cli/command"
|
"github.com/docker/cli/cli/command"
|
||||||
|
"github.com/docker/cli/cli/streams"
|
||||||
"github.com/docker/distribution/reference"
|
"github.com/docker/distribution/reference"
|
||||||
"github.com/docker/docker/pkg/jsonmessage"
|
"github.com/docker/docker/pkg/jsonmessage"
|
||||||
"github.com/docker/docker/registry"
|
"github.com/docker/docker/registry"
|
||||||
@ -68,9 +70,12 @@ func RunPush(dockerCli command.Cli, opts pushOptions) error {
|
|||||||
}
|
}
|
||||||
|
|
||||||
defer responseBody.Close()
|
defer responseBody.Close()
|
||||||
if !opts.quiet {
|
if opts.quiet {
|
||||||
return jsonmessage.DisplayJSONMessagesToStream(responseBody, dockerCli.Out(), nil)
|
err = jsonmessage.DisplayJSONMessagesToStream(responseBody, streams.NewOut(ioutil.Discard), nil)
|
||||||
|
if err == nil {
|
||||||
|
fmt.Fprintln(dockerCli.Out(), ref.String())
|
||||||
|
}
|
||||||
|
return err
|
||||||
}
|
}
|
||||||
fmt.Fprintln(dockerCli.Out(), ref.String())
|
return jsonmessage.DisplayJSONMessagesToStream(responseBody, dockerCli.Out(), nil)
|
||||||
return nil
|
|
||||||
}
|
}
|
||||||
|
@ -55,6 +55,14 @@ func TestPushWithContentTrust(t *testing.T) {
|
|||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func TestPushQuietErrors(t *testing.T) {
|
||||||
|
result := icmd.RunCmd(icmd.Command("docker", "push", "--quiet", "nosuchimage"))
|
||||||
|
result.Assert(t, icmd.Expected{
|
||||||
|
ExitCode: 1,
|
||||||
|
Err: "An image does not exist locally with the tag: nosuchimage",
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
func TestPushWithContentTrustUnreachableServer(t *testing.T) {
|
func TestPushWithContentTrustUnreachableServer(t *testing.T) {
|
||||||
skip.If(t, environment.RemoteDaemon())
|
skip.If(t, environment.RemoteDaemon())
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user