mirror of
https://code.forgejo.org/forgejo/runner.git
synced 2024-12-18 11:52:16 +03:00
ccc27329dc
Follow #242, #244 Fixes #258 Users could use `docker_host` configuration to specify which docker daemon will be used by act_runner. - If `docker_host` is **empty**, act_runner will find an available docker host automatically. - If `docker_host` is **"-"**, act_runner will find an available docker host automatically, but the docker host won't be mounted to the job containers and service containers. - If `docker_host` is **not empty or "-"**, the specified docker host will be used. An error will be returned if it doesn't work. Reviewed-on: https://gitea.com/gitea/act_runner/pulls/260 Co-authored-by: Zettat123 <zettat123@gmail.com> Co-committed-by: Zettat123 <zettat123@gmail.com>
34 lines
628 B
Go
34 lines
628 B
Go
// Copyright 2023 The Gitea Authors. All rights reserved.
|
|
// SPDX-License-Identifier: MIT
|
|
|
|
package envcheck
|
|
|
|
import (
|
|
"context"
|
|
"fmt"
|
|
|
|
"github.com/docker/docker/client"
|
|
)
|
|
|
|
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 cli.Close()
|
|
|
|
_, err = cli.Ping(ctx)
|
|
if err != nil {
|
|
return fmt.Errorf("cannot ping the docker daemon, does it running? %w", err)
|
|
}
|
|
|
|
return nil
|
|
}
|