2023-04-04 13:32:04 +00:00
|
|
|
// Copyright 2023 The Gitea Authors. All rights reserved.
|
|
|
|
// SPDX-License-Identifier: MIT
|
|
|
|
|
|
|
|
package envcheck
|
|
|
|
|
|
|
|
import (
|
|
|
|
"context"
|
|
|
|
"fmt"
|
|
|
|
|
2023-06-18 05:38:38 +00:00
|
|
|
"gitea.com/gitea/act_runner/internal/pkg/config"
|
|
|
|
|
2023-04-04 13:32:04 +00:00
|
|
|
"github.com/docker/docker/client"
|
|
|
|
)
|
|
|
|
|
2023-06-18 05:38:38 +00:00
|
|
|
func CheckIfDockerRunning(ctx context.Context, cfg *config.Config) error {
|
|
|
|
opts := []client.Opt{
|
|
|
|
client.FromEnv,
|
|
|
|
}
|
|
|
|
|
|
|
|
if cfg.Docker.Host != "" {
|
|
|
|
opts = append(opts, client.WithHost(cfg.Docker.Host))
|
|
|
|
}
|
|
|
|
|
|
|
|
cli, err := client.NewClientWithOpts(opts...)
|
2023-04-04 13:32:04 +00:00
|
|
|
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
|
|
|
|
}
|