Skip to content

Commit 40116c3

Browse files
committed
Code changes to match current dependecies
1 parent dbe3971 commit 40116c3

File tree

8 files changed

+87
-62
lines changed

8 files changed

+87
-62
lines changed

pkg/docker/docker.go

+29-27
Original file line numberDiff line numberDiff line change
@@ -18,12 +18,12 @@ import (
1818
"syscall"
1919
"time"
2020

21+
dockertypes "github.com/docker/docker/api/types"
22+
dockercontainer "github.com/docker/docker/api/types/container"
23+
dockernetwork "github.com/docker/docker/api/types/network"
24+
dockerapi "github.com/docker/docker/client"
2125
dockermessage "github.com/docker/docker/pkg/jsonmessage"
2226
dockerstdcopy "github.com/docker/docker/pkg/stdcopy"
23-
dockerapi "github.com/docker/engine-api/client"
24-
dockertypes "github.com/docker/engine-api/types"
25-
dockercontainer "github.com/docker/engine-api/types/container"
26-
dockernetwork "github.com/docker/engine-api/types/network"
2727
"github.com/docker/go-connections/tlsconfig"
2828
"golang.org/x/net/context"
2929

@@ -142,19 +142,19 @@ type Docker interface {
142142
// Client contains all methods used when interacting directly with docker engine-api
143143
type Client interface {
144144
ContainerAttach(ctx context.Context, container string, options dockertypes.ContainerAttachOptions) (dockertypes.HijackedResponse, error)
145-
ContainerCommit(ctx context.Context, container string, options dockertypes.ContainerCommitOptions) (dockertypes.ContainerCommitResponse, error)
146-
ContainerCreate(ctx context.Context, config *dockercontainer.Config, hostConfig *dockercontainer.HostConfig, networkingConfig *dockernetwork.NetworkingConfig, containerName string) (dockertypes.ContainerCreateResponse, error)
147-
ContainerInspect(ctx context.Context, containerID string) (dockertypes.ContainerJSON, error)
148-
ContainerRemove(ctx context.Context, containerID string, options dockertypes.ContainerRemoveOptions) error
149-
ContainerStart(ctx context.Context, containerID string) error
150-
ContainerKill(ctx context.Context, containerID, signal string) error
151-
ContainerWait(ctx context.Context, containerID string) (int, error)
145+
ContainerCommit(ctx context.Context, container string, options dockertypes.ContainerCommitOptions) (dockertypes.IDResponse, error)
146+
ContainerCreate(ctx context.Context, config *dockercontainer.Config, hostConfig *dockercontainer.HostConfig, networkingConfig *dockernetwork.NetworkingConfig, containerName string) (dockercontainer.ContainerCreateCreatedBody, error)
147+
ContainerInspect(ctx context.Context, container string) (dockertypes.ContainerJSON, error)
148+
ContainerRemove(ctx context.Context, container string, options dockertypes.ContainerRemoveOptions) error
149+
ContainerStart(ctx context.Context, container string, options dockertypes.ContainerStartOptions) error
150+
ContainerKill(ctx context.Context, container, signal string) error
151+
ContainerWait(ctx context.Context, container string, condition dockercontainer.WaitCondition) (<-chan dockercontainer.ContainerWaitOKBody, <-chan error)
152152
CopyToContainer(ctx context.Context, container, path string, content io.Reader, opts dockertypes.CopyToContainerOptions) error
153153
CopyFromContainer(ctx context.Context, container, srcPath string) (io.ReadCloser, dockertypes.ContainerPathStat, error)
154154
ImageBuild(ctx context.Context, buildContext io.Reader, options dockertypes.ImageBuildOptions) (dockertypes.ImageBuildResponse, error)
155-
ImageInspectWithRaw(ctx context.Context, imageID string, getSize bool) (dockertypes.ImageInspect, []byte, error)
155+
ImageInspectWithRaw(ctx context.Context, image string) (dockertypes.ImageInspect, []byte, error)
156156
ImagePull(ctx context.Context, ref string, options dockertypes.ImagePullOptions) (io.ReadCloser, error)
157-
ImageRemove(ctx context.Context, imageID string, options dockertypes.ImageRemoveOptions) ([]dockertypes.ImageDelete, error)
157+
ImageRemove(ctx context.Context, image string, options dockertypes.ImageRemoveOptions) ([]dockertypes.ImageDeleteResponseItem, error)
158158
ServerVersion(ctx context.Context) (dockertypes.Version, error)
159159
}
160160

@@ -167,7 +167,7 @@ type stiDocker struct {
167167
func (d stiDocker) InspectImage(name string) (*dockertypes.ImageInspect, error) {
168168
ctx, cancel := getDefaultContext()
169169
defer cancel()
170-
resp, _, err := d.client.ImageInspectWithRaw(ctx, name, false)
170+
resp, _, err := d.client.ImageInspectWithRaw(ctx, name)
171171
if err != nil {
172172
return nil, err
173173
}
@@ -819,7 +819,7 @@ func determineCommandBaseDir(opts RunContainerOptions, imageMetadata *api.Image,
819819
}
820820

821821
// dumpContainerInfo dumps information about a running container (port/IP/etc).
822-
func dumpContainerInfo(container dockertypes.ContainerCreateResponse, d *stiDocker, image string) {
822+
func dumpContainerInfo(container dockercontainer.ContainerCreateCreatedBody, d *stiDocker, image string) {
823823
ctx, cancel := getDefaultContext()
824824
defer cancel()
825825

@@ -1024,7 +1024,7 @@ func (d *stiDocker) RunContainer(opts RunContainerOptions) error {
10241024
glog.V(2).Infof("Starting container %q ...", container.ID)
10251025
ctx, cancel = getDefaultContext()
10261026
defer cancel()
1027-
err = d.client.ContainerStart(ctx, container.ID)
1027+
err = d.client.ContainerStart(ctx, container.ID, dockertypes.ContainerStartOptions{})
10281028
if err != nil {
10291029
return err
10301030
}
@@ -1053,18 +1053,20 @@ func (d *stiDocker) RunContainer(opts RunContainerOptions) error {
10531053
// Return an error if the exit code of the container is
10541054
// non-zero.
10551055
glog.V(4).Infof("Waiting for container %q to stop ...", container.ID)
1056-
exitCode, err := d.client.ContainerWait(context.Background(), container.ID)
1057-
if err != nil {
1058-
return fmt.Errorf("waiting for container %q to stop: %v", container.ID, err)
1059-
}
1060-
if exitCode != 0 {
1061-
var output string
1062-
json, _ := d.client.ContainerInspect(ctx, container.ID)
1063-
if err == nil && json.ContainerJSONBase != nil && json.ContainerJSONBase.State != nil {
1064-
state := json.ContainerJSONBase.State
1065-
output = fmt.Sprintf("Status: %s, Error: %s, OOMKilled: %v, Dead: %v", state.Status, state.Error, state.OOMKilled, state.Dead)
1056+
waitC, errC := d.client.ContainerWait(context.Background(), container.ID, dockercontainer.WaitConditionNextExit)
1057+
select {
1058+
case result := <-waitC:
1059+
if result.StatusCode != 0 {
1060+
var output string
1061+
json, _ := d.client.ContainerInspect(ctx, container.ID)
1062+
if err == nil && json.ContainerJSONBase != nil && json.ContainerJSONBase.State != nil {
1063+
state := json.ContainerJSONBase.State
1064+
output = fmt.Sprintf("Status: %s, Error: %s, OOMKilled: %v, Dead: %v", state.Status, state.Error, state.OOMKilled, state.Dead)
1065+
}
1066+
return s2ierr.NewContainerError(container.ID, int(result.StatusCode), output)
10661067
}
1067-
return s2ierr.NewContainerError(container.ID, exitCode, output)
1068+
case err := <-errC:
1069+
return fmt.Errorf("waiting for container %q to stop: %v", container.ID, err)
10681070
}
10691071

10701072
// OnStart must be done before we move on.

pkg/docker/docker_test.go

+4-4
Original file line numberDiff line numberDiff line change
@@ -16,9 +16,9 @@ import (
1616
"github.com/openshift/source-to-image/pkg/errors"
1717
testfs "github.com/openshift/source-to-image/pkg/test/fs"
1818

19-
dockertypes "github.com/docker/engine-api/types"
20-
dockercontainer "github.com/docker/engine-api/types/container"
21-
dockerstrslice "github.com/docker/engine-api/types/strslice"
19+
dockertypes "github.com/docker/docker/api/types"
20+
dockercontainer "github.com/docker/docker/api/types/container"
21+
dockerstrslice "github.com/docker/docker/api/types/strslice"
2222
)
2323

2424
func TestContainerName(t *testing.T) {
@@ -82,7 +82,7 @@ func TestCommitContainer(t *testing.T) {
8282
param := dockertypes.ContainerCommitOptions{
8383
Reference: tst.containerTag,
8484
}
85-
resp := dockertypes.ContainerCommitResponse{
85+
resp := dockertypes.IDResponse{
8686
ID: tst.expectedImageID,
8787
}
8888
fakeDocker := &dockertest.FakeDockerClient{

pkg/docker/fake_docker.go

+2-1
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,8 @@ import (
55
"io"
66
"io/ioutil"
77

8-
dockertypes "github.com/docker/engine-api/types"
8+
dockertypes "github.com/docker/docker/api/types"
9+
910
"github.com/openshift/source-to-image/pkg/api"
1011
"github.com/openshift/source-to-image/pkg/tar"
1112
"github.com/openshift/source-to-image/pkg/util/fs"

pkg/docker/test/client.go

+26-14
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,9 @@ import (
1010
"net"
1111
"time"
1212

13-
dockertypes "github.com/docker/engine-api/types"
14-
dockercontainer "github.com/docker/engine-api/types/container"
15-
dockernetwork "github.com/docker/engine-api/types/network"
13+
dockertypes "github.com/docker/docker/api/types"
14+
dockercontainer "github.com/docker/docker/api/types/container"
15+
dockernetwork "github.com/docker/docker/api/types/network"
1616
"golang.org/x/net/context"
1717
)
1818

@@ -79,7 +79,7 @@ type FakeDockerClient struct {
7979

8080
ContainerCommitID string
8181
ContainerCommitOptions dockertypes.ContainerCommitOptions
82-
ContainerCommitResponse dockertypes.ContainerCommitResponse
82+
ContainerCommitResponse dockertypes.IDResponse
8383
ContainerCommitErr error
8484

8585
BuildImageOpts dockertypes.ImageBuildOptions
@@ -103,7 +103,7 @@ func NewFakeDockerClient() *FakeDockerClient {
103103
}
104104

105105
// ImageInspectWithRaw returns the image information and its raw representation.
106-
func (d *FakeDockerClient) ImageInspectWithRaw(ctx context.Context, imageID string, getSize bool) (dockertypes.ImageInspect, []byte, error) {
106+
func (d *FakeDockerClient) ImageInspectWithRaw(ctx context.Context, imageID string) (dockertypes.ImageInspect, []byte, error) {
107107
d.Calls = append(d.Calls, "inspect_image")
108108

109109
if _, exists := d.Images[imageID]; exists {
@@ -129,13 +129,25 @@ func (d *FakeDockerClient) CopyFromContainer(ctx context.Context, container, src
129129
}
130130

131131
// ContainerWait pauses execution until a container exits.
132-
func (d *FakeDockerClient) ContainerWait(ctx context.Context, containerID string) (int, error) {
132+
func (d *FakeDockerClient) ContainerWait(ctx context.Context, containerID string, condition dockercontainer.WaitCondition) (<-chan dockercontainer.ContainerWaitOKBody, <-chan error) {
133133
d.WaitContainerID = containerID
134-
return d.WaitContainerResult, d.WaitContainerErr
134+
resultC := make(chan dockercontainer.ContainerWaitOKBody)
135+
errC := make(chan error, 1)
136+
137+
go func() {
138+
if d.WaitContainerErr != nil {
139+
errC <- d.WaitContainerErr
140+
return
141+
}
142+
143+
resultC <- dockercontainer.ContainerWaitOKBody{StatusCode: int64(d.WaitContainerResult)}
144+
}()
145+
146+
return resultC, errC
135147
}
136148

137149
// ContainerCommit applies changes into a container and creates a new tagged image.
138-
func (d *FakeDockerClient) ContainerCommit(ctx context.Context, container string, options dockertypes.ContainerCommitOptions) (dockertypes.ContainerCommitResponse, error) {
150+
func (d *FakeDockerClient) ContainerCommit(ctx context.Context, container string, options dockertypes.ContainerCommitOptions) (dockertypes.IDResponse, error) {
139151
d.ContainerCommitID = container
140152
d.ContainerCommitOptions = options
141153
return d.ContainerCommitResponse, d.ContainerCommitErr
@@ -156,11 +168,11 @@ func (d *FakeDockerClient) ImageBuild(ctx context.Context, buildContext io.Reade
156168
}
157169

158170
// ContainerCreate creates a new container based in the given configuration.
159-
func (d *FakeDockerClient) ContainerCreate(ctx context.Context, config *dockercontainer.Config, hostConfig *dockercontainer.HostConfig, networkingConfig *dockernetwork.NetworkingConfig, containerName string) (dockertypes.ContainerCreateResponse, error) {
171+
func (d *FakeDockerClient) ContainerCreate(ctx context.Context, config *dockercontainer.Config, hostConfig *dockercontainer.HostConfig, networkingConfig *dockernetwork.NetworkingConfig, containerName string) (dockercontainer.ContainerCreateCreatedBody, error) {
160172
d.Calls = append(d.Calls, "create")
161173

162174
d.Containers[containerName] = *config
163-
return dockertypes.ContainerCreateResponse{}, nil
175+
return dockercontainer.ContainerCreateCreatedBody{}, nil
164176
}
165177

166178
// ContainerInspect returns the container information.
@@ -186,7 +198,7 @@ func (d *FakeDockerClient) ContainerKill(ctx context.Context, containerID, signa
186198
}
187199

188200
// ContainerStart sends a request to the docker daemon to start a container.
189-
func (d *FakeDockerClient) ContainerStart(ctx context.Context, containerID string) error {
201+
func (d *FakeDockerClient) ContainerStart(ctx context.Context, containerID string, options dockertypes.ContainerStartOptions) error {
190202
d.Calls = append(d.Calls, "start")
191203
return nil
192204
}
@@ -203,14 +215,14 @@ func (d *FakeDockerClient) ImagePull(ctx context.Context, ref string, options do
203215
}
204216

205217
// ImageRemove removes an image from the docker host.
206-
func (d *FakeDockerClient) ImageRemove(ctx context.Context, imageID string, options dockertypes.ImageRemoveOptions) ([]dockertypes.ImageDelete, error) {
218+
func (d *FakeDockerClient) ImageRemove(ctx context.Context, imageID string, options dockertypes.ImageRemoveOptions) ([]dockertypes.ImageDeleteResponseItem, error) {
207219
d.Calls = append(d.Calls, "remove_image")
208220

209221
if _, exists := d.Images[imageID]; exists {
210222
delete(d.Images, imageID)
211-
return []dockertypes.ImageDelete{}, nil
223+
return []dockertypes.ImageDeleteResponseItem{}, nil
212224
}
213-
return []dockertypes.ImageDelete{}, errors.New("image does not exist")
225+
return []dockertypes.ImageDeleteResponseItem{}, errors.New("image does not exist")
214226
}
215227

216228
// ServerVersion returns information of the docker client and server host.

pkg/docker/util.go

+2-1
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,8 @@ import (
1616

1717
"github.com/docker/distribution/reference"
1818
cliconfig "github.com/docker/docker/cli/config"
19-
"github.com/docker/engine-api/client"
19+
"github.com/docker/docker/client"
20+
2021
"github.com/openshift/source-to-image/pkg/api"
2122
s2ierr "github.com/openshift/source-to-image/pkg/errors"
2223
utilglog "github.com/openshift/source-to-image/pkg/util/glog"

pkg/util/util.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
package util
22

33
import (
4-
"github.com/docker/engine-api/types/container"
4+
"github.com/docker/docker/api/types/container"
55

66
utilglog "github.com/openshift/source-to-image/pkg/util/glog"
77
)

pkg/util/util_test.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ import (
55
"strings"
66
"testing"
77

8-
"github.com/docker/engine-api/types/container"
8+
"github.com/docker/docker/api/types/container"
99
)
1010

1111
func TestSafeForLoggingContainerConfig(t *testing.T) {

test/integration/integration_test.go

+22-13
Original file line numberDiff line numberDiff line change
@@ -16,9 +16,9 @@ import (
1616
"testing"
1717
"time"
1818

19-
dockerapi "github.com/docker/engine-api/client"
20-
dockertypes "github.com/docker/engine-api/types"
21-
dockercontainer "github.com/docker/engine-api/types/container"
19+
dockertypes "github.com/docker/docker/api/types"
20+
dockercontainer "github.com/docker/docker/api/types/container"
21+
dockerapi "github.com/docker/docker/client"
2222
"github.com/golang/glog"
2323
"github.com/openshift/source-to-image/pkg/api"
2424
"github.com/openshift/source-to-image/pkg/build/strategies"
@@ -125,7 +125,7 @@ type integrationTest struct {
125125
func (i integrationTest) InspectImage(name string) (*dockertypes.ImageInspect, error) {
126126
ctx, cancel := getDefaultContext()
127127
defer cancel()
128-
resp, _, err := engineClient.ImageInspectWithRaw(ctx, name, false)
128+
resp, _, err := engineClient.ImageInspectWithRaw(ctx, name)
129129
if err != nil {
130130
if dockerapi.IsErrImageNotFound(err) {
131131
return nil, fmt.Errorf("no such image :%q", name)
@@ -541,20 +541,25 @@ func (i *integrationTest) createContainer(image string) string {
541541

542542
ctx, cancel = getDefaultContext()
543543
defer cancel()
544-
err = engineClient.ContainerStart(ctx, container.ID)
544+
err = engineClient.ContainerStart(ctx, container.ID, dockertypes.ContainerStartOptions{})
545545
if err != nil {
546546
i.t.Errorf("Couldn't start container: %s with error %+v", container.ID, err)
547547
return ""
548548
}
549549

550550
ctx, cancel = getDefaultContext()
551551
defer cancel()
552-
exitCode, _ := engineClient.ContainerWait(ctx, container.ID)
553-
if exitCode != 0 {
554-
i.t.Errorf("Bad exit code from container: %d", exitCode)
552+
waitC, errC := engineClient.ContainerWait(ctx, container.ID, dockercontainer.WaitConditionNextExit)
553+
select {
554+
case result := <-waitC:
555+
if result.StatusCode != 0 {
556+
i.t.Errorf("Bad exit code from container: %d", result.StatusCode)
557+
return ""
558+
}
559+
case err := <-errC:
560+
i.t.Errorf("Error waiting for container: %v", err)
555561
return ""
556562
}
557-
558563
return container.ID
559564
}
560565

@@ -570,15 +575,19 @@ func (i *integrationTest) runInContainer(image string, command []string) int {
570575

571576
ctx, cancel = getDefaultContext()
572577
defer cancel()
573-
err = engineClient.ContainerStart(ctx, container.ID)
578+
err = engineClient.ContainerStart(ctx, container.ID, dockertypes.ContainerStartOptions{})
574579
if err != nil {
575580
i.t.Errorf("Couldn't start container: %s", container.ID)
576581
}
577582
ctx, cancel = getDefaultContext()
578583
defer cancel()
579-
exitCode, err := engineClient.ContainerWait(ctx, container.ID)
580-
if err != nil {
581-
i.t.Errorf("Couldn't wait for container: %s", container.ID)
584+
waitC, errC := engineClient.ContainerWait(ctx, container.ID, dockercontainer.WaitConditionNextExit)
585+
exitCode := -1
586+
select {
587+
case result := <-waitC:
588+
exitCode = int(result.StatusCode)
589+
case err := <-errC:
590+
i.t.Errorf("Couldn't wait for container: %s: %v", container.ID, err)
582591
}
583592
ctx, cancel = getDefaultContext()
584593
defer cancel()

0 commit comments

Comments
 (0)