Merge pull request #511 from rajiv-k/docker-host-ssh

fix: Properly support remote docker daemon over ssh
This commit is contained in:
Jesse Duffield 2024-05-30 23:15:50 +10:00 committed by GitHub
commit 06ab7b77b1
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -28,7 +28,8 @@ import (
)
const (
APIVersion = "1.25"
APIVersion = "1.25"
dockerHostEnvKey = "DOCKER_HOST"
)
// DockerCommand is our main docker interface
@ -72,14 +73,28 @@ func (c *DockerCommand) NewCommandObject(obj CommandObject) CommandObject {
// NewDockerCommand it runs docker commands
func NewDockerCommand(log *logrus.Entry, osCommand *OSCommand, tr *i18n.TranslationSet, config *config.AppConfig, errorChan chan error) (*DockerCommand, error) {
dockerHost, err := determineDockerHost()
if err != nil {
ogLog.Printf("> could not determine host %v", err)
}
// NOTE: Inject the determined docker host to the environment. This allows the
// `SSHHandler.HandleSSHDockerHost()` to create a local unix socket tunneled
// over SSH to the specified ssh host.
if strings.HasPrefix(dockerHost, "ssh://") {
os.Setenv(dockerHostEnvKey, dockerHost)
}
tunnelCloser, err := ssh.NewSSHHandler(osCommand).HandleSSHDockerHost()
if err != nil {
ogLog.Fatal(err)
}
dockerHost, err := determineDockerHost()
if err != nil {
ogLog.Printf("> could not determine host %v", err)
// Retrieve the docker host from the environment which could have been set by
// the `SSHHandler.HandleSSHDockerHost()` and override `dockerHost`.
dockerHostFromEnv := os.Getenv(dockerHostEnvKey)
if dockerHostFromEnv != "" {
dockerHost = dockerHostFromEnv
}
cli, err := client.NewClientWithOpts(client.FromEnv, client.WithVersion(APIVersion), client.WithHost(dockerHost))