1
0
Fork 0
mirror of https://code.forgejo.org/forgejo/runner.git synced 2025-06-27 16:35:58 +00:00

cmd: exec: prefer docker socket path from DOCKER_HOST if specified

It's somewhat undocumented from the Docker side, but e.g. a common
solution when using podman to provide better compatibility with Docker.

See e.g.
https://podman-desktop.io/docs/migrating-from-docker/using-the-docker_host-environment-variable

Signed-off-by: Christoph Heiss <christoph@c8h4.io>
This commit is contained in:
Christoph Heiss 2025-06-09 12:05:42 +02:00
parent bb7c40a384
commit df8c6d39cb
No known key found for this signature in database
GPG key ID: 73D5E7FDEE3DE49A

View file

@ -448,6 +448,17 @@ func runExec(ctx context.Context, execArgs *executeArgs) func(cmd *cobra.Command
}
}
func defaultDockerDaemonSocket() string {
// (At least) Podman and Docker use the socket from $DOCKER_HOST if specified,
// so prefer it here over the default path too.
dockerHost := os.Getenv("DOCKER_HOST")
if dockerHost != "" {
return dockerHost
} else {
return "/var/run/docker.sock"
}
}
func loadExecCmd(ctx context.Context) *cobra.Command {
execArg := executeArgs{}
@ -475,7 +486,7 @@ func loadExecCmd(ctx context.Context) *cobra.Command {
execCmd.Flags().BoolVar(&execArg.privileged, "privileged", false, "use privileged mode")
execCmd.Flags().StringVar(&execArg.usernsMode, "userns", "", "user namespace to use")
execCmd.PersistentFlags().StringVarP(&execArg.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.")
execCmd.PersistentFlags().StringVarP(&execArg.containerDaemonSocket, "container-daemon-socket", "", "/var/run/docker.sock", "Path to Docker daemon socket which will be mounted to containers")
execCmd.PersistentFlags().StringVarP(&execArg.containerDaemonSocket, "container-daemon-socket", "", defaultDockerDaemonSocket(), "Path to Docker daemon socket which will be mounted to containers")
execCmd.Flags().BoolVar(&execArg.useGitIgnore, "use-gitignore", true, "Controls whether paths specified in .gitignore should be copied into container")
execCmd.Flags().StringArrayVarP(&execArg.containerCapAdd, "container-cap-add", "", []string{}, "kernel capabilities to add to the workflow containers (e.g. --container-cap-add SYS_PTRACE)")
execCmd.Flags().StringArrayVarP(&execArg.containerCapDrop, "container-cap-drop", "", []string{}, "kernel capabilities to remove from the workflow containers (e.g. --container-cap-drop SYS_PTRACE)")