refactor: move code that fetches raw tcp ports for dockerfile deploys to ports plugin
This commit is contained in:
@@ -1,5 +1,5 @@
|
||||
SUBCOMMANDS = subcommands/list subcommands/add subcommands/clear subcommands/remove subcommands/set subcommands/report
|
||||
TRIGGERS = triggers/ports-clear triggers/ports-get triggers/post-certs-remove triggers/post-certs-update triggers/report
|
||||
TRIGGERS = triggers/ports-clear triggers/ports-dockerfile-raw-tcp-ports triggers/ports-get triggers/post-certs-remove triggers/post-certs-update triggers/report
|
||||
BUILD = commands subcommands triggers
|
||||
PLUGIN_NAME = ports
|
||||
|
||||
|
||||
@@ -38,6 +38,37 @@ func filterAppPortMaps(appName string, scheme string, hostPort int) []PortMap {
|
||||
return filteredPortMaps
|
||||
}
|
||||
|
||||
func getDockerfileRawTCPPorts(appName string) []int {
|
||||
b, _ := common.PlugnTriggerOutput("config-get", []string{appName, "DOKKU_DOCKERFILE_PORTS"}...)
|
||||
dockerfilePorts := strings.TrimSpace(string(b[:]))
|
||||
|
||||
ports := []int{}
|
||||
for _, dockerfilePort := range strings.Split(dockerfilePorts, " ") {
|
||||
dockerfilePort = strings.TrimSpace(dockerfilePort)
|
||||
if strings.HasSuffix(dockerfilePort, "/udp") {
|
||||
continue
|
||||
}
|
||||
|
||||
dockerfilePort = strings.TrimSuffix(dockerfilePort, "/tcp")
|
||||
if dockerfilePort == "" {
|
||||
continue
|
||||
}
|
||||
|
||||
port, err := strconv.Atoi(dockerfilePort)
|
||||
if err != nil {
|
||||
continue
|
||||
}
|
||||
|
||||
if port == 0 {
|
||||
continue
|
||||
}
|
||||
|
||||
ports = append(ports, port)
|
||||
}
|
||||
|
||||
return ports
|
||||
}
|
||||
|
||||
func getPortMaps(appName string) []PortMap {
|
||||
value := config.GetWithDefault(appName, "DOKKU_PROXY_PORT_MAP", "")
|
||||
portMaps, _ := parsePortMapString(value)
|
||||
|
||||
@@ -24,6 +24,9 @@ func main() {
|
||||
case "ports-clear":
|
||||
appName := flag.Arg(0)
|
||||
err = ports.TriggerPortsClear(appName)
|
||||
case "ports-dockerfile-raw-tcp-ports":
|
||||
appName := flag.Arg(0)
|
||||
err = ports.TriggerPortsDockerfileRawTCPPorts(appName)
|
||||
case "post-certs-remove":
|
||||
appName := flag.Arg(0)
|
||||
err = ports.TriggerPostCertsRemove(appName)
|
||||
|
||||
@@ -3,9 +3,25 @@ package ports
|
||||
import (
|
||||
"fmt"
|
||||
|
||||
"github.com/dokku/dokku/plugins/common"
|
||||
"github.com/dokku/dokku/plugins/config"
|
||||
)
|
||||
|
||||
// TriggerPortsClear removes all ports for the specified app
|
||||
func TriggerPortsClear(appName string) error {
|
||||
return clearPorts(appName)
|
||||
}
|
||||
|
||||
// TriggerRawTCPPorts extracts raw tcp port numbers from DOCKERFILE_PORTS config variable
|
||||
func TriggerPortsDockerfileRawTCPPorts(appName string) error {
|
||||
ports := getDockerfileRawTCPPorts(appName)
|
||||
for _, port := range ports {
|
||||
common.Log(fmt.Sprint(port))
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
// TriggerPortsGet prints out the port mapping for a given app
|
||||
func TriggerPortsGet(appName string) error {
|
||||
for _, portMap := range getPortMaps(appName) {
|
||||
@@ -19,11 +35,6 @@ func TriggerPortsGet(appName string) error {
|
||||
return nil
|
||||
}
|
||||
|
||||
// TriggerPortsClear removes all ports for the specified app
|
||||
func TriggerPortsClear(appName string) error {
|
||||
return clearPorts(appName)
|
||||
}
|
||||
|
||||
// TriggerPostCertsRemove unsets port config vars after SSL cert is added
|
||||
func TriggerPostCertsRemove(appName string) error {
|
||||
keys := []string{"DOKKU_PROXY_SSL_PORT"}
|
||||
|
||||
Reference in New Issue
Block a user