Skip to content

Commit

Permalink
pass in whole config reference instead of just base image
Browse files Browse the repository at this point in the history
  • Loading branch information
christian-bromann committed Apr 24, 2020
1 parent 6952ae2 commit ecb2c32
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 8 deletions.
13 changes: 7 additions & 6 deletions cli/docker/docker.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ import (
"github.com/docker/docker/pkg/jsonmessage"
"github.com/docker/docker/pkg/system"

"github.com/saucelabs/saucectl/cli/config"
"github.com/saucelabs/saucectl/cli/streams"
"github.com/saucelabs/saucectl/cli/utils"
)
Expand Down Expand Up @@ -112,9 +113,9 @@ func (handler *Handler) PullBaseImage(ctx context.Context, baseImage string) err
}

// StartContainer starts the Docker testrunner container
func (handler *Handler) StartContainer(ctx context.Context, baseImage string) (*container.ContainerCreateCreatedBody, error) {
c, err := handler.client.ContainerCreate(ctx, &container.Config{
Image: baseImage,
func (handler *Handler) StartContainer(ctx context.Context, c config.JobConfiguration) (*container.ContainerCreateCreatedBody, error) {
container, err := handler.client.ContainerCreate(ctx, &container.Config{
Image: c.Image.Base,
Env: []string{
"SAUCE_USERNAME=" + os.Getenv("SAUCE_USERNAME"),
"SAUCE_ACCESS_KEY=" + os.Getenv("SAUCE_ACCESS_KEY")},
Expand All @@ -123,19 +124,19 @@ func (handler *Handler) StartContainer(ctx context.Context, baseImage string) (*
return nil, err
}

if err := handler.client.ContainerStart(ctx, c.ID, types.ContainerStartOptions{}); err != nil {
if err := handler.client.ContainerStart(ctx, container.ID, types.ContainerStartOptions{}); err != nil {
return nil, err
}

// We need to check the tty _before_ we do the ContainerExecCreate, because
// otherwise if we error out we will leak execIDs on the server (and
// there's no easy way to clean those up). But also in order to make "not
// exist" errors take precedence we do a dummy inspect first.
if _, err := handler.client.ContainerInspect(ctx, c.ID); err != nil {
if _, err := handler.client.ContainerInspect(ctx, container.ID); err != nil {
return nil, err
}

return &c, nil
return &container, nil
}

// CopyTestFilesToContainer copies files from the config into the container
Expand Down
6 changes: 5 additions & 1 deletion cli/docker/docker_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import (
"testing"

"github.com/docker/docker/api/types/container"
"github.com/saucelabs/saucectl/cli/config"
"github.com/stretchr/testify/assert"
"gotest.tools/v3/fs"
)
Expand Down Expand Up @@ -91,7 +92,10 @@ func TestStartContainer(t *testing.T) {
handler := Handler{
client: tc.Client,
}
_, err := handler.StartContainer(ctx, "foobar")
c := config.JobConfiguration{
Image: config.ImageDefinition{Base: "foobar"},
}
_, err := handler.StartContainer(ctx, c)
assert.Equal(t, err, tc.ExpectedError)
})
}
Expand Down
2 changes: 1 addition & 1 deletion cli/runner/local.go
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ func (r *localRunner) Setup() error {
}
}

container, err := r.docker.StartContainer(r.context, r.jobConfig.Image.Base)
container, err := r.docker.StartContainer(r.context, r.jobConfig)
if err != nil {
return err
}
Expand Down

0 comments on commit ecb2c32

Please sign in to comment.