-
-
Notifications
You must be signed in to change notification settings - Fork 2k
Support static nginx port when deploying without an application VHOST #1476
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
4dd4d7c
de6ccf4
943e9b3
89dd783
f84c2bf
e07ae7a
9efa8be
6e7ca94
b9ecb32
1e543af
467264d
70511c3
d3c218f
f914e62
3e18d9a
fd44635
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,7 +1,9 @@ | ||
| #!/usr/bin/env bash | ||
| [[ " build release trace delete ls logs run url urls version help " == *" $1 "* ]] || exit $DOKKU_NOT_IMPLEMENTED_EXIT | ||
| set -eo pipefail; [[ $DOKKU_TRACE ]] && set -x | ||
| source "$PLUGIN_CORE_AVAILABLE_PATH/common/functions" | ||
| source "$PLUGIN_AVAILABLE_PATH/config/functions" | ||
| source "$PLUGIN_AVAILABLE_PATH/nginx-vhosts/functions" | ||
|
|
||
| case "$1" in | ||
| build) | ||
|
|
@@ -189,12 +191,22 @@ case "$1" in | |
| SCHEME="https" | ||
| fi | ||
|
|
||
| if [[ -f "$DOKKU_ROOT/VHOST" ]] && [[ "$NO_VHOST" != "1" ]]; then | ||
| echo "$SCHEME://$(< "$DOKKU_ROOT/VHOST")" | ||
| else | ||
| if [[ "$(is_app_vhost_enabled $APP)" == "false" ]]; then | ||
| for PORT_FILE in $DOKKU_ROOT/$APP/PORT.*; do | ||
| echo "$SCHEME://$(< "$DOKKU_ROOT/HOSTNAME"):$(< "$PORT_FILE")" | ||
| echo "http://$(< "$DOKKU_ROOT/HOSTNAME"):$(< "$PORT_FILE") (container)" | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Why the hardcoded scheme here? What about https?
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. this is only if vhost is disabled and we print out the ssl version only if we have a port |
||
| done | ||
|
|
||
| DOKKU_NGINX_PORT=$(config_get $APP DOKKU_NGINX_PORT || true) | ||
| DOKKU_NGINX_SSL_PORT=$(config_get $APP DOKKU_NGINX_SSL_PORT || true) | ||
|
|
||
| if [[ -n "$DOKKU_NGINX_PORT" ]]; then | ||
| echo "http://$(< "$DOKKU_ROOT/HOSTNAME"):$DOKKU_NGINX_PORT (nginx)" | ||
| fi | ||
| if [[ -n "$DOKKU_NGINX_SSL_PORT" ]]; then | ||
| echo "https://$(< "$DOKKU_ROOT/HOSTNAME"):$DOKKU_NGINX_SSL_PORT (nginx-ssl)" | ||
| fi | ||
| else | ||
| echo "$SCHEME://$(< "$DOKKU_ROOT/VHOST")" | ||
| fi | ||
| ;; | ||
|
|
||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,7 +1,9 @@ | ||
| #!/usr/bin/env bash | ||
| [[ " certs:add certs:generate certs:info certs:remove certs:update help certs:help " == *" $1 "* ]] || exit $DOKKU_NOT_IMPLEMENTED_EXIT | ||
| set -eo pipefail; [[ $DOKKU_TRACE ]] && set -x | ||
| source "$PLUGIN_CORE_AVAILABLE_PATH/common/functions" | ||
| source "$PLUGIN_AVAILABLE_PATH/certs/functions" | ||
| source "$PLUGIN_AVAILABLE_PATH/nginx-vhosts/functions" | ||
|
|
||
| is_tar_import() { | ||
| [[ -t 0 ]] && return 1 | ||
|
|
@@ -57,7 +59,7 @@ certs_set() { | |
| mv "$KEY_FILE" "$DOKKU_ROOT/$APP/tls/server.key" | ||
| cd $DOKKU_ROOT | ||
| rm -rf $TEMP_DIR | ||
| dokku nginx:build-config $APP | ||
| nginx_build_config $APP | ||
| } | ||
|
|
||
| case "$1" in | ||
|
|
@@ -84,7 +86,7 @@ case "$1" in | |
| mkdir -p "$DOKKU_ROOT/$APP/tls" | ||
| dokku_log_info1 "Installing certificate and key..." | ||
| mv -f $TMP_WORK_DIR/server.key $TMP_WORK_DIR/server.crt $SSL_PATH | ||
| [[ -n "$DOMAIN" ]] && (dokku domains:add $APP $DOMAIN || dokku nginx:build-config $APP) | ||
| [[ -n "$DOMAIN" ]] && (dokku domains:add $APP $DOMAIN || nginx_build_config $APP) | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yay for smaller trace output! |
||
| dokku_log_info1 "The following is a certificate signing request that can be used" | ||
| dokku_log_info1 "to generate an 'officially' signed SSL certificate for $APP at $DOMAIN" | ||
| dokku_log_info1 "by a CA of your choosing." | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -330,3 +330,15 @@ docker_cleanup() { | |
| # shellcheck disable=SC2046 | ||
| docker rmi $(docker images -f 'dangling=true' -q) &> /dev/null & | ||
| } | ||
|
|
||
| get_available_port() { | ||
| while true; do | ||
| local port=$(shuf -i 1025-65535 -n 1) | ||
|
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. ?
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. just showing what provides |
||
| if ! nc -z 0.0.0.0 $port; then | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think your if statement is missing the brackets to evaluate this and you have a continue in an if statement?
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. it twerks: |
||
| echo $port | ||
| return 0 | ||
| else | ||
| continue | ||
| fi | ||
| done | ||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -214,6 +214,7 @@ config_unset() { | |
| ENV_TEMP=$(echo "${ENV_TEMP}" | sed "/^export $var=/ d") | ||
|
|
||
| config_write "$ENV_TEMP" | ||
| [[ "$var" == "NO_VHOST" ]] && config_set --no-restart $APP NO_VHOST=0 && DOKKU_CONFIG_RESTART=true | ||
|
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. it was impossible to support transitions from
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Why
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. To ensure consistency |
||
| done | ||
|
|
||
| if [[ "$DOKKU_CONFIG_RESTART" == "true" ]]; then | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,41 +1,13 @@ | ||
| #!/usr/bin/env bash | ||
| set -eo pipefail; [[ $DOKKU_TRACE ]] && set -x | ||
| source "$PLUGIN_AVAILABLE_PATH/config/functions" | ||
| source "$PLUGIN_AVAILABLE_PATH/nginx-vhosts/functions" | ||
|
|
||
| APP="$1" | ||
| NO_VHOST=$(config_get $APP NO_VHOST || true) | ||
|
|
||
| RE_IPV4="([0-9]{1,3}[\.]){3}[0-9]{1,3}" | ||
|
|
||
| RE_IPV6="([0-9a-fA-F]{1,4}:){7,7}[0-9a-fA-F]{1,4}|" # TEST: 1:2:3:4:5:6:7:8 | ||
| RE_IPV6="${RE_IPV6}([0-9a-fA-F]{1,4}:){1,7}:|" # TEST: 1:: 1:2:3:4:5:6:7:: | ||
| RE_IPV6="${RE_IPV6}([0-9a-fA-F]{1,4}:){1,6}:[0-9a-fA-F]{1,4}|" # TEST: 1::8 1:2:3:4:5:6::8 1:2:3:4:5:6::8 | ||
| RE_IPV6="${RE_IPV6}([0-9a-fA-F]{1,4}:){1,5}(:[0-9a-fA-F]{1,4}){1,2}|" # TEST: 1::7:8 1:2:3:4:5::7:8 1:2:3:4:5::8 | ||
| RE_IPV6="${RE_IPV6}([0-9a-fA-F]{1,4}:){1,4}(:[0-9a-fA-F]{1,4}){1,3}|" # TEST: 1::6:7:8 1:2:3:4::6:7:8 1:2:3:4::8 | ||
| RE_IPV6="${RE_IPV6}([0-9a-fA-F]{1,4}:){1,3}(:[0-9a-fA-F]{1,4}){1,4}|" # TEST: 1::5:6:7:8 1:2:3::5:6:7:8 1:2:3::8 | ||
| RE_IPV6="${RE_IPV6}([0-9a-fA-F]{1,4}:){1,2}(:[0-9a-fA-F]{1,4}){1,5}|" # TEST: 1::4:5:6:7:8 1:2::4:5:6:7:8 1:2::8 | ||
| RE_IPV6="${RE_IPV6}[0-9a-fA-F]{1,4}:((:[0-9a-fA-F]{1,4}){1,6})|" # TEST: 1::3:4:5:6:7:8 1::3:4:5:6:7:8 1::8 | ||
| RE_IPV6="${RE_IPV6}:((:[0-9a-fA-F]{1,4}){1,7}|:)|" # TEST: ::2:3:4:5:6:7:8 ::2:3:4:5:6:7:8 ::8 :: | ||
| RE_IPV6="${RE_IPV6}fe08:(:[0-9a-fA-F]{1,4}){2,2}%[0-9a-zA-Z]{1,}|" # TEST: fe08::7:8%eth0 fe08::7:8%1 (link-local IPv6 addresses with zone index) | ||
| RE_IPV6="${RE_IPV6}::(ffff(:0{1,4}){0,1}:){0,1}${RE_IPV4}|" # TEST: ::255.255.255.255 ::ffff:255.255.255.255 ::ffff:0:255.255.255.255 (IPv4-mapped IPv6 addresses and IPv4-translated addresses) | ||
| RE_IPV6="${RE_IPV6}([0-9a-fA-F]{1,4}:){1,4}:${RE_IPV4}" # TEST: 2001:db8:3:4::192.0.2.33 64:ff9b::192.0.2.33 | ||
|
|
||
|
|
||
| # Ensure the ip address continues to the end of the line | ||
| # Fixes using a wildcard dns service such as xip.io which allows for *.<ip address>.xip.io | ||
| RE_IPV4="${RE_IPV4}\$" | ||
| RE_IPV6="${RE_IPV6}\$" | ||
|
|
||
| [[ -f "$DOKKU_ROOT/VHOST" ]] && GLOBAL_VHOST=$(< "$DOKKU_ROOT/VHOST") | ||
|
|
||
| if [[ -n "$NO_VHOST" ]]; then | ||
| if [[ "$(is_app_vhost_enabled $APP)" == "false" ]]; then | ||
| echo true # bind to external ip. VHOST is disabled | ||
| elif [[ "$GLOBAL_VHOST" =~ $RE_IPV4 ]] || [[ "$GLOBAL_VHOST" =~ $RE_IPV6 ]]; then | ||
| echo true # bind to external ip. GLOBAL_VHOST is somehow an IPv4 or IPv6 address | ||
| elif [[ -z "$GLOBAL_VHOST" ]] && [[ ! -f "$DOKKU_ROOT/$APP/VHOST" ]]; then | ||
| echo true # bind to external ip. no GLOBAL_VHOST and no app vhost | ||
| elif [[ -f "$DOKKU_ROOT/$APP/VHOST" ]]; then | ||
| echo false # bind to docker ip. this app has a vhost defined | ||
| elif [[ "$(is_global_vhost_enabled $APP)" == "false" ]] && [[ ! -f "$DOKKU_ROOT/$APP/VHOST" ]]; then | ||
| echo true # bind to external ip. no global vhost or global vhost is an ip | ||
| else | ||
| echo false | ||
| fi |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should we add port as an option to
nginx:enableso that users can modify the port to their preferred value?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
eh? 🤷
just set the config var...?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fine by me :)