[#26] - Skip Image download if already downloaded
* Before performing Image Pull check if image already exists in local * Added ImageInpspect to check if Image exists locally * Updated Test cases Change-Id: I9f2927325f3b86124f9d2637ba3391af33b95c71
This commit is contained in:
parent
2bf3117197
commit
0ba6748020
|
@ -12,6 +12,8 @@ import (
|
|||
"github.com/docker/docker/api/types/filters"
|
||||
"github.com/docker/docker/api/types/network"
|
||||
"github.com/docker/docker/client"
|
||||
|
||||
"opendev.org/airship/airshipctl/pkg/log"
|
||||
)
|
||||
|
||||
// DockerClient interface that represents abstract Docker client object
|
||||
|
@ -196,8 +198,14 @@ func (c *DockerContainer) GetID() string {
|
|||
|
||||
// ImagePull downloads image for container
|
||||
func (c *DockerContainer) ImagePull() error {
|
||||
// TODO (D. Ukov) add logic for searching among local images
|
||||
// to avoid image download on each execution
|
||||
// skip image download if already downloaded
|
||||
// ImageInspectWithRaw returns err when image not found local and
|
||||
// in this case it will proceed for ImagePull.
|
||||
_, _, err := c.dockerClient.ImageInspectWithRaw(*c.ctx, c.imageURL)
|
||||
if err == nil {
|
||||
log.Debug("Image Already exists, skip download")
|
||||
return nil
|
||||
}
|
||||
resp, err := c.dockerClient.ImagePull(*c.ctx, c.imageURL, types.ImagePullOptions{})
|
||||
if err != nil {
|
||||
return err
|
||||
|
|
|
@ -218,6 +218,9 @@ func TestImagePull(t *testing.T) {
|
|||
imagePull: func() (io.ReadCloser, error) {
|
||||
return ioutil.NopCloser(strings.NewReader("test")), nil
|
||||
},
|
||||
imageInspectWithRaw: func() (types.ImageInspect, []byte, error) {
|
||||
return types.ImageInspect{}, nil, testError
|
||||
},
|
||||
},
|
||||
expectedErr: nil,
|
||||
},
|
||||
|
@ -226,6 +229,9 @@ func TestImagePull(t *testing.T) {
|
|||
imagePull: func() (io.ReadCloser, error) {
|
||||
return nil, testError
|
||||
},
|
||||
imageInspectWithRaw: func() (types.ImageInspect, []byte, error) {
|
||||
return types.ImageInspect{}, nil, testError
|
||||
},
|
||||
},
|
||||
expectedErr: testError,
|
||||
},
|
||||
|
@ -442,6 +448,9 @@ func TestNewDockerContainer(t *testing.T) {
|
|||
imagePull: func() (io.ReadCloser, error) {
|
||||
return ioutil.NopCloser(strings.NewReader("test")), nil
|
||||
},
|
||||
imageInspectWithRaw: func() (types.ImageInspect, []byte, error) {
|
||||
return types.ImageInspect{}, nil, testError
|
||||
},
|
||||
},
|
||||
expectedErr: nil,
|
||||
expectedResult: resultStruct{
|
||||
|
@ -457,6 +466,9 @@ func TestNewDockerContainer(t *testing.T) {
|
|||
imagePull: func() (io.ReadCloser, error) {
|
||||
return nil, testError
|
||||
},
|
||||
imageInspectWithRaw: func() (types.ImageInspect, []byte, error) {
|
||||
return types.ImageInspect{}, nil, testError
|
||||
},
|
||||
},
|
||||
expectedErr: testError,
|
||||
expectedResult: resultStruct{},
|
||||
|
|
Loading…
Reference in New Issue