forked from Ivasoft/github-actions
Link hidden docker socket to the expected path
All checks were successful
continuous-integration/drone/push Build is passing
All checks were successful
continuous-integration/drone/push Build is passing
This commit is contained in:
@@ -4,6 +4,14 @@ import (
|
|||||||
"fmt"
|
"fmt"
|
||||||
"os/exec"
|
"os/exec"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
|
"github.com/pkg/errors"
|
||||||
|
"os"
|
||||||
|
)
|
||||||
|
|
||||||
|
const (
|
||||||
|
StdDockerSocketPath = "/var/run/docker.sock"
|
||||||
|
HiddenDockerSocketPath = "/var/run/hidden_docker.sock"
|
||||||
)
|
)
|
||||||
|
|
||||||
type Daemon struct {
|
type Daemon struct {
|
||||||
@@ -26,6 +34,10 @@ type Daemon struct {
|
|||||||
func StartDaemon(d Daemon) error {
|
func StartDaemon(d Daemon) error {
|
||||||
if !d.Disabled {
|
if !d.Disabled {
|
||||||
startDaemon(d)
|
startDaemon(d)
|
||||||
|
} else if !d.NotHiddenSocket {
|
||||||
|
if err := os.Link(HiddenDockerSocketPath, StdDockerSocketPath); err != nil {
|
||||||
|
return errors.Wrap(err, "failed to link hidden docker socket to common one")
|
||||||
|
}
|
||||||
}
|
}
|
||||||
return waitForDaemon()
|
return waitForDaemon()
|
||||||
}
|
}
|
||||||
|
|||||||
17
plugin.go
17
plugin.go
@@ -24,9 +24,6 @@ const (
|
|||||||
secretFile = "/tmp/action.secrets"
|
secretFile = "/tmp/action.secrets"
|
||||||
workflowFile = "/tmp/workflow.yml"
|
workflowFile = "/tmp/workflow.yml"
|
||||||
eventPayloadFile = "/tmp/event.json"
|
eventPayloadFile = "/tmp/event.json"
|
||||||
|
|
||||||
stdDockerSocketPath = "/var/run/docker.sock"
|
|
||||||
hiddenDockerSocketPath = "/var/run/hidden_docker.sock"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
var (
|
var (
|
||||||
@@ -120,10 +117,6 @@ func (p Plugin) Exec() error {
|
|||||||
cmd.Stderr = os.Stderr
|
cmd.Stderr = os.Stderr
|
||||||
trace(cmd)
|
trace(cmd)
|
||||||
|
|
||||||
if p.Daemon.Disabled && !p.Daemon.NotHiddenSocket {
|
|
||||||
cmd.Env = append(os.Environ(), fmt.Sprintf("DOCKER_HOST=%s", "unix://" + hiddenDockerSocketPath))
|
|
||||||
}
|
|
||||||
|
|
||||||
err := cmd.Run()
|
err := cmd.Run()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
@@ -139,15 +132,7 @@ func trace(cmd *exec.Cmd) {
|
|||||||
|
|
||||||
func getWorkDirPath(p Plugin, ctx context.Context) (string, string, error) {
|
func getWorkDirPath(p Plugin, ctx context.Context) (string, string, error) {
|
||||||
// Connect to the docker
|
// Connect to the docker
|
||||||
// Note: We use a custom "hidden" socket path
|
docker, err := docker.NewClient("unix://" + daemon.StdDockerSocketPath, "v1.13.1", nil, nil)
|
||||||
dockerSockPath := ""
|
|
||||||
if p.Daemon.NotHiddenSocket {
|
|
||||||
dockerSockPath = stdDockerSocketPath
|
|
||||||
} else {
|
|
||||||
dockerSockPath = hiddenDockerSocketPath
|
|
||||||
}
|
|
||||||
|
|
||||||
docker, err := docker.NewClient("unix://" + dockerSockPath, "v1.13.1", nil, nil)
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return "", "", errors.Wrap(err, "failed to create docker client")
|
return "", "", errors.Wrap(err, "failed to create docker client")
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user