-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
4 changed files
with
32 additions
and
25 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -28,3 +28,7 @@ dcip export [email protected] main_pg:5432 0.0.0.0:5432 | |
# 可省略本地端口以及监听地址, 监听地址默认是 0.0.0.0, 本地端口默认为容器端口 | ||
dcip export [email protected] main_pg:5432 | ||
``` | ||
|
||
## 进阶使用 | ||
|
||
现在可以在 host 上传递 ssh options 了, 示例: `dcip of ' -J cn-host usa-host' pg`, 用法就是加上单引号并且使用空格开头 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -12,15 +12,15 @@ import ( | |
|
||
var CLI struct { | ||
Of struct { | ||
Host string `arg name:"[host|name]" passthrough help:"remote host optional or just a container name"` | ||
Container string `arg name:"name" optional help:"container name"` | ||
} `cmd help:"get container ip."` | ||
Host string `arg:"" name:"[host|name]" help:"remote host optional or just a container name"` | ||
Container string `arg:"" name:"name" optional:"" help:"container name"` | ||
} `cmd:"" passthrough:"" help:"get container ip."` | ||
Export struct { | ||
Host string `arg name:"host" passthrough help:"ssh host. example: [email protected]"` | ||
ContainerPort string `arg name:"cport" help:"remote container name and port. example: pg:5432"` | ||
LocalAddr string `arg name:"lport" optional help:"local bind address and port. default bind address is 0.0.0.0, default port is remote container port. example: 127.0.0.1:5432 or 5432"` | ||
} `cmd help:"export remote container port to local host."` | ||
Debug bool `name:"debug" short:"D" optional` | ||
Host string `arg:"" name:"host" help:"ssh host. example: [email protected]"` | ||
ContainerPort string `arg:"" name:"cport" help:"remote container name and port. example: pg:5432"` | ||
LocalAddr string `arg:"" name:"lport" optional:"" help:"local bind address and port. default bind address is 0.0.0.0, default port is remote container port. example: 127.0.0.1:5432 or 5432"` | ||
} `cmd:"" passthrough:"" help:"export remote container port to local host."` | ||
Debug bool `name:"debug" short:"D" optional:""` | ||
Version kong.VersionFlag `short:"V"` | ||
} | ||
|
||
|
@@ -48,7 +48,7 @@ func main() { | |
if params.Host == "" { | ||
cmd = RunCommand(cmdStr) | ||
} else { | ||
cmd = RunSSHCommand(params.Host, cmdStr) | ||
cmd = RunSSHCommand(ParseHostOptions(params.Host), cmdStr) | ||
} | ||
PrintCmd(cmd) | ||
result, err := cmd.CombinedOutput() | ||
|
@@ -81,15 +81,15 @@ func main() { | |
lbind = localAddrArr[0] | ||
lport = localAddrArr[1] | ||
} | ||
getIPCmd := RunSSHCommand(params.Host, dcip.MakeGetContainerIPCmd(container)) | ||
getIPCmd := RunSSHCommand(ParseHostOptions(params.Host), dcip.MakeGetContainerIPCmd(container)) | ||
PrintCmd(getIPCmd) | ||
cipBytes, err := getIPCmd.CombinedOutput() | ||
cip := strings.Replace(string(cipBytes), "\n", "", 1) | ||
if err != nil { | ||
reportError(err) | ||
return | ||
} | ||
cmdStr := dcip.MakeForwardPortCmd(params.Host, string(cip)+":"+cport, lbind+":"+lport) | ||
cmdStr := dcip.MakeForwardPortCmd(ParseHostOptions(params.Host), string(cip)+":"+cport, lbind+":"+lport) | ||
cmd := RunSSHCommand(cmdStr, "") | ||
cmd.Stdin = os.Stdin | ||
cmd.Stderr = os.Stderr | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3,10 +3,11 @@ package dcip | |
import "fmt" | ||
|
||
// ssh -NT -L 0.0.0.0:5432:172.17.0.5:5432 [email protected] | ||
func MakeForwardPortCmd(host string, cport string, lport string) []string { | ||
return []string{ | ||
func MakeForwardPortCmd(host []string, cport string, lport string) []string { | ||
cmd := []string{ | ||
"-NT", | ||
"-L", fmt.Sprintf("%s:%s", lport, cport), | ||
host, | ||
} | ||
cmd = append(cmd, host...) | ||
return cmd | ||
} |