Handle already-running containers and port conflicts#40
Handle already-running containers and port conflicts#40carole-lavillonniere wants to merge 2 commits intomainfrom
Conversation
|
@coderabbitai review |
e3ea894 to
cb71ed1
Compare
📝 WalkthroughWalkthroughRefactors the container startup flow into a staged pipeline (select, pull images, validate licenses, start) with new port availability validation, while consolidating Docker test helpers into a shared test infrastructure module. Changes
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~25 minutes 🚥 Pre-merge checks | ✅ 2✅ Passed checks (2 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing touches
🧪 Generate unit tests (beta)
Tip Issue Planner is now in beta. Read the docs and try it out! Share your feedback on Discord. Comment |
There was a problem hiding this comment.
Actionable comments posted: 1
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.
Inline comments:
In `@internal/container/start.go`:
- Around line 57-75: The token is currently retrieved before
selectContainersToStart which prevents early-return when no containers need
starting; move the token retrieval to after selectContainersToStart and the
len(containers)==0 check so lstk can fast-exit without failing on missing token.
Update the flow in start.go: call selectContainersToStart(...) first, if
len(containers)==0 return nil, then fetch the token (the existing token
retrieval logic), then ensure the filtered containers (the returned containers
value) are injected/associated with the token before calling pullImages(...),
validateLicenses(..., token) and startContainers(...). Adjust any code that
passes cfg.Containers or containers to validateLicenses to use the token-aware
container set.
cb71ed1 to
73f3a09
Compare
silv-io
left a comment
There was a problem hiding this comment.
LGTM! Just some thoughts that popped up
| return nil | ||
| } | ||
|
|
||
| func selectContainersToStart(ctx context.Context, rt runtime.Runtime, sink output.Sink, containers []runtime.ContainerConfig, cfgContainers []config.ContainerConfig) ([]runtime.ContainerConfig, []config.ContainerConfig, error) { |
There was a problem hiding this comment.
thought: that's a long line. Wild that gofmt doesn't split it up :) Maybe gofumpt would?
| var filtered []runtime.ContainerConfig | ||
| var filteredCfg []config.ContainerConfig |
There was a problem hiding this comment.
thought: I wonder if we could somehow compose those together so that we don't have to handle them separately, like having runtime.ContainerConfig contain config.ContainerConfig, somewhat like this:
type ContainerConfig struct {
Image string
Name string
Port string
HealthPath string
Env []string // e.g., ["KEY=value", "FOO=bar"]
*config.ContainerConfig
}
Not sure if it wouldn't make things annoying somewhere else though :)
| func checkPortAvailable(port string) error { | ||
| conn, err := net.DialTimeout("tcp", "localhost:"+port, time.Second) | ||
| if err != nil { | ||
| return nil | ||
| } | ||
| err = conn.Close() | ||
| if err != nil { | ||
| return nil | ||
| } | ||
| return fmt.Errorf("port %s already in use", port) | ||
| } |
There was a problem hiding this comment.
thought: I wonder if it makes sense to have that somewhere in a util/x, but we might only need it here.
Before pulling images or validating licenses,
lstk startnow checks the state of each configured container:"<name> is already running"and skips it. If all containers are already running, the command exits successfully without doing any work."port <N> already in use"with a hint pointing to the config file.