Some checks failed
CI / build-and-test (push) Has been cancelled
Release / build (arm64, darwin) (push) Has been cancelled
Release / build (amd64, windows) (push) Has been cancelled
Release / build (arm64, linux) (push) Has been cancelled
Release / build (amd64, darwin) (push) Has been cancelled
Release / build (amd64, linux) (push) Has been cancelled
Release / release (push) Has been cancelled
Adds package-level documentation comments across cmd and internal packages. Marks unused function parameters with underscore prefix to satisfy linter requirements. Replaces if-else chains with switch statements for better readability. Explicitly ignores os.Setenv return value where error handling is not needed.
36 lines
726 B
Go
36 lines
726 B
Go
// Copyright 2023 The Gitea Authors. All rights reserved.
|
|
// SPDX-License-Identifier: MIT
|
|
|
|
package envcheck
|
|
|
|
import (
|
|
"context"
|
|
"fmt"
|
|
|
|
"github.com/docker/docker/client"
|
|
)
|
|
|
|
// CheckIfDockerRunning verifies that the Docker daemon is running and accessible.
|
|
func CheckIfDockerRunning(ctx context.Context, configDockerHost string) error {
|
|
opts := []client.Opt{
|
|
client.FromEnv,
|
|
}
|
|
|
|
if configDockerHost != "" {
|
|
opts = append(opts, client.WithHost(configDockerHost))
|
|
}
|
|
|
|
cli, err := client.NewClientWithOpts(opts...)
|
|
if err != nil {
|
|
return err
|
|
}
|
|
defer func() { _ = cli.Close() }()
|
|
|
|
_, err = cli.Ping(ctx)
|
|
if err != nil {
|
|
return fmt.Errorf("cannot ping the docker daemon, is it running? %w", err)
|
|
}
|
|
|
|
return nil
|
|
}
|