2023-07-02 01:29:01 -04:00
|
|
|
package ports
|
|
|
|
|
|
|
|
|
|
import (
|
|
|
|
|
"errors"
|
|
|
|
|
"fmt"
|
2023-07-09 02:45:36 -04:00
|
|
|
"net"
|
2023-07-02 01:29:01 -04:00
|
|
|
"os"
|
|
|
|
|
"sort"
|
|
|
|
|
"strconv"
|
|
|
|
|
"strings"
|
|
|
|
|
|
|
|
|
|
"github.com/dokku/dokku/plugins/common"
|
|
|
|
|
"github.com/dokku/dokku/plugins/config"
|
|
|
|
|
"github.com/ryanuber/columnize"
|
|
|
|
|
)
|
|
|
|
|
|
2024-02-25 11:10:36 -05:00
|
|
|
// addPortMaps adds port mappings to an app
|
2023-07-02 01:29:01 -04:00
|
|
|
func addPortMaps(appName string, portMaps []PortMap) error {
|
|
|
|
|
allPortMaps := getPortMaps(appName)
|
|
|
|
|
allPortMaps = append(allPortMaps, portMaps...)
|
|
|
|
|
|
|
|
|
|
return setPortMaps(appName, allPortMaps)
|
|
|
|
|
}
|
|
|
|
|
|
2024-02-25 11:10:36 -05:00
|
|
|
// clearPorts clears all port mappings for an app
|
2023-07-08 15:13:17 -04:00
|
|
|
func clearPorts(appName string) error {
|
2023-07-11 21:06:40 -04:00
|
|
|
if err := common.PropertyDelete("ports", appName, "map"); err != nil {
|
|
|
|
|
return err
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return common.PropertyDelete("ports", appName, "map-detected")
|
2023-07-08 15:13:17 -04:00
|
|
|
}
|
|
|
|
|
|
2024-02-25 11:10:36 -05:00
|
|
|
// doesCertExist checks if a cert exists for an app
|
2023-07-02 19:29:05 -04:00
|
|
|
func doesCertExist(appName string) bool {
|
2024-03-14 00:46:55 -04:00
|
|
|
results, _ := common.CallPlugnTrigger(common.PlugnTriggerInput{
|
|
|
|
|
Trigger: "certs-exists",
|
|
|
|
|
Args: []string{appName},
|
|
|
|
|
})
|
|
|
|
|
if results.StdoutContents() == "true" {
|
2023-08-01 02:16:11 -04:00
|
|
|
return true
|
|
|
|
|
}
|
|
|
|
|
|
2024-03-14 00:46:55 -04:00
|
|
|
results, _ = common.CallPlugnTrigger(common.PlugnTriggerInput{
|
|
|
|
|
Trigger: "certs-force",
|
|
|
|
|
Args: []string{appName},
|
|
|
|
|
})
|
|
|
|
|
return results.StdoutContents() == "true"
|
2023-07-02 19:29:05 -04:00
|
|
|
}
|
|
|
|
|
|
2024-02-25 11:10:36 -05:00
|
|
|
// filterAppPortMaps filters the port mappings for an app
|
2023-07-02 01:29:01 -04:00
|
|
|
func filterAppPortMaps(appName string, scheme string, hostPort int) []PortMap {
|
|
|
|
|
var filteredPortMaps []PortMap
|
|
|
|
|
for _, portMap := range getPortMaps(appName) {
|
|
|
|
|
if portMap.Scheme == scheme && portMap.HostPort == hostPort {
|
|
|
|
|
filteredPortMaps = append(filteredPortMaps, portMap)
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return filteredPortMaps
|
|
|
|
|
}
|
|
|
|
|
|
2024-02-25 11:10:36 -05:00
|
|
|
// getAvailablePort gets an available port
|
2023-07-09 02:45:36 -04:00
|
|
|
func getAvailablePort() int {
|
|
|
|
|
addr, err := net.ResolveTCPAddr("tcp", "localhost:0")
|
|
|
|
|
if err != nil {
|
|
|
|
|
return 0
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
for {
|
|
|
|
|
l, err := net.ListenTCP("tcp", addr)
|
|
|
|
|
if err != nil {
|
|
|
|
|
return 0
|
|
|
|
|
}
|
|
|
|
|
defer l.Close()
|
|
|
|
|
|
|
|
|
|
port := l.Addr().(*net.TCPAddr).Port
|
|
|
|
|
if port >= 1025 && port <= 65535 {
|
|
|
|
|
return port
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2024-02-25 11:10:36 -05:00
|
|
|
// getComputedProxyPort gets the computed proxy port for an app
|
2023-07-11 21:06:40 -04:00
|
|
|
func getComputedProxyPort(appName string) int {
|
|
|
|
|
port := getProxyPort(appName)
|
|
|
|
|
if port == 0 {
|
|
|
|
|
port = getGlobalProxyPort()
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return port
|
|
|
|
|
}
|
|
|
|
|
|
2024-02-25 11:10:36 -05:00
|
|
|
// getComputedProxySSLPort gets the computed proxy ssl port for an app
|
2023-07-11 21:06:40 -04:00
|
|
|
func getComputedProxySSLPort(appName string) int {
|
|
|
|
|
port := getProxySSLPort(appName)
|
|
|
|
|
if port == 0 {
|
|
|
|
|
port = getGlobalProxySSLPort()
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return port
|
|
|
|
|
}
|
|
|
|
|
|
2024-02-25 11:10:36 -05:00
|
|
|
// getDetectedPortMaps gets the detected port mappings for an app
|
2023-07-16 03:35:40 -04:00
|
|
|
func getDetectedPortMaps(appName string) []PortMap {
|
2023-07-11 21:06:40 -04:00
|
|
|
basePort := getComputedProxyPort(appName)
|
|
|
|
|
if basePort == 0 {
|
|
|
|
|
basePort = 80
|
|
|
|
|
}
|
2023-07-16 03:35:40 -04:00
|
|
|
defaultMapping := []PortMap{
|
|
|
|
|
{
|
|
|
|
|
ContainerPort: 5000,
|
2023-07-11 21:06:40 -04:00
|
|
|
HostPort: basePort,
|
2023-07-16 03:35:40 -04:00
|
|
|
Scheme: "http",
|
|
|
|
|
},
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
portMaps := []PortMap{}
|
|
|
|
|
value, err := common.PropertyListGet("ports", appName, "map-detected")
|
|
|
|
|
if err == nil {
|
|
|
|
|
portMaps, _ = parsePortMapString(strings.Join(value, " "))
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if len(portMaps) == 0 {
|
|
|
|
|
portMaps = defaultMapping
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if doesCertExist(appName) {
|
|
|
|
|
setSSLPort := false
|
2023-07-11 21:06:40 -04:00
|
|
|
baseSSLPort := getComputedProxySSLPort(appName)
|
|
|
|
|
if baseSSLPort == 0 {
|
|
|
|
|
baseSSLPort = 443
|
|
|
|
|
}
|
|
|
|
|
|
2023-07-16 03:35:40 -04:00
|
|
|
for _, portMap := range portMaps {
|
|
|
|
|
if portMap.Scheme != "http" || portMap.HostPort != 80 {
|
|
|
|
|
continue
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
setSSLPort = true
|
|
|
|
|
portMaps = append(portMaps, PortMap{
|
|
|
|
|
ContainerPort: portMap.ContainerPort,
|
2023-07-11 21:06:40 -04:00
|
|
|
HostPort: baseSSLPort,
|
2023-07-16 03:35:40 -04:00
|
|
|
Scheme: "https",
|
|
|
|
|
})
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if !setSSLPort {
|
|
|
|
|
for i, portMap := range portMaps {
|
|
|
|
|
if portMap.Scheme != "http" {
|
|
|
|
|
continue
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
portMaps[i].Scheme = "https"
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return portMaps
|
|
|
|
|
}
|
|
|
|
|
|
2024-02-25 11:10:36 -05:00
|
|
|
// getGlobalProxyPort gets the global proxy port
|
2023-07-02 19:29:05 -04:00
|
|
|
func getGlobalProxyPort() int {
|
|
|
|
|
port := 0
|
2024-03-14 00:46:55 -04:00
|
|
|
results, _ := common.CallPlugnTrigger(common.PlugnTriggerInput{
|
|
|
|
|
Trigger: "config-get-global",
|
|
|
|
|
Args: []string{"DOKKU_PROXY_PORT"},
|
|
|
|
|
})
|
|
|
|
|
if intVar, err := strconv.Atoi(results.StdoutContents()); err == nil {
|
2023-07-02 19:29:05 -04:00
|
|
|
port = intVar
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return port
|
|
|
|
|
}
|
|
|
|
|
|
2024-02-25 11:10:36 -05:00
|
|
|
// getGlobalProxySSLPort gets the global proxy ssl port
|
2023-07-02 19:29:05 -04:00
|
|
|
func getGlobalProxySSLPort() int {
|
|
|
|
|
port := 0
|
2024-03-14 00:46:55 -04:00
|
|
|
results, _ := common.CallPlugnTrigger(common.PlugnTriggerInput{
|
|
|
|
|
Trigger: "config-get-global",
|
|
|
|
|
Args: []string{"DOKKU_PROXY_SSL_PORT"},
|
|
|
|
|
})
|
|
|
|
|
if intVar, err := strconv.Atoi(results.StdoutContents()); err == nil {
|
2023-07-02 19:29:05 -04:00
|
|
|
port = intVar
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return port
|
|
|
|
|
}
|
|
|
|
|
|
2024-02-25 11:10:36 -05:00
|
|
|
// getPortMaps gets the port mappings for an app
|
2023-07-02 01:29:01 -04:00
|
|
|
func getPortMaps(appName string) []PortMap {
|
2023-07-16 02:30:44 -04:00
|
|
|
value, err := common.PropertyListGet("ports", appName, "map")
|
2023-07-09 18:35:42 -04:00
|
|
|
if err != nil {
|
|
|
|
|
return []PortMap{}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
portMaps, _ := parsePortMapString(strings.Join(value, " "))
|
2023-07-02 01:29:01 -04:00
|
|
|
return portMaps
|
|
|
|
|
}
|
|
|
|
|
|
2024-02-25 11:10:36 -05:00
|
|
|
// getProxyPort gets the proxy port for an app
|
2023-07-02 19:29:05 -04:00
|
|
|
func getProxyPort(appName string) int {
|
|
|
|
|
port := 0
|
2024-03-14 00:46:55 -04:00
|
|
|
results, _ := common.CallPlugnTrigger(common.PlugnTriggerInput{
|
|
|
|
|
Trigger: "config-get",
|
|
|
|
|
Args: []string{appName, "DOKKU_PROXY_PORT"},
|
|
|
|
|
})
|
|
|
|
|
if intVar, err := strconv.Atoi(results.StdoutContents()); err == nil {
|
2023-07-02 19:29:05 -04:00
|
|
|
port = intVar
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return port
|
|
|
|
|
}
|
|
|
|
|
|
2024-02-25 11:10:36 -05:00
|
|
|
// getProxySSLPort gets the proxy ssl port for an app
|
2023-07-02 19:29:05 -04:00
|
|
|
func getProxySSLPort(appName string) int {
|
|
|
|
|
port := 0
|
2024-03-14 00:46:55 -04:00
|
|
|
results, _ := common.CallPlugnTrigger(common.PlugnTriggerInput{
|
|
|
|
|
Trigger: "config-get",
|
|
|
|
|
Args: []string{appName, "DOKKU_PROXY_SSL_PORT"},
|
|
|
|
|
})
|
|
|
|
|
if intVar, err := strconv.Atoi(results.StdoutContents()); err == nil {
|
2023-07-02 19:29:05 -04:00
|
|
|
port = intVar
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return port
|
|
|
|
|
}
|
|
|
|
|
|
2024-02-25 11:10:36 -05:00
|
|
|
// initializeProxyPort initializes the proxy port for an app
|
2023-07-11 21:06:40 -04:00
|
|
|
func initializeProxyPort(appName string) error {
|
2023-07-09 18:31:18 -04:00
|
|
|
port := getProxyPort(appName)
|
|
|
|
|
if port != 0 {
|
|
|
|
|
return nil
|
2023-07-02 19:29:05 -04:00
|
|
|
}
|
2023-07-09 18:31:18 -04:00
|
|
|
|
|
|
|
|
if isAppVhostEnabled(appName) {
|
|
|
|
|
port = getGlobalProxyPort()
|
|
|
|
|
} else {
|
|
|
|
|
common.LogInfo1("No port set, setting to random open high port")
|
|
|
|
|
port = getAvailablePort()
|
2023-07-11 21:06:40 -04:00
|
|
|
common.LogInfo1(fmt.Sprintf("Random port %d", port))
|
2023-07-09 18:31:18 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if port == 0 {
|
|
|
|
|
port = 80
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if err := setProxyPort(appName, port); err != nil {
|
|
|
|
|
return err
|
|
|
|
|
}
|
|
|
|
|
return nil
|
|
|
|
|
}
|
|
|
|
|
|
2024-02-25 11:10:36 -05:00
|
|
|
// initializeProxySSLPort initializes the proxy ssl port for an app
|
2023-07-11 21:06:40 -04:00
|
|
|
func initializeProxySSLPort(appName string) error {
|
2023-07-09 18:31:18 -04:00
|
|
|
port := getProxySSLPort(appName)
|
|
|
|
|
if port != 0 {
|
|
|
|
|
return nil
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if !doesCertExist(appName) {
|
|
|
|
|
return nil
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
port = getGlobalProxySSLPort()
|
|
|
|
|
if port == 0 {
|
|
|
|
|
port = 443
|
|
|
|
|
}
|
|
|
|
|
|
2023-07-11 21:06:40 -04:00
|
|
|
if !isAppVhostEnabled(appName) {
|
2023-07-09 18:31:18 -04:00
|
|
|
common.LogInfo1("No ssl port set, setting to random open high port")
|
|
|
|
|
port = getAvailablePort()
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if err := setProxySSLPort(appName, port); err != nil {
|
|
|
|
|
return err
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return nil
|
|
|
|
|
}
|
|
|
|
|
|
2024-02-25 11:10:36 -05:00
|
|
|
// inRange checks if a value is within a range
|
2023-07-02 01:29:01 -04:00
|
|
|
func inRange(value int, min int, max int) bool {
|
|
|
|
|
return min < value && value < max
|
|
|
|
|
}
|
|
|
|
|
|
2024-02-25 11:10:36 -05:00
|
|
|
// isAppVhostEnabled checks if the app vhost is enabled
|
2023-07-09 18:31:18 -04:00
|
|
|
func isAppVhostEnabled(appName string) bool {
|
2024-03-14 02:19:03 -04:00
|
|
|
_, err := common.CallPlugnTrigger(common.PlugnTriggerInput{
|
|
|
|
|
Trigger: "domains-vhost-enabled",
|
|
|
|
|
Args: []string{appName},
|
|
|
|
|
StreamStdio: true,
|
|
|
|
|
})
|
|
|
|
|
return err == nil
|
2023-07-09 18:31:18 -04:00
|
|
|
}
|
|
|
|
|
|
2024-02-25 11:10:36 -05:00
|
|
|
// listAppPortMaps lists the port mappings for an app
|
2023-07-02 01:29:01 -04:00
|
|
|
func listAppPortMaps(appName string) error {
|
|
|
|
|
portMaps := getPortMaps(appName)
|
|
|
|
|
|
|
|
|
|
if len(portMaps) == 0 {
|
|
|
|
|
return errors.New("No port mappings configured for app")
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
var lines []string
|
|
|
|
|
if os.Getenv("DOKKU_QUIET_OUTPUT") == "" {
|
|
|
|
|
lines = append(lines, "-----> scheme:host port:container port")
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
for _, portMap := range portMaps {
|
|
|
|
|
lines = append(lines, portMap.String())
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
sort.Strings(lines)
|
|
|
|
|
common.LogInfo1Quiet(fmt.Sprintf("Port mappings for %s", appName))
|
|
|
|
|
config := columnize.DefaultConfig()
|
|
|
|
|
config.Delim = ":"
|
|
|
|
|
config.Prefix = " "
|
|
|
|
|
config.Empty = ""
|
|
|
|
|
fmt.Println(columnize.Format(lines, config))
|
|
|
|
|
return nil
|
|
|
|
|
}
|
|
|
|
|
|
2024-02-25 11:10:36 -05:00
|
|
|
// parsePortMapString parses a port map string into a slice of PortMap structs
|
2023-07-02 01:29:01 -04:00
|
|
|
func parsePortMapString(stringPortMap string) ([]PortMap, error) {
|
|
|
|
|
var portMaps []PortMap
|
|
|
|
|
|
|
|
|
|
for _, v := range strings.Split(strings.TrimSpace(stringPortMap), " ") {
|
|
|
|
|
parts := strings.SplitN(v, ":", 3)
|
|
|
|
|
if len(parts) == 1 {
|
|
|
|
|
hostPort, err := strconv.Atoi(v)
|
|
|
|
|
if err != nil {
|
|
|
|
|
return portMaps, fmt.Errorf("Invalid port map %s [err=%s]", v, err.Error())
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if !inRange(hostPort, 0, 65536) {
|
|
|
|
|
return portMaps, fmt.Errorf("Invalid port map %s [hostPort=%d]", v, hostPort)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
portMaps = append(portMaps, PortMap{
|
|
|
|
|
HostPort: hostPort,
|
|
|
|
|
Scheme: "__internal__",
|
|
|
|
|
})
|
|
|
|
|
continue
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if len(parts) != 3 {
|
|
|
|
|
return portMaps, fmt.Errorf("Invalid port map %s [len=%d]", v, len(parts))
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
hostPort, err := strconv.Atoi(parts[1])
|
|
|
|
|
if err != nil {
|
|
|
|
|
return portMaps, fmt.Errorf("Invalid port map %s [err=%s]", v, err.Error())
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
containerPort, err := strconv.Atoi(parts[2])
|
|
|
|
|
if err != nil {
|
|
|
|
|
return portMaps, fmt.Errorf("Invalid port map %s [err=%s]", v, err.Error())
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if !inRange(hostPort, 0, 65536) {
|
|
|
|
|
return portMaps, fmt.Errorf("Invalid port map %s [hostPort=%d]", v, hostPort)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if !inRange(containerPort, 0, 65536) {
|
|
|
|
|
return portMaps, fmt.Errorf("Invalid port map %s [containerPort=%d]", v, containerPort)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
portMaps = append(portMaps, PortMap{
|
|
|
|
|
ContainerPort: containerPort,
|
|
|
|
|
HostPort: hostPort,
|
|
|
|
|
Scheme: parts[0],
|
|
|
|
|
})
|
|
|
|
|
}
|
|
|
|
|
|
2024-02-25 12:13:06 -05:00
|
|
|
return portMaps, nil
|
2023-07-02 01:29:01 -04:00
|
|
|
}
|
|
|
|
|
|
2024-02-25 11:10:36 -05:00
|
|
|
// removePortMaps removes specific port mappings from an app
|
2023-07-02 01:29:01 -04:00
|
|
|
func removePortMaps(appName string, portMaps []PortMap) error {
|
|
|
|
|
toRemove := map[string]bool{}
|
|
|
|
|
toRemoveByPort := map[int]bool{}
|
|
|
|
|
|
|
|
|
|
for _, portMap := range portMaps {
|
|
|
|
|
if portMap.AllowsPersistence() {
|
|
|
|
|
toRemoveByPort[portMap.HostPort] = true
|
|
|
|
|
continue
|
|
|
|
|
}
|
|
|
|
|
toRemove[portMap.String()] = true
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
var toSet []PortMap
|
|
|
|
|
for _, portMap := range getPortMaps(appName) {
|
|
|
|
|
if toRemove[portMap.String()] {
|
|
|
|
|
continue
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if toRemoveByPort[portMap.HostPort] {
|
|
|
|
|
continue
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
toSet = append(toSet, portMap)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if len(toSet) == 0 {
|
2023-07-16 02:30:44 -04:00
|
|
|
return common.PropertyDelete("ports", appName, "map")
|
2023-07-02 01:29:01 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return setPortMaps(appName, toSet)
|
|
|
|
|
}
|
|
|
|
|
|
2024-02-25 11:10:36 -05:00
|
|
|
// reusesSchemeHostPort returns true if the port maps reuse the same scheme:host-port
|
|
|
|
|
func reusesSchemeHostPort(portMaps []PortMap) error {
|
|
|
|
|
found := map[string]bool{}
|
|
|
|
|
|
|
|
|
|
for _, portMap := range portMaps {
|
|
|
|
|
key := fmt.Sprintf("%s:%d", portMap.Scheme, portMap.HostPort)
|
|
|
|
|
if found[key] {
|
|
|
|
|
return fmt.Errorf("The same scheme:host-port is being reused: %s", key)
|
|
|
|
|
}
|
|
|
|
|
found[key] = true
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return nil
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// setPortMaps sets the port maps for an app
|
2023-07-02 01:29:01 -04:00
|
|
|
func setPortMaps(appName string, portMaps []PortMap) error {
|
2024-02-25 12:13:06 -05:00
|
|
|
if err := reusesSchemeHostPort(portMaps); err != nil {
|
|
|
|
|
return fmt.Errorf("Error validating port mappings: %s", err)
|
|
|
|
|
}
|
|
|
|
|
|
2023-07-02 01:29:01 -04:00
|
|
|
var value []string
|
2024-02-25 12:13:06 -05:00
|
|
|
for _, portMap := range portMaps {
|
2023-07-02 01:29:01 -04:00
|
|
|
if portMap.AllowsPersistence() {
|
|
|
|
|
continue
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
value = append(value, portMap.String())
|
|
|
|
|
}
|
|
|
|
|
|
2023-07-09 18:35:42 -04:00
|
|
|
sort.Strings(value)
|
2023-07-16 02:30:44 -04:00
|
|
|
return common.PropertyListWrite("ports", appName, "map", value)
|
2023-07-02 01:29:01 -04:00
|
|
|
}
|
|
|
|
|
|
2024-02-25 11:10:36 -05:00
|
|
|
// setProxyPort sets the proxy port for an app
|
2023-07-09 18:31:18 -04:00
|
|
|
func setProxyPort(appName string, port int) error {
|
|
|
|
|
return common.EnvWrap(func() error {
|
|
|
|
|
entries := map[string]string{
|
|
|
|
|
"DOKKU_PROXY_PORT": fmt.Sprint(port),
|
|
|
|
|
}
|
2025-11-08 01:02:19 -05:00
|
|
|
return config.SetMany(appName, entries, false, false)
|
2023-07-09 18:31:18 -04:00
|
|
|
}, map[string]string{"DOKKU_QUIET_OUTPUT": "1"})
|
|
|
|
|
}
|
|
|
|
|
|
2024-02-25 11:10:36 -05:00
|
|
|
// setProxySSLPort sets the proxy ssl port for an app
|
2023-07-09 18:31:18 -04:00
|
|
|
func setProxySSLPort(appName string, port int) error {
|
|
|
|
|
return common.EnvWrap(func() error {
|
|
|
|
|
entries := map[string]string{
|
|
|
|
|
"DOKKU_PROXY_SSL_PORT": fmt.Sprint(port),
|
|
|
|
|
}
|
2025-11-08 01:02:19 -05:00
|
|
|
return config.SetMany(appName, entries, false, false)
|
2023-07-09 18:31:18 -04:00
|
|
|
}, map[string]string{"DOKKU_QUIET_OUTPUT": "1"})
|
|
|
|
|
}
|
|
|
|
|
|
2024-02-25 11:10:36 -05:00
|
|
|
// uniquePortMaps returns a unique set of port maps
|
2023-07-02 01:29:01 -04:00
|
|
|
func uniquePortMaps(portMaps []PortMap) []PortMap {
|
2024-02-25 11:10:36 -05:00
|
|
|
uniquePortMaps := []PortMap{}
|
|
|
|
|
found := map[string]bool{}
|
2023-07-02 01:29:01 -04:00
|
|
|
|
|
|
|
|
for _, portMap := range portMaps {
|
2024-02-25 11:10:36 -05:00
|
|
|
key := fmt.Sprintf("%s:%d", portMap.Scheme, portMap.HostPort)
|
|
|
|
|
if found[key] {
|
2023-07-02 01:29:01 -04:00
|
|
|
continue
|
|
|
|
|
}
|
|
|
|
|
|
2024-02-25 11:10:36 -05:00
|
|
|
found[key] = true
|
|
|
|
|
uniquePortMaps = append(uniquePortMaps, portMap)
|
2023-07-02 01:29:01 -04:00
|
|
|
}
|
|
|
|
|
|
2024-02-25 11:10:36 -05:00
|
|
|
return uniquePortMaps
|
2023-07-02 01:29:01 -04:00
|
|
|
}
|