Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 5 additions & 3 deletions internal/runtime/docker.go
Original file line number Diff line number Diff line change
Expand Up @@ -107,10 +107,12 @@ func (d *DockerRuntime) PullImage(ctx context.Context, imageName string, progres
return nil
}

const emulatorContainerPort = nat.Port("4566/tcp")
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

thought: ultimately, when we support other emulators, we will to configure it per emulator and might want to move this value to runtime.ContainerConfig, but we can do it later!


func (d *DockerRuntime) Start(ctx context.Context, config ContainerConfig) (string, error) {
port := nat.Port(config.Port + "/tcp")
exposedPorts := nat.PortSet{port: struct{}{}}
portBindings := nat.PortMap{port: []nat.PortBinding{{HostPort: config.Port}}}
containerPort := emulatorContainerPort
exposedPorts := nat.PortSet{containerPort: struct{}{}}
portBindings := nat.PortMap{containerPort: []nat.PortBinding{{HostPort: config.Port}}}

resp, err := d.client.ContainerCreate(ctx,
&container.Config{
Expand Down
26 changes: 26 additions & 0 deletions test/integration/start_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@ package integration_test
import (
"context"
"net"
"os"
"path/filepath"
"testing"

"github.com/docker/docker/api/types/container"
Expand Down Expand Up @@ -95,6 +97,30 @@ func TestStartCommandFailsWhenPortInUse(t *testing.T) {
assert.Contains(t, stdout, "lstk stop")
}

func TestStartCommandSucceedsWithNonDefaultPort(t *testing.T) {
requireDocker(t)
_ = env.Require(t, env.AuthToken)

cleanup()
t.Cleanup(cleanup)

mockServer := createMockLicenseServer(true)
defer mockServer.Close()

configContent := `
[[containers]]
type = "aws"
tag = "latest"
port = "4567"
`
configFile := filepath.Join(t.TempDir(), "config.toml")
require.NoError(t, os.WriteFile(configFile, []byte(configContent), 0644))

ctx := testContext(t)
_, stderr, err := runLstk(t, ctx, "", env.With(env.APIEndpoint, mockServer.URL), "--config", configFile, "start")
require.NoError(t, err, "lstk start failed: %s", stderr)
}

func cleanup() {
ctx := context.Background()
_ = dockerClient.ContainerStop(ctx, containerName, container.StopOptions{})
Expand Down
Loading