From f2629f2ea3cbf665dc32961671dfb5a8f629e601 Mon Sep 17 00:00:00 2001 From: Zettat123 Date: Sat, 1 Jul 2023 01:27:54 +0000 Subject: [PATCH] Add support for finding docker daemon from common socket paths (#263) Caused by #260 act_runner will fail to start if user does not set `docker_host` configuration and `DOCKER_HOST` env. This PR adds the support for finding docker daemon from common socket paths so act_runner could detect the docker socket from these paths. The `commonSocketPaths` is from [nektos/act](https://github.com/nektos/act/blob/e60018a6d9403b27bfd1a1ed6111a6e9de0032fd/cmd/root.go#L124-L131) Reviewed-on: https://gitea.com/gitea/act_runner/pulls/263 Co-authored-by: Zettat123 Co-committed-by: Zettat123 --- internal/app/cmd/daemon.go | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/internal/app/cmd/daemon.go b/internal/app/cmd/daemon.go index 05c80a2..d579739 100644 --- a/internal/app/cmd/daemon.go +++ b/internal/app/cmd/daemon.go @@ -8,6 +8,7 @@ import ( "fmt" "os" "path" + "path/filepath" "runtime" "strconv" "strings" @@ -160,6 +161,15 @@ func initLogging(cfg *config.Config) { } } +var commonSocketPaths = []string{ + "/var/run/docker.sock", + "/var/run/podman/podman.sock", + "$HOME/.colima/docker.sock", + "$XDG_RUNTIME_DIR/docker.sock", + `\\.\pipe\docker_engine`, + "$HOME/.docker/run/docker.sock", +} + func getDockerSocketPath(configDockerHost string) (string, error) { // a `-` means don't mount the docker socket to job containers if configDockerHost != "" && configDockerHost != "-" { @@ -171,5 +181,14 @@ func getDockerSocketPath(configDockerHost string) (string, error) { return socket, nil } + for _, p := range commonSocketPaths { + if _, err := os.Lstat(os.ExpandEnv(p)); err == nil { + if strings.HasPrefix(p, `\\.\`) { + return "npipe://" + filepath.ToSlash(os.ExpandEnv(p)), nil + } + return "unix://" + filepath.ToSlash(os.ExpandEnv(p)), nil + } + } + return "", fmt.Errorf("daemon Docker Engine socket not found and docker_host config was invalid") }