Skip to content

Commit

Permalink
fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
ChristopherHX authored and github-actions committed Apr 25, 2023
1 parent 12f6f15 commit 6277722
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 11 deletions.
11 changes: 6 additions & 5 deletions cmd/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -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.")
Expand Down Expand Up @@ -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()
Expand All @@ -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
}
}
Expand Down
17 changes: 11 additions & 6 deletions pkg/runner/run_context.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@ import (
"regexp"
"runtime"
"strings"
"net/url"

"github.com/opencontainers/selinux/go-selinux"

Expand Down Expand Up @@ -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"))
Expand Down

0 comments on commit 6277722

Please sign in to comment.