From e0074d7c41708cc388452691cd720da81423c90e Mon Sep 17 00:00:00 2001 From: bjarneo Date: Fri, 15 Nov 2024 17:35:10 +0100 Subject: [PATCH] chore: check if docker runs remotely If not, return an error message --- main.go | 20 +++++++++++++++----- 1 file changed, 15 insertions(+), 5 deletions(-) diff --git a/main.go b/main.go index 837a91e..efde5b5 100644 --- a/main.go +++ b/main.go @@ -251,10 +251,20 @@ func ExecuteCommand(logger *Logger, command string, description string) (*Comman return result, nil } -// CheckDocker checks if Docker is installed and running -func CheckDocker(logger *Logger) error { - _, err := ExecuteCommand(logger, "docker info", "Checking Docker installation") - return err +// CheckDocker checks if Docker is installed and running locally and remotely +func CheckDocker(config *Config, logger *Logger) error { + // Check local Docker + if _, err := ExecuteCommand(logger, "docker info", "Checking local Docker installation"); err != nil { + return fmt.Errorf("local Docker check failed: %v", err) + } + + // Check remote Docker + remoteCmd := fmt.Sprintf("%s \"docker info\"", getSSHCommand(config)) + if _, err := ExecuteCommand(logger, remoteCmd, "Checking remote Docker installation"); err != nil { + return fmt.Errorf("remote Docker check failed - please ensure Docker is installed on %s: %v", config.Host, err) + } + + return nil } // getSSHKeyFlag returns the SSH key flag if SSHKey is set @@ -419,7 +429,7 @@ func Deploy(config *Config, logger *Logger) error { } // Preliminary checks - if err := CheckDocker(logger); err != nil { + if err := CheckDocker(config, logger); err != nil { return err }