feat: implement ssh forwarding

This commit is contained in:
2024-11-17 18:10:35 +00:00
parent a7933f8b06
commit 45bfbe093a
21 changed files with 1175 additions and 296 deletions

21
internal/docker/docker.go Normal file
View File

@@ -0,0 +1,21 @@
package docker
import (
"context"
"github.com/docker/docker/api/types"
"github.com/docker/go-connections/nat"
"strconv"
)
// ContainerSSHHostPort returns the port on the host that is exposing the internal ssh port of the given container info
func ContainerSSHHostPort(ctx context.Context, container types.ContainerJSON) int {
ports := container.NetworkSettings.Ports[nat.Port("22/tcp")]
if len(ports) == 0 {
return -1
}
port, err := strconv.Atoi(ports[0].HostPort)
if err != nil {
return -1
}
return port
}