Skip to content

Commit

Permalink
fix: rework docker socket changes
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 8167b77 commit 3a2d703
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 11 deletions.
25 changes: 16 additions & 9 deletions cmd/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -361,18 +361,25 @@ func newRunCommand(ctx context.Context, input *Input) func(*cobra.Command, []str
return bugReport(ctx, cmd.Version)
}

var socketPath string
if input.containerDaemonSocket != "" {
socketPath = input.containerDaemonSocket
} else {
socket, found := socketLocation()
if !found && input.containerDaemonSocket == "" {
log.Errorln("daemon Docker Engine socket not found and containerDaemonSocket option was not set")
// Prefer DOCKER_HOST
socketPath, hasDockerHost := os.GetEnv("DOCKER_HOST")
if !hasDockerHost {
// a - in containerDaemonSocket means don't mount, preserve this value
if input.containerDaemonSocket != "" && rc.Config.ContainerDaemonSocket != "-" {
socketPath = input.containerDaemonSocket
} else {
socketPath = socket
socket, found := socketLocation()
if !found {
log.Errorln("daemon Docker Engine socket not found and containerDaemonSocket option was not set")
} else {
socketPath = socket
}
if rc.Config.ContainerDaemonSocket != "-" {
input.containerDaemonSocket = socketPath
}
}
os.Setenv("DOCKER_HOST", socketPath)
}
os.Setenv("DOCKER_HOST", socketPath)

if runtime.GOOS == "darwin" && runtime.GOARCH == "arm64" && input.containerArchitecture == "" {
l := log.New()
Expand Down
18 changes: 16 additions & 2 deletions pkg/runner/run_context.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ import (
"regexp"
"runtime"
"strings"
"net/url"

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

Expand Down Expand Up @@ -95,8 +96,21 @@ func (rc *RunContext) GetBindsAndMounts() ([]string, map[string]string) {
rc.Config.ContainerDaemonSocket = "/var/run/docker.sock"
}

binds := []string{
fmt.Sprintf("%s:%s", rc.Config.ContainerDaemonSocket, "/var/run/docker.sock"),
binds := []string{}
if rc.Config.ContainerDaemonSocket != "-" {
daemonPathUri, err := url.Parse(rc.Config.ContainerDaemonSocket)
daemonPath := rc.Config.ContainerDaemonSocket
err != nil
if daemonPathUri.Scheme == "npipe" {
// linux container mount on windows, use the default socket path
daemonPath = "/var/run/docker.sock"
} else if daemonPathUri.Scheme == "unix" {
daemonPath = filepath.Join(daemonPathUri.Host, daemonPathUri.Path)
}
// Only bind mount the socket if it exists, e.g.
if daemonPathInfo, err := os.Stat(daemonPath); err == nil {
binds = append(binds, fmt.Sprintf("%s:%s", rc.Config.ContainerDaemonSocket, "/var/run/docker.sock"))
}
}

ext := container.LinuxContainerEnvironmentExtensions{}
Expand Down

0 comments on commit 3a2d703

Please sign in to comment.