Improve the usage of docker_host configuration (#260)

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>
This commit is contained in:
Zettat123
2023-06-30 04:00:04 +00:00
committed by Jason Song
parent b0bd503b11
commit ccc27329dc
4 changed files with 62 additions and 29 deletions

View File

@ -8,17 +8,15 @@ import (
"fmt"
"github.com/docker/docker/client"
"gitea.com/gitea/act_runner/internal/pkg/config"
)
func CheckIfDockerRunning(ctx context.Context, cfg *config.Config) error {
func CheckIfDockerRunning(ctx context.Context, configDockerHost string) error {
opts := []client.Opt{
client.FromEnv,
}
if cfg.Container.DockerHost != "" {
opts = append(opts, client.WithHost(cfg.Container.DockerHost))
if configDockerHost != "" {
opts = append(opts, client.WithHost(configDockerHost))
}
cli, err := client.NewClientWithOpts(opts...)