feat: write auto-detected port mappings during a deploy
During an app build, we now auto-detect ports based on the source code. This is usually http:80:5000, with Dockerfile-based deploys having their ports extracted from the docker image or Dockerfile. Additionally, we add an https:443 mapping for any detected http:80 mapping when there is an ssl certificate, and all http port mappings are transformed to https mappings for Dockerfile-based deploys. While the ports aren't currently consumed, a future refactor will provide the ability to fallback to the new detected ports when there is no user-specified port mapping.
This commit is contained in:
@@ -63,6 +63,54 @@ func getAvailablePort() int {
|
||||
}
|
||||
}
|
||||
|
||||
func getDetectedPortMaps(appName string) []PortMap {
|
||||
defaultMapping := []PortMap{
|
||||
{
|
||||
ContainerPort: 5000,
|
||||
HostPort: 80,
|
||||
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
|
||||
for _, portMap := range portMaps {
|
||||
if portMap.Scheme != "http" || portMap.HostPort != 80 {
|
||||
continue
|
||||
}
|
||||
|
||||
setSSLPort = true
|
||||
portMaps = append(portMaps, PortMap{
|
||||
ContainerPort: portMap.ContainerPort,
|
||||
HostPort: 443,
|
||||
Scheme: "https",
|
||||
})
|
||||
}
|
||||
|
||||
if !setSSLPort {
|
||||
for i, portMap := range portMaps {
|
||||
if portMap.Scheme != "http" {
|
||||
continue
|
||||
}
|
||||
|
||||
portMaps[i].Scheme = "https"
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return portMaps
|
||||
}
|
||||
|
||||
func getDockerfileRawTCPPorts(appName string) []int {
|
||||
b, _ := common.PlugnTriggerOutput("config-get", []string{appName, "DOKKU_DOCKERFILE_PORTS"}...)
|
||||
dockerfilePorts := strings.TrimSpace(string(b[:]))
|
||||
|
||||
Reference in New Issue
Block a user