-
Notifications
You must be signed in to change notification settings - Fork 126
[Spacetime] Enhance errors #2779
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 | ||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
@@ -190,3 +190,20 @@ func Copy(containerName, containerPath, localPath string) error { | |||||||||||||||
} | ||||||||||||||||
return nil | ||||||||||||||||
} | ||||||||||||||||
|
||||||||||||||||
// CheckDaemonRunning checks if the Docker daemon is running. | ||||||||||||||||
// Returns nil if the daemon is running, or an error if it's not. | ||||||||||||||||
func CheckDaemonRunning() error { | ||||||||||||||||
cmd := exec.Command("docker", "info") | ||||||||||||||||
errOutput := new(bytes.Buffer) | ||||||||||||||||
cmd.Stderr = errOutput | ||||||||||||||||
|
||||||||||||||||
logger.Debugf("running command to check Docker daemon: %s", cmd) | ||||||||||||||||
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. I'd use Trace level for this message
Suggested change
|
||||||||||||||||
if err := cmd.Run(); err != nil { | ||||||||||||||||
daemonError := fmt.Errorf("docker daemon is not running (stderr=%q): %w", errOutput.String(), err) | ||||||||||||||||
logger.Error(": Docker daemon is not running or not accessible") | ||||||||||||||||
logger.Error(": Please make sure Docker is installed and running before executing commands that require Docker") | ||||||||||||||||
Comment on lines
+204
to
+205
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. This is an internal method. I would prefer to log closer to the user.
Suggested change
|
||||||||||||||||
return daemonError | ||||||||||||||||
Comment on lines
+203
to
+206
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. Nit. You can directly return the error.
Suggested change
|
||||||||||||||||
} | ||||||||||||||||
return nil | ||||||||||||||||
} |
Original file line number | Diff line number | Diff line change | ||
---|---|---|---|---|
|
@@ -12,6 +12,7 @@ import ( | |||
"github.com/elastic/elastic-package/internal/compose" | ||||
"github.com/elastic/elastic-package/internal/docker" | ||||
"github.com/elastic/elastic-package/internal/install" | ||||
"github.com/elastic/elastic-package/internal/logger" | ||||
) | ||||
|
||||
type ServiceStatus struct { | ||||
|
@@ -50,7 +51,18 @@ func (eb *envBuilder) build() []string { | |||
return eb.vars | ||||
} | ||||
|
||||
// CheckDockerRunning verifies that the Docker daemon is running before executing Docker operations | ||||
func CheckDockerRunning() error { | ||||
logger.Debug("Checking if Docker daemon is running...") | ||||
return docker.CheckDaemonRunning() | ||||
} | ||||
|
||||
func dockerComposeBuild(ctx context.Context, options Options) error { | ||||
// Check if Docker daemon is running | ||||
if err := CheckDockerRunning(); err != nil { | ||||
return err | ||||
} | ||||
|
||||
c, err := compose.NewProject(DockerComposeProjectName(options.Profile), options.Profile.Path(ProfileStackPath, ComposeFile)) | ||||
if err != nil { | ||||
return fmt.Errorf("could not create docker compose project: %w", err) | ||||
|
@@ -77,6 +89,11 @@ func dockerComposeBuild(ctx context.Context, options Options) error { | |||
} | ||||
|
||||
func dockerComposePull(ctx context.Context, options Options) error { | ||||
// Check if Docker daemon is running | ||||
if err := CheckDockerRunning(); err != nil { | ||||
return err | ||||
} | ||||
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. Instead of having to check it on every operation, I think we could create a new
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. I think the other providers (Environment and Serverless) could take advantage of this check too. IIRC these two providers run also docker (docker-compose) commands. Just thinking that doing this check in the providers makes that elastic-package test or install commands do not run this check. |
||||
|
||||
c, err := compose.NewProject(DockerComposeProjectName(options.Profile), options.Profile.Path(ProfileStackPath, ComposeFile)) | ||||
if err != nil { | ||||
return fmt.Errorf("could not create docker compose project: %w", err) | ||||
|
@@ -103,6 +120,11 @@ func dockerComposePull(ctx context.Context, options Options) error { | |||
} | ||||
|
||||
func dockerComposeUp(ctx context.Context, options Options) error { | ||||
// Check if Docker daemon is running | ||||
if err := CheckDockerRunning(); err != nil { | ||||
return err | ||||
} | ||||
|
||||
c, err := compose.NewProject(DockerComposeProjectName(options.Profile), options.Profile.Path(ProfileStackPath, ComposeFile)) | ||||
if err != nil { | ||||
return fmt.Errorf("could not create docker compose project: %w", err) | ||||
|
@@ -135,6 +157,11 @@ func dockerComposeUp(ctx context.Context, options Options) error { | |||
} | ||||
|
||||
func dockerComposeDown(ctx context.Context, options Options) error { | ||||
// Check if Docker daemon is running | ||||
if err := CheckDockerRunning(); err != nil { | ||||
return err | ||||
} | ||||
|
||||
c, err := compose.NewProject(DockerComposeProjectName(options.Profile), options.Profile.Path(ProfileStackPath, ComposeFile)) | ||||
if err != nil { | ||||
return fmt.Errorf("could not create docker compose project: %w", err) | ||||
|
Uh oh!
There was an error while loading. Please reload this page.
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.
This commands has a large output. It should not be an issue, but maybe it could be format the output to just shown a specific value (e.g.
ServerVersion
).