chore(engine): ping docker daemon

Signed-off-by: Bo-Yi Wu <appleboy.tw@gmail.com>
This commit is contained in:
Bo-Yi Wu
2022-08-13 14:15:21 +08:00
committed by Jason Song
parent 9225a3a856
commit 4eb5213294
6 changed files with 281 additions and 221 deletions

39
engine/docker.go Normal file
View File

@ -0,0 +1,39 @@
package engine
import (
"context"
"github.com/docker/docker/client"
)
// Opts configures the Docker engine.
type Opts struct {
HidePull bool
}
type Docker struct {
client client.APIClient
hidePull bool
}
func New(client client.APIClient, opts Opts) *Docker {
return &Docker{
client: client,
hidePull: opts.HidePull,
}
}
// NewEnv returns a new Engine from the environment.
func NewEnv(opts Opts) (*Docker, error) {
cli, err := client.NewClientWithOpts(client.FromEnv)
if err != nil {
return nil, err
}
return New(cli, opts), nil
}
// Ping pings the Docker daemon.
func (e *Docker) Ping(ctx context.Context) error {
_, err := e.client.Ping(ctx)
return err
}