Skip to content
This repository has been archived by the owner on Apr 25, 2023. It is now read-only.

Commit

Permalink
Ping docker server before running
Browse files Browse the repository at this point in the history
  • Loading branch information
Yuriy Bogdanov committed Oct 7, 2015
1 parent 9371ae9 commit eafb0ef
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 7 deletions.
5 changes: 5 additions & 0 deletions src/cmd/rocker-compose/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -555,6 +555,11 @@ func initComposeConfig(ctx *cli.Context, dockerCli *docker.Client) *config.Confi
log.Fatal(err)
}

// Check the docker connection before we actually run
if err := dockerclient.Ping(dockerCli, 5000); err != nil {
log.Fatal(err)
}

return manifest
}

Expand Down
14 changes: 7 additions & 7 deletions vendor/manifest
Original file line number Diff line number Diff line change
Expand Up @@ -85,13 +85,6 @@
"branch": "master",
"path": "/src/rocker/test"
},
{
"importpath": "github.com/grammarly/rocker/src/rocker/dockerclient",
"repository": "https://github.com/grammarly/rocker",
"revision": "79bcadfcce121a8d9fa0f84e231314c6374bf8f3",
"branch": "master",
"path": "/src/rocker/dockerclient"
},
{
"importpath": "github.com/grammarly/rocker/src/rocker/util",
"repository": "https://github.com/grammarly/rocker",
Expand Down Expand Up @@ -131,6 +124,13 @@
"revision": "4d0275e3fcdd6460c7fe467678b04721bc19c9c7",
"branch": "v1",
"path": "/src/rocker/textformatter"
},
{
"importpath": "github.com/grammarly/rocker/src/rocker/dockerclient",
"repository": "https://github.com/grammarly/rocker",
"revision": "80510375c825db6731268f9f4f247a404879c966",
"branch": "v1",
"path": "/src/rocker/dockerclient"
}
]
}
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ import (
"os"
"strconv"
"strings"
"time"

"github.com/codegangsta/cli"
"github.com/fsouza/go-dockerclient"
Expand Down Expand Up @@ -95,6 +96,26 @@ func NewFromCli(c *cli.Context) (*docker.Client, error) {
return NewFromConfig(NewConfigFromCli(c))
}

// Ping pings docker client but with timeout
// The problem is that for some reason it's impossible to set the
// default timeout for the go-dockerclient Dialer, need to investigate
func Ping(client *docker.Client, timeoutMs int) error {
var (
chErr = make(chan error)
timeout = time.Duration(timeoutMs) * time.Millisecond
)
go func() {
chErr <- client.Ping()
}()
select {
case err := <-chErr:
return err
case <-time.After(timeout):
// TODO: can we kill the ping goroutine?
return fmt.Errorf("Failed to reach docker server, timeout %s", timeout)
}
}

// GlobalCliParams returns global params that configures docker client connection
func GlobalCliParams() []cli.Flag {
return []cli.Flag{
Expand Down

0 comments on commit eafb0ef

Please sign in to comment.