act_runner/internal/pkg/envcheck/docker.go
appleboy 56a7c930f8 feat: improve Docker configuration and detection handling
- Pass `cfg` to `envcheck.CheckIfDockerRunning` function
- Add `Docker` struct to `config.go` for Docker configuration
- Update `config.example.yaml` with `docker` configuration options
- Modify `CheckIfDockerRunning` in `docker.go` to use Docker host from config if provided

Signed-off-by: appleboy <appleboy.tw@gmail.com>
2023-06-17 06:27:10 +08:00

37 lines
672 B
Go

// Copyright 2023 The Gitea Authors. All rights reserved.
// SPDX-License-Identifier: MIT
package envcheck
import (
"context"
"fmt"
"gitea.com/gitea/act_runner/internal/pkg/config"
"github.com/docker/docker/client"
)
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...)
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
}