This repository has been archived by the owner on Nov 28, 2022. It is now read-only.
/
client.go
53 lines (46 loc) · 2.34 KB
/
client.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
/*******************************************************************************
* Copyright (c) 2019 IBM Corporation and others.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v2.0
* which accompanies this distribution, and is available at
* http://www.eclipse.org/legal/epl-v20.html
*
* Contributors:
* IBM Corporation - initial API and implementation
*******************************************************************************/
package docker
import (
"context"
"io"
"time"
"github.com/docker/docker/api/types"
"github.com/docker/docker/api/types/registry"
"github.com/docker/docker/client"
)
// DockerClient requires all the functions called on the docker client
type DockerClient interface {
ImagePull(ctx context.Context, image string, imagePullOptions types.ImagePullOptions) (io.ReadCloser, error)
ImageList(ctx context.Context, imageListOptions types.ImageListOptions) ([]types.ImageSummary, error)
ClientVersion() string
ContainerList(ctx context.Context, containerListOptions types.ContainerListOptions) ([]types.Container, error)
ContainerInspect(ctx context.Context, containerID string) (types.ContainerJSON, error)
ContainerLogs(ctx context.Context, containerID string, options types.ContainerLogsOptions) (io.ReadCloser, error)
ContainerStop(ctx context.Context, containerID string, timeout *time.Duration) error
ContainerRemove(ctx context.Context, containerID string, options types.ContainerRemoveOptions) error
DaemonHost() string
CopyFromContainer(ctx context.Context, containerID, srcPath string) (io.ReadCloser, types.ContainerPathStat, error)
DistributionInspect(ctx context.Context, image, encodedRegistryAuth string) (registry.DistributionInspect, error)
ServerVersion(ctx context.Context) (types.Version, error)
}
// NewDockerClient creates a new client for the docker API
func NewDockerClient() (DockerClient, *DockerError) {
dockerClient, err := client.NewClientWithOpts(client.FromEnv, client.WithVersion("1.30"))
if err != nil {
return nil, &DockerError{errOpClientCreate, err, err.Error()}
}
return dockerClient, nil
}
// UsingLocalDockerHost returns true if we are using the default local docker host.
func UsingLocalDockerHost(dockerClient DockerClient) bool {
return dockerClient.DaemonHost() == client.DefaultDockerHost
}