Merge pull request #7941 from dokku/7817-https-port-dockerfile

Do not generate an https url when there is no SSL certificate
This commit is contained in:
Jose Diaz-Gonzalez
2025-09-07 23:09:01 -04:00
committed by GitHub
5 changed files with 50 additions and 16 deletions

View File

@@ -124,8 +124,12 @@ fn-builder-dockerfile-get-detect-port-map() {
p=${p//\/udp/} p=${p//\/udp/}
port_map+="udp:$p:$p " port_map+="udp:$p:$p "
else else
scheme="http"
p=${p//\/tcp/} p=${p//\/tcp/}
port_map+="http:$p:$p " if [[ "$p" == "443" ]]; then
scheme="https"
fi
port_map+="$scheme:$p:$p "
fi fi
done done
echo "$port_map" | xargs echo "$port_map" | xargs

View File

@@ -9,25 +9,25 @@ trigger-domains-domains-urls() {
declare APP="$1" URL_TYPE="$2" declare APP="$1" URL_TYPE="$2"
local urls local urls
local SCHEME="http" local DEFAULT_SCHEME="http"
local DEFAULT_LISTEN_PORT="80" local DEFAULT_LISTEN_PORT="80"
if [[ "$(plugn trigger certs-exists "$APP")" == "true" ]]; then if [[ "$(plugn trigger certs-exists "$APP")" == "true" ]]; then
SCHEME="https" DEFAULT_SCHEME="https"
DEFAULT_LISTEN_PORT="443" DEFAULT_LISTEN_PORT="443"
fi fi
urls=$(plugn trigger app-urls "$APP" "$URL_TYPE") urls=$(plugn trigger app-urls "$APP" "$URL_TYPE")
if [[ -n "$urls" ]]; then if [[ -n "$urls" ]]; then
if [[ "$URL_TYPE" == "url" ]]; then if [[ "$URL_TYPE" == "url" ]]; then
echo "$urls" | tr ' ' '\n' | grep "$SCHEME://" | head -n1 echo "$urls" | tr ' ' '\n' | grep "$DEFAULT_SCHEME://" | head -n1
else else
echo "$urls" | tr ' ' '\n' | sort echo "$urls" | tr ' ' '\n' | sort
fi fi
else else
if [[ "$URL_TYPE" == "url" ]]; then if [[ "$URL_TYPE" == "url" ]]; then
fn-domains-generate-urls "$APP" "$SCHEME" "$DEFAULT_LISTEN_PORT" | tr ' ' '\n' | grep "$SCHEME://" | head -n1 fn-domains-generate-urls "$APP" "$DEFAULT_SCHEME" "$DEFAULT_LISTEN_PORT" | tr ' ' '\n' | grep "$DEFAULT_SCHEME://" | head -n1
else else
fn-domains-generate-urls "$APP" "$SCHEME" "$DEFAULT_LISTEN_PORT" | tr ' ' '\n' | sort fn-domains-generate-urls "$APP" "$DEFAULT_SCHEME" "$DEFAULT_LISTEN_PORT" | tr ' ' '\n' | sort -u
fi fi
fi fi
} }

View File

@@ -116,26 +116,26 @@ fn-domains-global-vhosts() {
} }
fn-domains-generate-urls() { fn-domains-generate-urls() {
declare APP="$1" SCHEME="$2" DEFAULT_LISTEN_PORT="$3" declare APP="$1" DEFAULT_SCHEME="$2" DEFAULT_LISTEN_PORT="$3"
local app_vhosts="$(plugn trigger domains-list "$APP")" local app_vhosts="$(plugn trigger domains-list "$APP")"
if [[ -n "$app_vhosts" ]]; then if [[ -n "$app_vhosts" ]]; then
for app_vhost in $app_vhosts; do for app_vhost in $app_vhosts; do
fn-domains-generate-urls-from-config "$APP" "$SCHEME" "$app_vhost" "$DEFAULT_LISTEN_PORT" fn-domains-generate-urls-from-config "$APP" "$DEFAULT_SCHEME" "$app_vhost" "$DEFAULT_LISTEN_PORT"
done done
else else
if [[ -s "$DOKKU_ROOT/VHOST" ]]; then if [[ -s "$DOKKU_ROOT/VHOST" ]]; then
while read -r VHOST || [[ -n "$VHOST" ]]; do while read -r VHOST || [[ -n "$VHOST" ]]; do
fn-domains-generate-urls-from-config "$APP" "$SCHEME" "$VHOST" "$DEFAULT_LISTEN_PORT" fn-domains-generate-urls-from-config "$APP" "$DEFAULT_SCHEME" "$VHOST" "$DEFAULT_LISTEN_PORT"
done <"$DOKKU_ROOT/VHOST" done <"$DOKKU_ROOT/VHOST"
else else
fn-domains-generate-urls-from-config "$APP" "$SCHEME" "$(hostname -f)" "$DEFAULT_LISTEN_PORT" fn-domains-generate-urls-from-config "$APP" "$DEFAULT_SCHEME" "$(hostname -f)" "$DEFAULT_LISTEN_PORT"
fi fi
fi fi
} }
fn-domains-generate-urls-from-config() { fn-domains-generate-urls-from-config() {
declare APP="$1" SCHEME="$2" VHOST="$3" DEFAULT_LISTEN_PORT="$4" declare APP="$1" DEFAULT_SCHEME="$2" VHOST="$3" DEFAULT_LISTEN_PORT="$4"
local APP_PORT_MAP="$(plugn trigger ports-get "$APP")" local APP_PORT_MAP="$(plugn trigger ports-get "$APP")"
if [[ "$(plugn trigger proxy-is-enabled "$APP")" == "false" ]]; then if [[ "$(plugn trigger proxy-is-enabled "$APP")" == "false" ]]; then
@@ -143,18 +143,22 @@ fn-domains-generate-urls-from-config() {
DOKKU_APP_WEB_LISTENERS="$(plugn trigger network-get-listeners "$APP" "web" | xargs)" DOKKU_APP_WEB_LISTENERS="$(plugn trigger network-get-listeners "$APP" "web" | xargs)"
for DOKKU_APP_WEB_LISTENER in $DOKKU_APP_WEB_LISTENERS; do for DOKKU_APP_WEB_LISTENER in $DOKKU_APP_WEB_LISTENERS; do
listen_port="$(echo "$DOKKU_APP_WEB_LISTENER" | cut -d ':' -f2)" listen_port="$(echo "$DOKKU_APP_WEB_LISTENER" | cut -d ':' -f2)"
fn-domains-generate-url "$SCHEME" "$VHOST" "$listen_port" fn-domains-generate-url "$DEFAULT_SCHEME" "$VHOST" "$listen_port"
done done
shopt -u nullglob shopt -u nullglob
elif [[ -n "$APP_PORT_MAP" ]]; then elif [[ -n "$APP_PORT_MAP" ]]; then
CERTS_EXIST="$(plugn trigger certs-exists "$APP")"
local port_map local port_map
while IFS= read -r port_map; do while IFS= read -r port_map; do
local scheme="$(awk -F ':' '{ print $1 }' <<<"$port_map")" local scheme="$(awk -F ':' '{ print $1 }' <<<"$port_map")"
local listen_port="$(awk -F ':' '{ print $2 }' <<<"$port_map")" local listen_port="$(awk -F ':' '{ print $2 }' <<<"$port_map")"
fn-domains-generate-url "$SCHEME" "$VHOST" "$listen_port" if [[ "$CERTS_EXIST" != "true" ]] && [[ "$scheme" == "https" ]]; then
continue
fi
fn-domains-generate-url "$scheme" "$VHOST" "$listen_port"
done <<<"$APP_PORT_MAP" done <<<"$APP_PORT_MAP"
else else
fn-domains-generate-url "$SCHEME" "$VHOST" "$DEFAULT_LISTEN_PORT" fn-domains-generate-url "$DEFAULT_SCHEME" "$VHOST" "$DEFAULT_LISTEN_PORT"
fi fi
} }
@@ -163,7 +167,11 @@ fn-domains-generate-url() {
if [[ "$PORT" == "80" ]]; then if [[ "$PORT" == "80" ]]; then
echo "http://$VHOST" echo "http://$VHOST"
elif [[ "$PORT" == "443" ]]; then elif [[ "$PORT" == "443" ]]; then
echo "https://$VHOST" if [[ "$SCHEME" == "https" ]]; then
echo "https://$VHOST"
else
echo "$SCHEME://$VHOST:$PORT"
fi
else else
echo "$SCHEME://$VHOST:$PORT" echo "$SCHEME://$VHOST:$PORT"
fi fi

View File

@@ -17,7 +17,7 @@ fn-openresty-vhosts-copy-from-image() {
fi fi
find "${DOKKU_LIB_ROOT}/data/openresty-vhosts/app-$APP/" -maxdepth 1 -name 'openresty-location-includes.*' -type d -exec rm -r {} + find "${DOKKU_LIB_ROOT}/data/openresty-vhosts/app-$APP/" -maxdepth 1 -name 'openresty-location-includes.*' -type d -exec rm -r {} +
copy_dir_from_image "$IMAGE_NAME" "$LOCATION_CONF_PATH" "${DOKKU_LIB_ROOT}/data/openresty-vhosts/app-$APP/openresty-location-includes.$DOKKU_PID" 2>/dev/null|| true copy_dir_from_image "$IMAGE_NAME" "$LOCATION_CONF_PATH" "${DOKKU_LIB_ROOT}/data/openresty-vhosts/app-$APP/openresty-location-includes.$DOKKU_PID" 2>/dev/null || true
if [[ ! -f "${DOKKU_LIB_ROOT}/data/openresty-vhosts/app-$APP/openresty-location-includes.$DOKKU_PID" ]]; then if [[ ! -f "${DOKKU_LIB_ROOT}/data/openresty-vhosts/app-$APP/openresty-location-includes.$DOKKU_PID" ]]; then
touch "${DOKKU_LIB_ROOT}/data/openresty-vhosts/app-$APP/openresty-location-includes.$DOKKU_PID.missing" touch "${DOKKU_LIB_ROOT}/data/openresty-vhosts/app-$APP/openresty-location-includes.$DOKKU_PID.missing"
fi fi

View File

@@ -410,3 +410,25 @@ teardown() {
assert_success assert_success
assert_output_contains "Detected IPv4 domain name with nginx proxy enabled." 0 assert_output_contains "Detected IPv4 domain name with nginx proxy enabled." 0
} }
@test "(domains) https:443" {
run /bin/bash -c "dokku domains:set $TEST_APP $TEST_APP.${DOKKU_DOMAIN}"
echo "output: $output"
echo "status: $status"
assert_success
run /bin/bash -c "dokku git:from-image $TEST_APP cockpithq/cockpit:core-latest"
echo "output: $output"
echo "status: $status"
assert_success
assert_output_contains "http://$TEST_APP.${DOKKU_DOMAIN}" 2
assert_output_contains "http://$TEST_APP.${DOKKU_DOMAIN}:2019"
assert_output_contains "udp://$TEST_APP.${DOKKU_DOMAIN}:443"
assert_output_contains "http://$TEST_APP.${DOKKU_DOMAIN}:443" 0
run /bin/bash -c "dokku ports:report $TEST_APP --ports-map-detected"
echo "output: $output"
echo "status: $status"
assert_success
assert_output "http:2019:2019 http:80:80 https:443:443 udp:443:443"
}