Skip to content

Commit db2c708

Browse files
committed
Address feedback
1 parent ac85b51 commit db2c708

4 files changed

Lines changed: 34 additions & 17 deletions

File tree

internal/config/containers.go

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,10 @@ var emulatorHealthPaths = map[EmulatorType]string{
3131
EmulatorAWS: "/_localstack/health",
3232
}
3333

34+
var emulatorContainerPorts = map[EmulatorType]string{
35+
EmulatorAWS: "4566/tcp",
36+
}
37+
3438
type ContainerConfig struct {
3539
Type EmulatorType `mapstructure:"type"`
3640
Tag string `mapstructure:"tag"`
@@ -84,6 +88,14 @@ func (c *ContainerConfig) HealthPath() (string, error) {
8488
return path, nil
8589
}
8690

91+
func (c *ContainerConfig) ContainerPort() (string, error) {
92+
port, ok := emulatorContainerPorts[c.Type]
93+
if !ok {
94+
return "", fmt.Errorf("%s emulator not supported yet by lstk", c.Type)
95+
}
96+
return port, nil
97+
}
98+
8799
func (c *ContainerConfig) DisplayName() string {
88100
name, ok := emulatorDisplayNames[c.Type]
89101
if !ok {

internal/container/start.go

Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -69,19 +69,25 @@ func Start(ctx context.Context, rt runtime.Runtime, sink output.Sink, opts Start
6969
return err
7070
}
7171

72+
containerPort, err := c.ContainerPort()
73+
if err != nil {
74+
return err
75+
}
76+
7277
resolvedEnv, err := c.ResolvedEnv(opts.Env)
7378
if err != nil {
7479
return err
7580
}
7681
env := append(resolvedEnv, "LOCALSTACK_AUTH_TOKEN="+token)
7782
containers[i] = runtime.ContainerConfig{
78-
Image: image,
79-
Name: c.Name(),
80-
Port: c.Port,
81-
HealthPath: healthPath,
82-
Env: env,
83-
Tag: c.Tag,
84-
ProductName: productName,
83+
Image: image,
84+
Name: c.Name(),
85+
Port: c.Port,
86+
ContainerPort: containerPort,
87+
HealthPath: healthPath,
88+
Env: env,
89+
Tag: c.Tag,
90+
ProductName: productName,
8591
}
8692
}
8793

internal/runtime/docker.go

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -107,10 +107,8 @@ func (d *DockerRuntime) PullImage(ctx context.Context, imageName string, progres
107107
return nil
108108
}
109109

110-
const emulatorContainerPort = nat.Port("4566/tcp")
111-
112110
func (d *DockerRuntime) Start(ctx context.Context, config ContainerConfig) (string, error) {
113-
containerPort := emulatorContainerPort
111+
containerPort := nat.Port(config.ContainerPort)
114112
exposedPorts := nat.PortSet{containerPort: struct{}{}}
115113
portBindings := nat.PortMap{containerPort: []nat.PortBinding{{HostPort: config.Port}}}
116114

internal/runtime/runtime.go

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -8,13 +8,14 @@ import (
88
)
99

1010
type ContainerConfig struct {
11-
Image string
12-
Name string
13-
Port string
14-
HealthPath string
15-
Env []string // e.g., ["KEY=value", "FOO=bar"]
16-
Tag string
17-
ProductName string
11+
Image string
12+
Name string
13+
Port string
14+
ContainerPort string // internal port the emulator listens on inside the container (e.g. "4566/tcp")
15+
HealthPath string
16+
Env []string // e.g., ["KEY=value", "FOO=bar"]
17+
Tag string
18+
ProductName string
1819
}
1920

2021
type PullProgress struct {

0 commit comments

Comments
 (0)