refactor: rewrite network plugin in golang
This commit is contained in:
1 parent
e74346f0dc
commit
c788659b63
69 files changed
+3710
-274
No files matched your search
@@ -0,0 +1,15 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"flag"
|
||||
|
||||
network "github.com/dokku/dokku/plugins/network"
|
||||
)
|
||||
|
||||
// rebuilds network settings for an app
|
||||
func main() {
|
||||
flag.Parse()
|
||||
appName := flag.Arg(1)
|
||||
|
||||
network.BuildConfig(appName)
|
||||
}
|
||||
@@ -0,0 +1,42 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"flag"
|
||||
"fmt"
|
||||
"os"
|
||||
"strings"
|
||||
|
||||
common "github.com/dokku/dokku/plugins/common"
|
||||
config "github.com/dokku/dokku/plugins/config"
|
||||
)
|
||||
|
||||
// computes the ports for a given app container
|
||||
func main() {
|
||||
flag.Parse()
|
||||
appName := flag.Arg(1)
|
||||
procType := flag.Arg(2)
|
||||
isHerokuishContainer := common.ToBool(flag.Arg(3))
|
||||
|
||||
if procType != "web" {
|
||||
return
|
||||
}
|
||||
|
||||
var dockerfilePorts []string
|
||||
if !isHerokuishContainer {
|
||||
dockerfilePorts = strings.Split(config.GetWithDefault(appName, "DOKKU_DOCKERFILE_PORTS", ""), " ")
|
||||
}
|
||||
|
||||
var ports []string
|
||||
if len(dockerfilePorts) == 0 {
|
||||
ports = append(ports, "5000")
|
||||
} else {
|
||||
for _, port := range dockerfilePorts {
|
||||
port = strings.TrimSuffix(strings.TrimSpace(port), "/tcp")
|
||||
if port == "" || strings.HasSuffix(port, "/udp") {
|
||||
continue
|
||||
}
|
||||
ports = append(ports, port)
|
||||
}
|
||||
}
|
||||
fmt.Fprint(os.Stdout, strings.Join(ports, " "))
|
||||
}
|
||||
@@ -0,0 +1,22 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"flag"
|
||||
"fmt"
|
||||
"os"
|
||||
|
||||
common "github.com/dokku/dokku/plugins/common"
|
||||
network "github.com/dokku/dokku/plugins/network"
|
||||
)
|
||||
|
||||
// write the ipaddress to stdout for a given app container
|
||||
func main() {
|
||||
flag.Parse()
|
||||
appName := flag.Arg(1)
|
||||
procType := flag.Arg(2)
|
||||
isHerokuishContainer := common.ToBool(flag.Arg(3))
|
||||
containerId := flag.Arg(4)
|
||||
|
||||
ipAddress := network.GetContainerIpaddress(appName, procType, isHerokuishContainer, containerId)
|
||||
fmt.Fprintln(os.Stdout, ipAddress)
|
||||
}
|
||||
@@ -0,0 +1,32 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"path/filepath"
|
||||
"flag"
|
||||
"fmt"
|
||||
"os"
|
||||
"strings"
|
||||
|
||||
common "github.com/dokku/dokku/plugins/common"
|
||||
)
|
||||
|
||||
// returns the listeners (host:port combinations) for a given app container
|
||||
func main() {
|
||||
flag.Parse()
|
||||
appName := flag.Arg(1)
|
||||
|
||||
dokkuRoot := common.MustGetEnv("DOKKU_ROOT")
|
||||
appRoot := strings.Join([]string{dokkuRoot, appName}, "/")
|
||||
|
||||
files, _ := filepath.Glob(appRoot + "/IP.web.*")
|
||||
|
||||
var listeners []string
|
||||
for _, ipfile := range files {
|
||||
portfile := strings.Replace(ipfile, "/IP.web.", "/PORT.web.", 1)
|
||||
ipAddress := common.ReadFirstLine(ipfile)
|
||||
port := common.ReadFirstLine(portfile)
|
||||
listeners = append(listeners, fmt.Sprintf("%s:%s", ipAddress, port))
|
||||
}
|
||||
|
||||
fmt.Fprint(os.Stdout, strings.Join(listeners, " "))
|
||||
}
|
||||
@@ -0,0 +1,22 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"flag"
|
||||
"fmt"
|
||||
"os"
|
||||
|
||||
common "github.com/dokku/dokku/plugins/common"
|
||||
network "github.com/dokku/dokku/plugins/network"
|
||||
)
|
||||
|
||||
// write the port to stdout for a given app container
|
||||
func main() {
|
||||
flag.Parse()
|
||||
appName := flag.Arg(1)
|
||||
procType := flag.Arg(2)
|
||||
isHerokuishContainer := common.ToBool(flag.Arg(3))
|
||||
containerId := flag.Arg(4)
|
||||
|
||||
port := network.GetContainerPort(appName, procType, isHerokuishContainer, containerId)
|
||||
fmt.Fprintln(os.Stdout, port)
|
||||
}
|
||||
@@ -0,0 +1,40 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"flag"
|
||||
"fmt"
|
||||
"os"
|
||||
"strings"
|
||||
|
||||
common "github.com/dokku/dokku/plugins/common"
|
||||
)
|
||||
|
||||
// writes the ip to disk
|
||||
func main() {
|
||||
flag.Parse()
|
||||
appName := flag.Arg(1)
|
||||
procType := flag.Arg(2)
|
||||
containerIndex := flag.Arg(3)
|
||||
ip := flag.Arg(4)
|
||||
|
||||
if appName == "" {
|
||||
common.LogFail("Please specify an app to run the command on")
|
||||
}
|
||||
err := common.VerifyAppName(appName)
|
||||
if err != nil {
|
||||
common.LogFail(err.Error())
|
||||
}
|
||||
|
||||
appRoot := strings.Join([]string{common.MustGetEnv("DOKKU_ROOT"), appName}, "/")
|
||||
filename := fmt.Sprintf("%v/IP.%v.%v", appRoot, procType, containerIndex)
|
||||
f, err := os.Create(filename)
|
||||
if err != nil {
|
||||
common.LogFail(err.Error())
|
||||
}
|
||||
|
||||
ipBytes := []byte(ip)
|
||||
_, err = f.Write(ipBytes)
|
||||
if err != nil {
|
||||
common.LogFail(err.Error())
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,40 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"flag"
|
||||
"fmt"
|
||||
"os"
|
||||
"strings"
|
||||
|
||||
common "github.com/dokku/dokku/plugins/common"
|
||||
)
|
||||
|
||||
// writes the port to disk
|
||||
func main() {
|
||||
flag.Parse()
|
||||
appName := flag.Arg(1)
|
||||
procType := flag.Arg(2)
|
||||
containerIndex := flag.Arg(3)
|
||||
port := flag.Arg(4)
|
||||
|
||||
if appName == "" {
|
||||
common.LogFail("Please specify an app to run the command on")
|
||||
}
|
||||
err := common.VerifyAppName(appName)
|
||||
if err != nil {
|
||||
common.LogFail(err.Error())
|
||||
}
|
||||
|
||||
appRoot := strings.Join([]string{common.MustGetEnv("DOKKU_ROOT"), appName}, "/")
|
||||
filename := fmt.Sprintf("%v/PORT.%v.%v", appRoot, procType, containerIndex)
|
||||
f, err := os.Create(filename)
|
||||
if err != nil {
|
||||
common.LogFail(err.Error())
|
||||
}
|
||||
|
||||
portBytes := []byte(port)
|
||||
_, err = f.Write(portBytes)
|
||||
if err != nil {
|
||||
common.LogFail(err.Error())
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user