-
Notifications
You must be signed in to change notification settings - Fork 40
fix: wait for daemon readiness after auto-start #263
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
base: main
Are you sure you want to change the base?
Changes from all commits
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 |
|---|---|---|
|
|
@@ -46,9 +46,11 @@ type CLIOptions struct { | |
| } | ||
|
|
||
| var ( | ||
| cliOptions CLIOptions | ||
| registryURL string | ||
| registryToken string | ||
| cliOptions CLIOptions | ||
| registryURL string | ||
| registryToken string | ||
| // Package-level var so tests can stub out the real docker-compose check. | ||
| isDockerComposeAvailable = utils.IsDockerComposeAvailable | ||
| ) | ||
|
|
||
| // Configure applies options to the root command (e.g. for tests or alternate entry points). | ||
|
|
@@ -224,16 +226,8 @@ func preRunSetup(ctx context.Context, cmd *cobra.Command, baseURL, token string, | |
| } | ||
|
|
||
| if autoStartDaemon { | ||
| if !utils.IsDockerComposeAvailable() { | ||
| fmt.Println("Docker compose is not available. Please install docker compose and try again.") | ||
| fmt.Println("See https://docs.docker.com/compose/install/ for installation instructions.") | ||
| fmt.Println("agent registry uses docker compose to start the server and the agent gateway.") | ||
| return nil, fmt.Errorf("docker compose is not available") | ||
| } | ||
| if !dm.IsRunning() { | ||
| if err := dm.Start(); err != nil { | ||
| return nil, fmt.Errorf("failed to start daemon: %w", err) | ||
| } | ||
| if err := ensureDaemonRunning(dm, baseURL); err != nil { | ||
| return nil, err | ||
| } | ||
| } | ||
|
|
||
|
|
@@ -265,3 +259,22 @@ func preRunSetup(ctx context.Context, cmd *cobra.Command, baseURL, token string, | |
| } | ||
| return c, nil | ||
| } | ||
|
|
||
| func ensureDaemonRunning(dm types.DaemonManager, baseURL string) error { | ||
| if !isDockerComposeAvailable() { | ||
| fmt.Println("Docker compose is not available. Please install docker compose and try again.") | ||
| fmt.Println("See https://docs.docker.com/compose/install/ for installation instructions.") | ||
| fmt.Println("agent registry uses docker compose to start the server and the agent gateway.") | ||
| return fmt.Errorf("docker compose is not available") | ||
| } | ||
| if dm.IsRunning() { | ||
| return nil | ||
| } | ||
|
Comment on lines
+264
to
+272
Collaborator
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. Should this logic be flipped? We check if dm.IsRunning() first before validating whether docker compose is available in the env? |
||
| if err := dm.Start(); err != nil { | ||
| return fmt.Errorf("failed to start daemon: %w", err) | ||
| } | ||
| if err := dm.WaitForReady(baseURL); err != nil { | ||
| return fmt.Errorf("daemon started but not ready: %w", err) | ||
| } | ||
| return nil | ||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -152,6 +152,8 @@ type DaemonManager interface { | |
| IsRunning() bool | ||
| // Start starts the daemon, blocking until it's ready | ||
| Start() error | ||
| // WaitForReady polls the daemon API until it responds or the timeout expires | ||
| WaitForReady(baseURL string) error | ||
|
Comment on lines
+155
to
+156
Collaborator
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. We already have IsRunning & Start methods defined for this interface. Wondering whether it makes sense to deflate this method into Start() since we already call --wait on docker compose. The one benefit is being able to call Start and then WaitForReady by consumers of this interface but the value seems low. Overall, fine with extending this for now. I think there's some other cruft in this interface that's worth addressing first. |
||
| } | ||
|
|
||
| // CLIAuthnProvider provides authentication for CLI commands. | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fine for now - I think this indicates a clear smell with the daemon manager component though. The interface should abstract whether docker compose is available, or we define something like a no-op daemon manager and call the right constructor in the CLI run logic, etc.