mirror of
https://github.com/chenasraf/sofmani.git
synced 2026-05-17 17:28:04 +00:00
feat(docker): add flag to skip if docker is not running
This commit is contained in:
@@ -26,6 +26,8 @@ type DockerOpts struct {
|
||||
Flags *string
|
||||
// Platform is a platform-specific map of Docker platform strings (e.g., "linux/amd64").
|
||||
Platform *platform.PlatformMap[string]
|
||||
// SkipIfUnavailable indicates whether to skip installation if Docker is unavailable.
|
||||
SkipIfUnavailable *bool
|
||||
}
|
||||
|
||||
// NewDockerInstaller creates a new DockerInstaller.
|
||||
@@ -45,11 +47,26 @@ func (i *DockerInstaller) Validate() []ValidationError {
|
||||
|
||||
// Install implements IInstaller.
|
||||
func (i *DockerInstaller) Install() error {
|
||||
if !isDockerAvailable() {
|
||||
if i.GetOpts().SkipIfUnavailable != nil && *i.GetOpts().SkipIfUnavailable {
|
||||
logger.Debug("Docker not available, skipping install")
|
||||
return nil
|
||||
}
|
||||
return fmt.Errorf("docker is not available")
|
||||
}
|
||||
return i.runOrStartContainer(false)
|
||||
}
|
||||
|
||||
// Update implements IInstaller.
|
||||
func (i *DockerInstaller) Update() error {
|
||||
if !isDockerAvailable() {
|
||||
if i.GetOpts().SkipIfUnavailable != nil && *i.GetOpts().SkipIfUnavailable {
|
||||
logger.Debug("Docker not available, skipping update")
|
||||
return nil
|
||||
}
|
||||
return fmt.Errorf("docker is not available")
|
||||
}
|
||||
|
||||
image := *i.Info.Name
|
||||
containerName := i.GetContainerName()
|
||||
|
||||
@@ -103,6 +120,9 @@ func (i *DockerInstaller) GetOpts() *DockerOpts {
|
||||
}
|
||||
}
|
||||
}
|
||||
if skip, ok := (*i.Info.Opts)["skip_if_unavailable"].(bool); ok {
|
||||
opts.SkipIfUnavailable = &skip
|
||||
}
|
||||
return opts
|
||||
}
|
||||
|
||||
@@ -188,3 +208,9 @@ func GetPlatformArchWithFallback(preferred string, fallbacks ...string) string {
|
||||
}
|
||||
return preferred
|
||||
}
|
||||
|
||||
// isDockerAvailable checks if Docker is available on the system.
|
||||
func isDockerAvailable() bool {
|
||||
err := exec.Command("docker", "info").Run()
|
||||
return err == nil
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user