Skip to content

Commit

Permalink
Fix Docker image pulling during e2e test setup
Browse files Browse the repository at this point in the history
Signed-off-by: Peter Motičák <[email protected]>
  • Loading branch information
pemoticak committed Aug 11, 2023
1 parent 6143d1b commit 33bc9a2
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 5 deletions.
14 changes: 13 additions & 1 deletion tests/e2e/e2etest/containerruntime.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ package e2etest
import (
"bytes"
"context"
"encoding/json"
"fmt"
"io"
"strings"
Expand All @@ -25,6 +26,7 @@ import (
moby "github.com/docker/docker/api/types"
"github.com/docker/docker/api/types/container"
"github.com/docker/docker/errdefs"
"github.com/docker/docker/pkg/jsonmessage"
"github.com/docker/docker/pkg/stdcopy"
"github.com/docker/docker/pkg/stringid"
"github.com/go-errors/errors"
Expand Down Expand Up @@ -180,10 +182,20 @@ func (c *ContainerRuntime) createContainer(config *moby.ContainerCreateConfig, p
// pull image
if pull {
image := config.Config.Image
_, err := c.ctx.dockerClient.ImagePull(c.ctx.ctx, image, moby.ImagePullOptions{})
reader, err := c.ctx.dockerClient.ImagePull(c.ctx.ctx, image, moby.ImagePullOptions{})
if err != nil {
return "", errors.Errorf("failed to pull %s image: %v", c.logIdentity, err)
}
defer reader.Close()
decoder := json.NewDecoder(reader)
for {
if err := decoder.Decode(&jsonmessage.JSONMessage{}); err == io.EOF {
break
} else if err != nil {
return "", errors.Errorf("failed to decode %s image pull response: %v", c.logIdentity, err)
}
}
c.ctx.t.Logf("pulled %s image with name %s", c.logIdentity, image)
}

// create container
Expand Down
4 changes: 2 additions & 2 deletions tests/e2e/e2etest/dns.go
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ func DNSServerStartOptionsForContainerRuntime(ctx *TestCtx, options interface{})
coreFilepath := CreateFileOnSharedVolume(ctx, "Corefile", corefileContent)

// construct container options
containerOptions := &moby.ContainerCreateConfig{
config := &moby.ContainerCreateConfig{
Name: "e2e-test-dns",
Config: &container.Config{
Image: dnsImage,
Expand All @@ -116,7 +116,7 @@ func DNSServerStartOptionsForContainerRuntime(ctx *TestCtx, options interface{})
}

return &ContainerStartOptions{
ContainerConfig: containerOptions,
ContainerConfig: config,
Pull: true,
}, nil
}
4 changes: 2 additions & 2 deletions tests/e2e/e2etest/etcd.go
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@ func ETCDStartOptionsForContainerRuntime(ctx *TestCtx, options interface{}) (int
"2379/tcp": {{HostIP: "0.0.0.0", HostPort: "2379"}},
}
}
containerConfig := &moby.ContainerCreateConfig{
config := &moby.ContainerCreateConfig{
Name: "e2e-test-etcd",
Config: &container.Config{
Env: []string{"ETCDCTL_API=3"},
Expand All @@ -125,7 +125,7 @@ func ETCDStartOptionsForContainerRuntime(ctx *TestCtx, options interface{}) (int
}

return &ContainerStartOptions{
ContainerConfig: containerConfig,
ContainerConfig: config,
Pull: true,
}, nil
}

0 comments on commit 33bc9a2

Please sign in to comment.