Merge pull request #44703 from thaJeztah/23.0_backport_docker_proxy_version_flag
[23.0 backport] cmd/docker-proxy: add "-v / --version" flag
This commit is contained in:
commit
8cb02d8c58
1 changed files with 12 additions and 4 deletions
|
@ -9,12 +9,13 @@ import (
|
||||||
"os/signal"
|
"os/signal"
|
||||||
"syscall"
|
"syscall"
|
||||||
|
|
||||||
|
"github.com/docker/docker/dockerversion"
|
||||||
"github.com/ishidawataru/sctp"
|
"github.com/ishidawataru/sctp"
|
||||||
)
|
)
|
||||||
|
|
||||||
func main() {
|
func main() {
|
||||||
f := os.NewFile(3, "signal-parent")
|
f := os.NewFile(3, "signal-parent")
|
||||||
host, container := parseHostContainerAddrs()
|
host, container := parseFlags()
|
||||||
|
|
||||||
p, err := NewProxy(host, container)
|
p, err := NewProxy(host, container)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
@ -30,19 +31,26 @@ func main() {
|
||||||
p.Run()
|
p.Run()
|
||||||
}
|
}
|
||||||
|
|
||||||
// parseHostContainerAddrs parses the flags passed on reexec to create the TCP/UDP/SCTP
|
// parseFlags parses the flags passed on reexec to create the TCP/UDP/SCTP
|
||||||
// net.Addrs to map the host and container ports
|
// net.Addrs to map the host and container ports.
|
||||||
func parseHostContainerAddrs() (host net.Addr, container net.Addr) {
|
func parseFlags() (host net.Addr, container net.Addr) {
|
||||||
var (
|
var (
|
||||||
proto = flag.String("proto", "tcp", "proxy protocol")
|
proto = flag.String("proto", "tcp", "proxy protocol")
|
||||||
hostIP = flag.String("host-ip", "", "host ip")
|
hostIP = flag.String("host-ip", "", "host ip")
|
||||||
hostPort = flag.Int("host-port", -1, "host port")
|
hostPort = flag.Int("host-port", -1, "host port")
|
||||||
containerIP = flag.String("container-ip", "", "container ip")
|
containerIP = flag.String("container-ip", "", "container ip")
|
||||||
containerPort = flag.Int("container-port", -1, "container port")
|
containerPort = flag.Int("container-port", -1, "container port")
|
||||||
|
printVer = flag.Bool("v", false, "print version information and quit")
|
||||||
|
printVersion = flag.Bool("version", false, "print version information and quit")
|
||||||
)
|
)
|
||||||
|
|
||||||
flag.Parse()
|
flag.Parse()
|
||||||
|
|
||||||
|
if *printVer || *printVersion {
|
||||||
|
fmt.Printf("docker-proxy (commit %s) version %s\n", dockerversion.GitCommit, dockerversion.Version)
|
||||||
|
os.Exit(0)
|
||||||
|
}
|
||||||
|
|
||||||
switch *proto {
|
switch *proto {
|
||||||
case "tcp":
|
case "tcp":
|
||||||
host = &net.TCPAddr{IP: net.ParseIP(*hostIP), Port: *hostPort}
|
host = &net.TCPAddr{IP: net.ParseIP(*hostIP), Port: *hostPort}
|
||||||
|
|
Loading…
Reference in a new issue