refactor: only use detected port mapping if override is not specified

Previously, we would always set the port mapping during a dockerfile build, making it difficult for users to override mappings. We also only _sometimes_ updated the detected port mapping, further confusing issues when users were migrating from Dockerfile to Buildpacks for builds.

Now, we always detect the port mapping during the build process, and only use that detected port mapping if an override is not specified. This greatly simplifies the experience around port mapping, as now a user can create an app, set a port mapping, and that first deploy will respect the port mapping without an additional deploy.

The builder always has the best context for what the app should be listening on, and thus we can always specify a "default" port mapping at this stage. Users can override this map as desired later.

This change also results in the removal of a ton of internal code that is now centralized in the ports plugin.

Closes #4067
This commit is contained in:
Jose Diaz-Gonzalez committed 2023-08-05 10:58:57 -04:00
1 parent 6168b0c71c
commit f8ccf52079
36 files changed
+238 -416

No files matched your search

+25 -20
View File
@@ -52,36 +52,25 @@ func TriggerPortsClear(appName string) error {
// TriggerPortsConfigure ensures we have a port mapping
func TriggerPortsConfigure(appName string) error {
rawTCPPorts := getDockerfileRawTCPPorts(appName)
if err := initializeProxyPort(appName, rawTCPPorts); err != nil {
if err := initializeProxyPort(appName); err != nil {
return err
}
if err := initializeProxySSLPort(appName, rawTCPPorts); err != nil {
if err := initializeProxySSLPort(appName); err != nil {
return err
}
if err := initializePortMap(appName, rawTCPPorts); err != nil {
return err
}
return nil
}
// 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) {
portMaps := getPortMaps(appName)
if len(portMaps) == 0 {
portMaps = getDetectedPortMaps(appName)
}
for _, portMap := range portMaps {
if portMap.AllowsPersistence() {
continue
}
@@ -102,7 +91,23 @@ func TriggerPortsGetAvailable() error {
return nil
}
// TriggerPortsGetAvailable prints out an available port greater than 1024
// TriggerPortsGetProperty writes the ports key to stdout for a given app container
func TriggerPortsGetProperty(appName string, key string) error {
if key == "proxy-port" {
fmt.Println(getComputedProxyPort(appName))
return nil
}
if key == "proxy-ssl-port" {
fmt.Println(getComputedProxySSLPort(appName))
return nil
}
fmt.Println(common.PropertyGet("ports", appName, key))
return nil
}
// TriggerPortsSetDetected writes out detected ports
func TriggerPortsSetDetected(appName string, portMapString string) error {
portMaps, _ := parsePortMapString(portMapString)