Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: Allow the container working directory to be specified #1899

Merged
merged 2 commits into from
Nov 6, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
1 change: 1 addition & 0 deletions container.go
Original file line number Diff line number Diff line change
Expand Up @@ -136,6 +136,7 @@ type ContainerRequest struct {
HostConfigModifier func(*container.HostConfig) // Modifier for the host config before container creation
EnpointSettingsModifier func(map[string]*network.EndpointSettings) // Modifier for the network settings before container creation
LifecycleHooks []ContainerLifecycleHooks // define hooks to be executed during container lifecycle
WorkingDir string // specify the working directory of the container
fhke marked this conversation as resolved.
Show resolved Hide resolved
}

// containerOptions functional options for a container
Expand Down
1 change: 1 addition & 0 deletions docker.go
Original file line number Diff line number Diff line change
Expand Up @@ -999,6 +999,7 @@ func (p *DockerProvider) CreateContainer(ctx context.Context, req ContainerReque
Cmd: req.Cmd,
Hostname: req.Hostname,
User: req.User,
WorkingDir: req.WorkingDir,
}

hostConfig := &container.HostConfig{
Expand Down
28 changes: 28 additions & 0 deletions docker_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1059,6 +1059,34 @@ func TestEntrypoint(t *testing.T) {
terminateContainerOnEnd(t, ctx, c)
}

func TestWorkingDir(t *testing.T) {
/*
print the current working directory to ensure that
we can specify working directory in the
ContainerRequest and it will be used for the container
*/

ctx := context.Background()

req := ContainerRequest{
Image: "docker.io/alpine",
WaitingFor: wait.ForAll(
wait.ForLog("/var/tmp/test"),
),
Entrypoint: []string{"pwd"},
WorkingDir: "/var/tmp/test",
}

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

require.NoError(t, err)
terminateContainerOnEnd(t, ctx, c)
}

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