feat: improve Docker configuration and detection handling (#242)

- 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 <[email protected]>

Reviewed-on: https://gitea.com/gitea/act_runner/pulls/242
Reviewed-by: Lunny Xiao <[email protected]>
Reviewed-by: wxiaoguang <[email protected]>
Co-authored-by: appleboy <[email protected]>
Co-committed-by: appleboy <[email protected]>
This commit is contained in:
appleboy authored and Lunny Xiao committed 2023-06-18 05:38:38 +00:00
1 parent ec38401097
commit 9e4a5f7363
4 files changed
+25 -4

No files matched your search

+12 -3
View File
@@ -7,12 +7,21 @@ import (
"context"
"fmt"
"gitea.com/gitea/act_runner/internal/pkg/config"
"github.com/docker/docker/client"
)
func CheckIfDockerRunning(ctx context.Context) error {
// TODO: if runner support configures to use docker, we need config.Config to pass in
cli, err := client.NewClientWithOpts(client.FromEnv)
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
}