Merge pull request #4125 from dokku/4086-custom-nginx-app-conf-location
Allow customizing the various nginx templates
This commit is contained in:
4 files changed
+48
-5
No files matched your search
@@ -854,6 +854,36 @@ set -eo pipefail; [[ $DOKKU_TRACE ]] && set -x
|
|||||||
# TODO
|
# TODO
|
||||||
```
|
```
|
||||||
|
|
||||||
|
### `nginx-app-template-source`
|
||||||
|
|
||||||
|
- Description: Return the path to a `sigil` template that should be used to generate a given nginx configuration file.
|
||||||
|
- Invoked by: `nginx-vhosts#build-config`
|
||||||
|
- Arguments: `$APP $TEMPLATE_TYPE`
|
||||||
|
- The `TEMPLATE_TYPE` argument can be one of: `[app-config, hsts-config, validate-config]`
|
||||||
|
- Example:
|
||||||
|
|
||||||
|
```shell
|
||||||
|
#!/usr/bin/env bash
|
||||||
|
|
||||||
|
set -eo pipefail; [[ $DOKKU_TRACE ]] && set -x
|
||||||
|
source "$PLUGIN_CORE_AVAILABLE_PATH/common/functions"
|
||||||
|
|
||||||
|
APP="$1"
|
||||||
|
TEMPLATE_TYPE="$2"
|
||||||
|
case "$TEMPLATE_TYPE" in
|
||||||
|
app-config)
|
||||||
|
echo "$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)/app.conf.sigil";;
|
||||||
|
hsts-config)
|
||||||
|
echo "$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)/hsts.conf.sigil";;
|
||||||
|
validate-config)
|
||||||
|
echo "$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)/validate.conf.sigil";;
|
||||||
|
*)
|
||||||
|
dokku_log_fail "Invalid template type: ${TEMPLATE_TYPE}"
|
||||||
|
esac
|
||||||
|
```
|
||||||
|
|
||||||
|
The default templates are viewable here: [plugins/nginx-vhosts/templates/](https://github.com/dokku/dokku/tree/master/plugins/nginx-vhosts/templates)
|
||||||
|
|
||||||
### `nginx-dokku-template-source`
|
### `nginx-dokku-template-source`
|
||||||
|
|
||||||
- Description: Return the path to a `sigil` template that should be used to generate the `dokku.conf` nginx configuration file.
|
- Description: Return the path to a `sigil` template that should be used to generate the `dokku.conf` nginx configuration file.
|
||||||
|
|||||||
@@ -0,0 +1 @@
|
|||||||
|
hook
|
||||||
@@ -315,21 +315,23 @@ is_grpc_enabled() {
|
|||||||
|
|
||||||
nginx_build_config() {
|
nginx_build_config() {
|
||||||
declare desc="build nginx config to proxy app containers using sigil"
|
declare desc="build nginx config to proxy app containers using sigil"
|
||||||
local APP="$1"
|
declare APP="$1" DOKKU_APP_LISTEN_PORT="$2" DOKKU_APP_LISTEN_IP="$3"
|
||||||
verify_app_name "$APP"
|
verify_app_name "$APP"
|
||||||
local DOKKU_APP_LISTEN_PORT="$2"
|
|
||||||
local DOKKU_APP_LISTEN_IP="$3"
|
|
||||||
local VHOST_PATH="$DOKKU_ROOT/$APP/VHOST"
|
local VHOST_PATH="$DOKKU_ROOT/$APP/VHOST"
|
||||||
local APP_URLS_PATH="$DOKKU_ROOT/$APP/URLS"
|
local APP_URLS_PATH="$DOKKU_ROOT/$APP/URLS"
|
||||||
local NGINX_TEMPLATE_NAME="nginx.conf.sigil"
|
local NGINX_TEMPLATE_NAME="nginx.conf.sigil"
|
||||||
local DEFAULT_NGINX_TEMPLATE="$PLUGIN_AVAILABLE_PATH/nginx-vhosts/templates/$NGINX_TEMPLATE_NAME"
|
local NGINX_TEMPLATE="$PLUGIN_AVAILABLE_PATH/nginx-vhosts/templates/$NGINX_TEMPLATE_NAME"
|
||||||
local NGINX_TEMPLATE="$DEFAULT_NGINX_TEMPLATE"
|
|
||||||
local SCHEME=http
|
local SCHEME=http
|
||||||
local NGINX_TEMPLATE_SOURCE="built-in"
|
local NGINX_TEMPLATE_SOURCE="built-in"
|
||||||
local APP_SSL_PATH="$DOKKU_ROOT/$APP/tls"
|
local APP_SSL_PATH="$DOKKU_ROOT/$APP/tls"
|
||||||
local RAW_TCP_PORTS="$(get_app_raw_tcp_ports "$APP")"
|
local RAW_TCP_PORTS="$(get_app_raw_tcp_ports "$APP")"
|
||||||
local DOKKU_APP_LISTENERS
|
local DOKKU_APP_LISTENERS
|
||||||
|
|
||||||
|
CUSTOM_NGINX_TEMPLATE="$(plugn trigger nginx-app-template-source "$APP" "app-config")"
|
||||||
|
if [[ -n "$CUSTOM_NGINX_TEMPLATE" ]]; then
|
||||||
|
NGINX_TEMPLATE="$CUSTOM_NGINX_TEMPLATE"
|
||||||
|
fi
|
||||||
|
|
||||||
local IS_APP_VHOST_ENABLED=true
|
local IS_APP_VHOST_ENABLED=true
|
||||||
plugn trigger domains-vhost-enabled "$APP" || IS_APP_VHOST_ENABLED=false
|
plugn trigger domains-vhost-enabled "$APP" || IS_APP_VHOST_ENABLED=false
|
||||||
|
|
||||||
|
|||||||
@@ -22,6 +22,11 @@ fn-nginx-vhosts-manage-hsts() {
|
|||||||
local NGINX_HSTS_CONF="$DOKKU_ROOT/$APP/nginx.conf.d/hsts.conf"
|
local NGINX_HSTS_CONF="$DOKKU_ROOT/$APP/nginx.conf.d/hsts.conf"
|
||||||
local HSTS_TEMPLATE="$PLUGIN_AVAILABLE_PATH/nginx-vhosts/templates/hsts.conf.sigil"
|
local HSTS_TEMPLATE="$PLUGIN_AVAILABLE_PATH/nginx-vhosts/templates/hsts.conf.sigil"
|
||||||
|
|
||||||
|
CUSTOM_HSTS_TEMPLATE="$(plugn trigger nginx-app-template-source "$APP" "hsts-config")"
|
||||||
|
if [[ -n "$CUSTOM_HSTS_TEMPLATE" ]]; then
|
||||||
|
HSTS_TEMPLATE="$CUSTOM_HSTS_TEMPLATE"
|
||||||
|
fi
|
||||||
|
|
||||||
if [[ "$HSTS" == "false" ]] || [[ "$SSL_ENABLED" != "true" ]]; then
|
if [[ "$HSTS" == "false" ]] || [[ "$SSL_ENABLED" != "true" ]]; then
|
||||||
rm -rf "$NGINX_HSTS_CONF"
|
rm -rf "$NGINX_HSTS_CONF"
|
||||||
return
|
return
|
||||||
@@ -137,6 +142,11 @@ nginx_vhosts_is_valid_nginx_config_func() {
|
|||||||
local TMP_OUTPUT=$(mktemp "/tmp/dokku-${DOKKU_PID}-${FUNCNAME[0]}.XXXXXX")
|
local TMP_OUTPUT=$(mktemp "/tmp/dokku-${DOKKU_PID}-${FUNCNAME[0]}.XXXXXX")
|
||||||
trap "rm -rf '$TMP_OUTPUT' >/dev/null" RETURN INT TERM EXIT
|
trap "rm -rf '$TMP_OUTPUT' >/dev/null" RETURN INT TERM EXIT
|
||||||
|
|
||||||
|
CUSTOM_VALIDATE_TEMPLATE="$(plugn trigger nginx-app-template-source "$APP" "validate-config")"
|
||||||
|
if [[ -n "$CUSTOM_VALIDATE_TEMPLATE" ]]; then
|
||||||
|
VALIDATE_TEMPLATE="$CUSTOM_VALIDATE_TEMPLATE"
|
||||||
|
fi
|
||||||
|
|
||||||
sigil -f "$VALIDATE_TEMPLATE" NGINX_CONF="$DOKKU_ROOT/$APP/nginx.conf" | cat -s >"$TMP_OUTPUT"
|
sigil -f "$VALIDATE_TEMPLATE" NGINX_CONF="$DOKKU_ROOT/$APP/nginx.conf" | cat -s >"$TMP_OUTPUT"
|
||||||
sudo "$NGINX_LOCATION" -t -c "$TMP_OUTPUT" 2>/dev/null
|
sudo "$NGINX_LOCATION" -t -c "$TMP_OUTPUT" 2>/dev/null
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in new issue
Block a user