054c8d912f
Follow #242. Move `docker.host` to `container.docker_host`. There are already some options for docker/container in `container`, so developers could get confused about where to add options. It's breaking, but I think it's OK since `docker.host` was added just two days ago. Reviewed-on: https://gitea.com/gitea/act_runner/pulls/244 Reviewed-by: Lunny Xiao <xiaolunwen@gmail.com>
36 lines
690 B
Go
36 lines
690 B
Go
// Copyright 2023 The Gitea Authors. All rights reserved.
|
|
// SPDX-License-Identifier: MIT
|
|
|
|
package envcheck
|
|
|
|
import (
|
|
"context"
|
|
"fmt"
|
|
|
|
"github.com/docker/docker/client"
|
|
|
|
"gitea.com/gitea/act_runner/internal/pkg/config"
|
|
)
|
|
|
|
func CheckIfDockerRunning(ctx context.Context, cfg *config.Config) error {
|
|
opts := []client.Opt{
|
|
client.FromEnv,
|
|
}
|
|
|
|
if cfg.Container.DockerHost != "" {
|
|
opts = append(opts, client.WithHost(cfg.Container.DockerHost))
|
|
}
|
|
|
|
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
|
|
}
|