Revert breaking docker socket changes (#1763)
* fix: rework docker socket changes * fixup * fixup * fixes * patch * ... * lint * Fix docker outputs windows * fix type * Revert containerDaemonSocket breaking change --------- Co-authored-by: mergify[bot] <37929162+mergify[bot]@users.noreply.github.com>
This commit is contained in:
parent
baf3bcf48b
commit
7cbb1a910e
2 changed files with 56 additions and 15 deletions
47
cmd/root.go
47
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.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.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.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.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.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.")
|
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.")
|
||||||
|
@ -136,9 +136,9 @@ func socketLocation() (string, bool) {
|
||||||
for _, p := range commonSocketPaths {
|
for _, p := range commonSocketPaths {
|
||||||
if _, err := os.Lstat(os.ExpandEnv(p)); err == nil {
|
if _, err := os.Lstat(os.ExpandEnv(p)); err == nil {
|
||||||
if strings.HasPrefix(p, `\\.\`) {
|
if strings.HasPrefix(p, `\\.\`) {
|
||||||
return "npipe://" + os.ExpandEnv(p), true
|
return "npipe://" + filepath.ToSlash(os.ExpandEnv(p)), true
|
||||||
}
|
}
|
||||||
return "unix://" + os.ExpandEnv(p), true
|
return "unix://" + filepath.ToSlash(os.ExpandEnv(p)), true
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -350,6 +350,18 @@ func parseMatrix(matrix []string) map[string]map[string]bool {
|
||||||
return matrixes
|
return matrixes
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func isDockerHostURI(daemonPath string) bool {
|
||||||
|
if protoIndex := strings.Index(daemonPath, "://"); protoIndex != -1 {
|
||||||
|
scheme := daemonPath[:protoIndex]
|
||||||
|
if strings.IndexFunc(scheme, func(r rune) bool {
|
||||||
|
return (r < 'a' || r > 'z') && (r < 'A' || r > 'Z')
|
||||||
|
}) == -1 {
|
||||||
|
return true
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
|
||||||
//nolint:gocyclo
|
//nolint:gocyclo
|
||||||
func newRunCommand(ctx context.Context, input *Input) func(*cobra.Command, []string) error {
|
func newRunCommand(ctx context.Context, input *Input) func(*cobra.Command, []string) error {
|
||||||
return func(cmd *cobra.Command, args []string) error {
|
return func(cmd *cobra.Command, args []string) error {
|
||||||
|
@ -361,18 +373,27 @@ func newRunCommand(ctx context.Context, input *Input) func(*cobra.Command, []str
|
||||||
return bugReport(ctx, cmd.Version)
|
return bugReport(ctx, cmd.Version)
|
||||||
}
|
}
|
||||||
|
|
||||||
var socketPath string
|
// Prefer DOCKER_HOST, don't override it
|
||||||
if input.containerDaemonSocket != "" {
|
socketPath, hasDockerHost := os.LookupEnv("DOCKER_HOST")
|
||||||
socketPath = input.containerDaemonSocket
|
if !hasDockerHost {
|
||||||
} else {
|
// a - in containerDaemonSocket means don't mount, preserve this value
|
||||||
socket, found := socketLocation()
|
// otherwise if input.containerDaemonSocket is a filepath don't use it as socketPath
|
||||||
if !found && input.containerDaemonSocket == "" {
|
skipMount := input.containerDaemonSocket == "-" || !isDockerHostURI(input.containerDaemonSocket)
|
||||||
log.Errorln("daemon Docker Engine socket not found and containerDaemonSocket option was not set")
|
if input.containerDaemonSocket != "" && !skipMount {
|
||||||
|
socketPath = input.containerDaemonSocket
|
||||||
} else {
|
} 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 !skipMount {
|
||||||
|
input.containerDaemonSocket = socketPath
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
os.Setenv("DOCKER_HOST", socketPath)
|
||||||
}
|
}
|
||||||
os.Setenv("DOCKER_HOST", socketPath)
|
|
||||||
|
|
||||||
if runtime.GOOS == "darwin" && runtime.GOARCH == "arm64" && input.containerArchitecture == "" {
|
if runtime.GOOS == "darwin" && runtime.GOARCH == "arm64" && input.containerArchitecture == "" {
|
||||||
l := log.New()
|
l := log.New()
|
||||||
|
@ -565,7 +586,7 @@ func newRunCommand(ctx context.Context, input *Input) func(*cobra.Command, []str
|
||||||
Privileged: input.privileged,
|
Privileged: input.privileged,
|
||||||
UsernsMode: input.usernsMode,
|
UsernsMode: input.usernsMode,
|
||||||
ContainerArchitecture: input.containerArchitecture,
|
ContainerArchitecture: input.containerArchitecture,
|
||||||
ContainerDaemonSocket: socketPath,
|
ContainerDaemonSocket: input.containerDaemonSocket,
|
||||||
ContainerOptions: input.containerOptions,
|
ContainerOptions: input.containerOptions,
|
||||||
UseGitIgnore: input.useGitIgnore,
|
UseGitIgnore: input.useGitIgnore,
|
||||||
GitHubInstance: input.githubInstance,
|
GitHubInstance: input.githubInstance,
|
||||||
|
|
|
@ -87,6 +87,24 @@ func (rc *RunContext) jobContainerName() string {
|
||||||
return createContainerName("act", rc.String())
|
return createContainerName("act", rc.String())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func getDockerDaemonSocketMountPath(daemonPath string) string {
|
||||||
|
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
|
||||||
|
return "/var/run/docker.sock"
|
||||||
|
} else if strings.EqualFold(scheme, "unix") {
|
||||||
|
return daemonPath[protoIndex+3:]
|
||||||
|
} else if strings.IndexFunc(scheme, func(r rune) bool {
|
||||||
|
return (r < 'a' || r > 'z') && (r < 'A' || r > 'Z')
|
||||||
|
}) == -1 {
|
||||||
|
// unknown protocol use default
|
||||||
|
return "/var/run/docker.sock"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return daemonPath
|
||||||
|
}
|
||||||
|
|
||||||
// Returns the binds and mounts for the container, resolving paths as appopriate
|
// Returns the binds and mounts for the container, resolving paths as appopriate
|
||||||
func (rc *RunContext) GetBindsAndMounts() ([]string, map[string]string) {
|
func (rc *RunContext) GetBindsAndMounts() ([]string, map[string]string) {
|
||||||
name := rc.jobContainerName()
|
name := rc.jobContainerName()
|
||||||
|
@ -95,8 +113,10 @@ func (rc *RunContext) GetBindsAndMounts() ([]string, map[string]string) {
|
||||||
rc.Config.ContainerDaemonSocket = "/var/run/docker.sock"
|
rc.Config.ContainerDaemonSocket = "/var/run/docker.sock"
|
||||||
}
|
}
|
||||||
|
|
||||||
binds := []string{
|
binds := []string{}
|
||||||
fmt.Sprintf("%s:%s", rc.Config.ContainerDaemonSocket, "/var/run/docker.sock"),
|
if rc.Config.ContainerDaemonSocket != "-" {
|
||||||
|
daemonPath := getDockerDaemonSocketMountPath(rc.Config.ContainerDaemonSocket)
|
||||||
|
binds = append(binds, fmt.Sprintf("%s:%s", daemonPath, "/var/run/docker.sock"))
|
||||||
}
|
}
|
||||||
|
|
||||||
ext := container.LinuxContainerEnvironmentExtensions{}
|
ext := container.LinuxContainerEnvironmentExtensions{}
|
||||||
|
|
Loading…
Reference in a new issue