Skip to content

Commit

Permalink
Merge pull request #209 from aklinkert/master
Browse files Browse the repository at this point in the history
Add pass-through for entrypoint to ContainerRequest
  • Loading branch information
gianarb authored Jun 10, 2020
2 parents 95d887a + c6d69ad commit 825f6a2
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 1 deletion.
2 changes: 2 additions & 0 deletions container.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import (
"github.com/docker/docker/pkg/archive"
"github.com/docker/go-connections/nat"
"github.com/pkg/errors"

"github.com/testcontainers/testcontainers-go/wait"
)

Expand Down Expand Up @@ -69,6 +70,7 @@ type FromDockerfile struct {
type ContainerRequest struct {
FromDockerfile
Image string
Entrypoint []string
Env map[string]string
ExposedPorts []string // allow specifying protocol info
Cmd []string
Expand Down
3 changes: 2 additions & 1 deletion docker.go
Original file line number Diff line number Diff line change
Expand Up @@ -531,6 +531,7 @@ func (p *DockerProvider) CreateContainer(ctx context.Context, req ContainerReque
}

dockerInput := &container.Config{
Entrypoint: req.Entrypoint,
Image: tag,
Env: env,
ExposedPorts: exposedPortSet,
Expand Down Expand Up @@ -600,7 +601,7 @@ func (p *DockerProvider) CreateContainer(ctx context.Context, req ContainerReque
return c, nil
}

//attemptToPullImage tries to pull the image while respecting the ctx cancellations.
// attemptToPullImage tries to pull the image while respecting the ctx cancellations.
// Besides, if the image cannot be pulled due to ErrorNotFound then no need to retry but terminate immediately.
func (p *DockerProvider) attemptToPullImage(ctx context.Context, tag string, pullOpt types.ImagePullOptions) error {
var (
Expand Down
30 changes: 30 additions & 0 deletions docker_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1036,6 +1036,36 @@ func TestCMD(t *testing.T) {
defer c.Terminate(ctx)
}

func TestEntrypoint(t *testing.T) {
/*
echo a unique statement to ensure that we
can pass in an entrypoint to the ContainerRequest
and it will be run when we run the container
*/

ctx := context.Background()

req := ContainerRequest{
Image: "alpine",
WaitingFor: wait.ForAll(
wait.ForLog("entrypoint override!"),
),
Entrypoint: []string{"echo", "entrypoint override!"},
}

c, err := GenericContainer(ctx, GenericContainerRequest{
ContainerRequest: req,
Started: true,
})

if err != nil {
t.Fatal(err)
}

// defer not needed, but keeping it in for consistency
defer c.Terminate(ctx)
}

func ExampleDockerProvider_CreateContainer() {
ctx := context.Background()
req := ContainerRequest{
Expand Down

0 comments on commit 825f6a2

Please sign in to comment.