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
2023-07-11 21:06:40 -04:00
parent 6168b0c71c
commit f8ccf52079
36 changed files with 238 additions and 416 deletions

View File

@@ -632,18 +632,9 @@ release_and_deploy() {
local APP="$1"
local IMAGE_TAG="${2:-latest}"
local IMAGE=$(get_app_image_name "$APP" "$IMAGE_TAG")
local DOKKU_DOCKERFILE_PORTS
if verify_image "$IMAGE"; then
IMAGE_SOURCE_TYPE="$(get_image_builder_type "$IMAGE" "$APP")"
if [[ "$IMAGE_SOURCE_TYPE" == "dockerfile" ]]; then
DOKKU_DOCKERFILE_PORTS=$(config_get "$APP" DOKKU_DOCKERFILE_PORTS || true)
if [[ -z "$DOKKU_DOCKERFILE_PORTS" ]]; then
local DOCKER_IMAGE_PORTS=$(get_exposed_ports_from_image "$IMAGE")
[[ -n "$DOCKER_IMAGE_PORTS" ]] && config_set --no-restart "$APP" DOKKU_DOCKERFILE_PORTS="$DOCKER_IMAGE_PORTS"
fi
fi
local DOKKU_APP_SKIP_DEPLOY="$(config_get "$APP" DOKKU_SKIP_DEPLOY || true)"
local DOKKU_GLOBAL_SKIP_DEPLOY="$(config_get --global DOKKU_SKIP_DEPLOY || true)"
@@ -768,12 +759,16 @@ get_ipv6_regex() {
get_dockerfile_exposed_ports() {
declare desc="return all exposed ports from passed file path"
dokku_log_warn "Deprecated: this function should not be used in app code"
local DOCKERFILE_PORTS=$(grep -E "^EXPOSE " "$1" | awk '{ print $2 }' | xargs) || true
echo "$DOCKERFILE_PORTS"
}
get_exposed_ports_from_image() {
declare desc="return all exposed ports from passed image name"
dokku_log_warn "Deprecated: this function should not be used in app code"
local IMAGE="$1"
verify_image "$IMAGE"
# shellcheck disable=SC2016
@@ -806,14 +801,6 @@ extract_directive_from_dockerfile() {
echo "$FOUND_LINE"
}
get_app_raw_tcp_ports() {
declare desc="extracts raw tcp port numbers from DOCKERFILE_PORTS config variable"
declare APP="$1"
dokku_log_warn "Deprecated: this function should not be used in app code"
plugn trigger ports-dockerfile-raw-tcp-ports "$APP" | xargs
}
get_container_ports() {
declare desc="returns published ports from app containers"
local APP="$1"

View File

@@ -1,6 +0,0 @@
#!/usr/bin/env bash
source "$PLUGIN_CORE_AVAILABLE_PATH/common/functions"
set -eo pipefail
[[ $DOKKU_TRACE ]] && set -x
get_available_port "$@"