From 6277722f45fbe9ce7d92e106fdf3f65d564814df Mon Sep 17 00:00:00 2001 From: Christopher Homberger Date: Mon, 24 Apr 2023 20:08:48 +0200 Subject: [PATCH] fixes --- cmd/root.go | 11 ++++++----- pkg/runner/run_context.go | 17 +++++++++++------ 2 files changed, 17 insertions(+), 11 deletions(-) diff --git a/cmd/root.go b/cmd/root.go index 7e6a29da90e..ce18fcfc84f 100644 --- a/cmd/root.go +++ b/cmd/root.go @@ -80,7 +80,7 @@ func Execute(ctx context.Context, version string) { rootCmd.PersistentFlags().StringVarP(&input.envfile, "env-file", "", ".env", "environment file to read and use as env in the containers") rootCmd.PersistentFlags().StringVarP(&input.inputfile, "input-file", "", ".input", "input file to read and use as action input") rootCmd.PersistentFlags().StringVarP(&input.containerArchitecture, "container-architecture", "", "", "Architecture which should be used to run containers, e.g.: linux/amd64. If not specified, will use host default architecture. Requires Docker server API Version 1.41+. Ignored on earlier Docker server platforms.") - rootCmd.PersistentFlags().StringVarP(&input.containerDaemonSocket, "container-daemon-socket", "", "", "URI to Docker Engine socket (e.g.: unix://~/.docker/run/docker.sock)") + rootCmd.PersistentFlags().StringVarP(&input.containerDaemonSocket, "container-daemon-socket", "", "", "URI to Docker Engine socket (e.g.: unix://~/.docker/run/docker.sock or - to disable bind mounting the socket)") rootCmd.PersistentFlags().StringVarP(&input.containerOptions, "container-options", "", "", "Custom docker container options for the job container without an options property in the job definition") rootCmd.PersistentFlags().StringVarP(&input.githubInstance, "github-instance", "", "github.com", "GitHub instance to use. Don't use this if you are not using GitHub Enterprise Server.") rootCmd.PersistentFlags().StringVarP(&input.artifactServerPath, "artifact-server-path", "", "", "Defines the path where the artifact server stores uploads and retrieves downloads from. If not specified the artifact server will not start.") @@ -361,11 +361,12 @@ func newRunCommand(ctx context.Context, input *Input) func(*cobra.Command, []str return bugReport(ctx, cmd.Version) } - // Prefer DOCKER_HOST - socketPath, hasDockerHost := os.GetEnv("DOCKER_HOST") + // Prefer DOCKER_HOST, don't override it + socketPath, hasDockerHost := os.LookupEnv("DOCKER_HOST") if !hasDockerHost { // a - in containerDaemonSocket means don't mount, preserve this value - if input.containerDaemonSocket != "" && rc.Config.ContainerDaemonSocket != "-" { + skipMount := input.containerDaemonSocket == "-" + if input.containerDaemonSocket != "" && !skipMount { socketPath = input.containerDaemonSocket } else { socket, found := socketLocation() @@ -374,7 +375,7 @@ func newRunCommand(ctx context.Context, input *Input) func(*cobra.Command, []str } else { socketPath = socket } - if rc.Config.ContainerDaemonSocket != "-" { + if !skipMount { input.containerDaemonSocket = socketPath } } diff --git a/pkg/runner/run_context.go b/pkg/runner/run_context.go index c963fd7ddf4..25b0ac9eee8 100644 --- a/pkg/runner/run_context.go +++ b/pkg/runner/run_context.go @@ -16,7 +16,6 @@ import ( "regexp" "runtime" "strings" - "net/url" "github.com/opencontainers/selinux/go-selinux" @@ -98,14 +97,20 @@ func (rc *RunContext) GetBindsAndMounts() ([]string, map[string]string) { binds := []string{} if rc.Config.ContainerDaemonSocket != "-" { - daemonPathUri, err := url.Parse(rc.Config.ContainerDaemonSocket) daemonPath := rc.Config.ContainerDaemonSocket - if err != nil { - if daemonPathUri.Scheme == "npipe" { + + if protoIndex := strings.Index(daemonPath, "://"); protoIndex != -1 { + scheme := daemonPath[:protoIndex] + if strings.EqualFold(scheme, "npipe") { // linux container mount on windows, use the default socket path of the VM / wsl2 daemonPath = "/var/run/docker.sock" - } else if daemonPathUri.Scheme == "unix" { - daemonPath = filepath.Join(daemonPathUri.Host, daemonPathUri.Path) + } else if strings.EqualFold(scheme, "unix") { + daemonPath = daemonPath[protoIndex+2:] + } else if strings.IndexFunc(scheme, func(r rune) bool { + return (r < 'a' || r > 'z') && (r < 'A' || r > 'Z') + }) == -1 { + // unknown protocol use default + daemonPath = "/var/run/docker.sock" } } binds = append(binds, fmt.Sprintf("%s:%s", daemonPath, "/var/run/docker.sock"))