-
Notifications
You must be signed in to change notification settings - Fork 4
Attach to externally-started LS container #190
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
Changes from all commits
9a63042
e22f334
4432271
2cdc7cf
dd1fb3f
200ce21
0016815
2d2748f
a3d2a27
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -372,27 +372,82 @@ func selectContainersToStart(ctx context.Context, rt runtime.Runtime, sink outpu | |
| emitPostStartPointers(sink, resolvedHost, webAppURL) | ||
| continue | ||
| } | ||
| if err := ports.CheckAvailable(c.Port); err != nil { | ||
|
|
||
| imageRepo, _, _ := strings.Cut(c.Image, ":") | ||
| found, err := rt.FindRunningByImage(ctx, []string{imageRepo, "localstack/localstack"}, c.ContainerPort) | ||
| if err != nil { | ||
| return nil, fmt.Errorf("failed to scan for running containers: %w", err) | ||
| } | ||
| if found != nil { | ||
| if found.BoundPort != c.Port { | ||
| output.EmitError(sink, output.ErrorEvent{ | ||
| Title: fmt.Sprintf("LocalStack is already running on port %s", found.BoundPort), | ||
|
gtsiolis marked this conversation as resolved.
|
||
| Summary: fmt.Sprintf("Config expects port %s. Only one instance can run at a time.", c.Port), | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. thought: We previously didn't have this restriction.
I'd expect to be able to spin up more than one instance as long as the port is different. This is how it works now, you can set
Collaborator
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Reporting here e the conversation @gtsiolis and I had privately: Because of the fact that the aws emulator also uses other ports ( |
||
| Actions: []output.ErrorAction{ | ||
| {Label: "Stop existing emulator:", Value: "lstk stop"}, | ||
| }, | ||
| }) | ||
| emitEmulatorStartError(ctx, tel, c, telemetry.ErrCodePortConflict, fmt.Sprintf("running on port %s, configured port %s", found.BoundPort, c.Port)) | ||
| return nil, output.NewSilentError(fmt.Errorf("LocalStack already running on port %s", found.BoundPort)) | ||
| } | ||
| output.EmitInfo(sink, "LocalStack is already running") | ||
|
gtsiolis marked this conversation as resolved.
|
||
| continue | ||
| } | ||
|
|
||
| if _, err := ports.CheckAvailable(c.Port); err != nil { | ||
| if info, infoErr := fetchLocalStackInfo(ctx, c.Port); infoErr == nil { | ||
| emitLocalStackAlreadyRunningWarning(sink, c.Port, info.Version, c.Tag) | ||
| continue | ||
| } | ||
| emitPortInUseError(sink, c.Port) | ||
| emitEmulatorStartError(ctx, tel, c, telemetry.ErrCodePortConflict, err.Error()) | ||
| return nil, output.NewSilentError(err) | ||
| } | ||
|
|
||
| // Check extra ports required by this emulator (443 for HTTPS, 4510-4559 for | ||
| // the service port range). These are singletons: if any is taken, another | ||
| // LocalStack instance is likely running and we cannot start a new one. | ||
| extraSpecs := make([]string, len(c.ExtraPorts)) | ||
| for i, ep := range c.ExtraPorts { | ||
| extraSpecs[i] = ep.HostPort | ||
| } | ||
| if conflictPort, err := ports.CheckAvailable(extraSpecs...); err != nil { | ||
| output.EmitError(sink, output.ErrorEvent{ | ||
| Title: fmt.Sprintf("Port %s is already in use", conflictPort), | ||
|
carole-lavillonniere marked this conversation as resolved.
|
||
| Summary: "LocalStack requires this port. Free it before starting.", | ||
| }) | ||
| emitEmulatorStartError(ctx, tel, c, telemetry.ErrCodePortConflict, err.Error()) | ||
| return nil, output.NewSilentError(err) | ||
| } | ||
|
|
||
| filtered = append(filtered, c) | ||
| } | ||
| return filtered, nil | ||
| } | ||
|
|
||
| func emitPortInUseError(sink output.Sink, port string) { | ||
| actions := []output.ErrorAction{ | ||
| {Label: "Stop existing emulator:", Value: "lstk stop"}, | ||
| func emitLocalStackAlreadyRunningWarning(sink output.Sink, port, runningVersion, configTag string) { | ||
| if configTag == "" { | ||
| configTag = "latest" | ||
| } | ||
| if runningVersion != configTag { | ||
| output.EmitWarning(sink, fmt.Sprintf( | ||
| "LocalStack %s is already running on port %s (config specifies %s) — using the running instance", | ||
| runningVersion, port, configTag, | ||
| )) | ||
| } else { | ||
| output.EmitInfo(sink, fmt.Sprintf("LocalStack %s is already running on port %s", runningVersion, port)) | ||
| } | ||
| } | ||
|
|
||
| func emitPortInUseError(sink output.Sink, port string) { | ||
| actions := []output.ErrorAction{} | ||
| configPath, pathErr := config.ConfigFilePath() | ||
| if pathErr == nil { | ||
| actions = append(actions, output.ErrorAction{Label: "Use another port in the configuration:", Value: configPath}) | ||
| } | ||
| output.EmitError(sink, output.ErrorEvent{ | ||
| Title: fmt.Sprintf("Port %s already in use", port), | ||
| Summary: "LocalStack may already be running.", | ||
| Summary: "Free the port or configure a different one.", | ||
| Actions: actions, | ||
| }) | ||
| } | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.