refactor: deprecate proxy-configure-ports plugin trigger in favor of ports-configure
This also rewrites the logic to be in golang, which will make it easier to refactor portions of it to use the property system going forward.
This commit is contained in:
1 parent
192f7cf768
commit
48d5820b8c
13 files changed
+203
-64
No files matched your search
@@ -2,6 +2,8 @@ package ports
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"path/filepath"
|
||||
"strconv"
|
||||
|
||||
"github.com/dokku/dokku/plugins/common"
|
||||
"github.com/dokku/dokku/plugins/config"
|
||||
@@ -12,6 +14,110 @@ func TriggerPortsClear(appName string) error {
|
||||
return clearPorts(appName)
|
||||
}
|
||||
|
||||
// TriggerPortsConfigure ensures we have a port mapping
|
||||
func TriggerPortsConfigure(appName string) error {
|
||||
rawTCPPorts := getDockerfileRawTCPPorts(appName)
|
||||
|
||||
dokkuProxyPort := getProxyPort(appName)
|
||||
dokkuProxySSLPort := getProxySSLPort(appName)
|
||||
portMaps := getPortMaps(appName)
|
||||
|
||||
vhostEnabled := isAppVhostEnabled(appName)
|
||||
|
||||
if dokkuProxyPort == 0 && len(rawTCPPorts) == 0 {
|
||||
proxyPort := 80
|
||||
if !vhostEnabled {
|
||||
common.LogInfo1("No port set, setting to random open high port")
|
||||
proxyPort = getAvailablePort()
|
||||
} else {
|
||||
proxyPort = getGlobalProxyPort()
|
||||
}
|
||||
|
||||
if proxyPort == 0 {
|
||||
proxyPort = 80
|
||||
}
|
||||
|
||||
dokkuProxyPort = proxyPort
|
||||
err := common.EnvWrap(func() error {
|
||||
entries := map[string]string{
|
||||
"DOKKU_PROXY_PORT": fmt.Sprint(proxyPort),
|
||||
}
|
||||
return config.SetMany(appName, entries, false)
|
||||
}, map[string]string{"DOKKU_QUIET_OUTPUT": "1"})
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
|
||||
if dokkuProxySSLPort == 0 {
|
||||
if doesCertExist(appName) {
|
||||
proxySSLPort := getGlobalProxySSLPort()
|
||||
if proxySSLPort == 0 {
|
||||
proxySSLPort = 443
|
||||
}
|
||||
|
||||
if len(rawTCPPorts) == 0 && !vhostEnabled {
|
||||
common.LogInfo1("No ssl port set, setting to random open high port")
|
||||
proxySSLPort = getAvailablePort()
|
||||
}
|
||||
|
||||
dokkuProxySSLPort = proxySSLPort
|
||||
err := common.EnvWrap(func() error {
|
||||
entries := map[string]string{
|
||||
"DOKKU_PROXY_SSL_PORT": fmt.Sprint(proxySSLPort),
|
||||
}
|
||||
return config.SetMany(appName, entries, false)
|
||||
}, map[string]string{"DOKKU_QUIET_OUTPUT": "1"})
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if len(portMaps) == 0 {
|
||||
if len(rawTCPPorts) > 0 {
|
||||
for _, rawTcpPort := range rawTCPPorts {
|
||||
portMaps = append(portMaps, PortMap{
|
||||
ContainerPort: rawTcpPort,
|
||||
HostPort: rawTcpPort,
|
||||
Scheme: "http",
|
||||
})
|
||||
}
|
||||
} else {
|
||||
upstreamPort := 5000
|
||||
portFile := filepath.Join(common.AppRoot(appName), "PORT.web.1")
|
||||
if common.FileExists(portFile) {
|
||||
if port, err := strconv.Atoi(common.ReadFirstLine(portFile)); err == nil {
|
||||
upstreamPort = port
|
||||
}
|
||||
}
|
||||
|
||||
if dokkuProxyPort != 0 {
|
||||
portMaps = append(portMaps, PortMap{
|
||||
ContainerPort: upstreamPort,
|
||||
HostPort: dokkuProxyPort,
|
||||
Scheme: "http",
|
||||
})
|
||||
}
|
||||
if dokkuProxySSLPort != 0 {
|
||||
portMaps = append(portMaps, PortMap{
|
||||
ContainerPort: upstreamPort,
|
||||
HostPort: dokkuProxySSLPort,
|
||||
Scheme: "https",
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
if len(portMaps) > 0 {
|
||||
return setPortMaps(appName, portMaps)
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
// TriggerRawTCPPorts extracts raw tcp port numbers from DOCKERFILE_PORTS config variable
|
||||
func TriggerPortsDockerfileRawTCPPorts(appName string) error {
|
||||
ports := getDockerfileRawTCPPorts(appName)
|
||||
|
||||
Reference in new issue
Block a user