From 2b19881f014a8cdbb02683da063397993e46aa20 Mon Sep 17 00:00:00 2001 From: Michael Hobbs Date: Wed, 15 Jun 2016 18:05:10 -0700 Subject: [PATCH] [ci skip] port mapping docs --- docs/appendices/0.6.0-migration-guide.md | 4 ++ docs/development/plugin-triggers.md | 88 ++++++++++++++++++++++++ docs/nginx.md | 49 +++++++++++++ docs/proxy.md | 11 ++- 4 files changed, 149 insertions(+), 3 deletions(-) diff --git a/docs/appendices/0.6.0-migration-guide.md b/docs/appendices/0.6.0-migration-guide.md index bb9313828..ed5871238 100644 --- a/docs/appendices/0.6.0-migration-guide.md +++ b/docs/appendices/0.6.0-migration-guide.md @@ -7,3 +7,7 @@ - `DOKKU_CHECKS_DISABLED` is now a thing - The values for the above can be a comma-separated list of process-types or the literal string `_all_` - See the [updated `checks`](/dokku/checks-examples/) docs for more info + +## proxy port mapping +- You can now configure host -> container proxy port mappings + - The UI is handled by the [proxy](/dokku/proxy/) interface plugin by setting the `DOKKU_PROXY_PORT_MAP` config variable in the format of `scheme:host-port:container-port`. The default `nginx-vhosts` proxy plugin supports both the `http` and `https` schemes. diff --git a/docs/development/plugin-triggers.md b/docs/development/plugin-triggers.md index da1683002..4b2933f44 100644 --- a/docs/development/plugin-triggers.md +++ b/docs/development/plugin-triggers.md @@ -400,6 +400,26 @@ set -eo pipefail; [[ $DOKKU_TRACE ]] && set -x sudo service haproxy reload ``` +### `post-proxy-ports-update` + +- Description: Allows you to run commands once the proxy port mappings for an application have been updated. It also sends the invoking command. This can be "add", "clear" or "remove". +- Invoked by: `dokku proxy:ports-add`, `dokku proxy:ports-clear`, `dokku proxy:ports-remove` +- Arguments: `$APP` `action name` +- Example: + +```shell +#!/usr/bin/env bash +# Rebuilds haproxy config for our imaginary haproxy plugin +# that replaces the nginx-vhosts plugin + +set -eo pipefail; [[ $DOKKU_TRACE ]] && set -x +source "$PLUGIN_CORE_AVAILABLE_PATH/common/functions" +source "$PLUGIN_AVAILABLE_PATH/haproxy/functions" +APP="$1"; verify_app_name "$APP" + +haproxy-build-config "$APP" +``` + ### `post-release-buildpack` - Description: Allows you to run commands after environment variables are set for the release step of the deploy. Only applies to applications using buildpacks. @@ -602,6 +622,74 @@ verify_app_name "$APP" # TODO ``` +### `pre-disable-vhost` + +- Description: Allows you to run commands before the VHOST feature is disabled +- Invoked by: `dokku domains:disable` +- Arguments: `$APP` +- Example: + +```shell +#!/usr/bin/env bash + +set -eo pipefail; [[ $DOKKU_TRACE ]] && set -x +source "$PLUGIN_CORE_AVAILABLE_PATH/common/functions" +APP="$1"; verify_app_name "$APP" + +# TODO +``` + +### `pre-enable-vhost` + +- Description: Allows you to run commands before the VHOST feature is enabled +- Invoked by: `dokku domains:enable` +- Arguments: `$APP` +- Example: + +```shell +#!/usr/bin/env bash + +set -eo pipefail; [[ $DOKKU_TRACE ]] && set -x +source "$PLUGIN_CORE_AVAILABLE_PATH/common/functions" +APP="$1"; verify_app_name "$APP" + +# TODO +``` + +### `post-certs-update` + +- Description: Allows you to run commands after a cert is added/updated +- Invoked by: `dokku certs:add`, `dokku certs:update` +- Arguments: `$APP` +- Example: + +```shell +#!/usr/bin/env bash + +set -eo pipefail; [[ $DOKKU_TRACE ]] && set -x +source "$PLUGIN_CORE_AVAILABLE_PATH/common/functions" +APP="$1"; verify_app_name "$APP" + +# TODO +``` + +### `post-certs-remove` + +- Description: Allows you to run commands after a cert is removed +- Invoked by: `dokku certs:remove` +- Arguments: `$APP` +- Example: + +```shell +#!/usr/bin/env bash + +set -eo pipefail; [[ $DOKKU_TRACE ]] && set -x +source "$PLUGIN_CORE_AVAILABLE_PATH/common/functions" +APP="$1"; verify_app_name "$APP" + +# TODO +``` + ### `receive-app` - Description: Allows you to customize what occurs when an app is received. Normally just triggers an application build. diff --git a/docs/nginx.md b/docs/nginx.md index 642853aea..4f739ae3f 100644 --- a/docs/nginx.md +++ b/docs/nginx.md @@ -73,6 +73,7 @@ upstream {{ .APP }} { {{ .NGINX_SSL_PORT }} SSL nginx listener port (same as `DOKKU_NGINX_SSL_PORT` config var) {{ .NOSSL_SERVER_NAME }} List of non-SSL VHOSTS {{ .PROXY_PORT_MAP }} List of port mappings (same as `DOKKU_PROXY_PORT_MAP` config var) +{{ .PROXY_UPSTREAM_PORTS }} List of configured upstream ports (derived from `DOKKU_PROXY_PORT_MAP` config var) {{ .RAW_TCP_PORTS }} List of exposed tcp ports as defined by Dockerfile `EXPOSE` directive (**Dockerfile apps only**) {{ .SSL_INUSE }} Boolean set when an app is SSL-enabled {{ .SSL_SERVER_NAME }} List of SSL VHOSTS @@ -128,6 +129,54 @@ upstream {{ .APP }} { } ``` +### Example using new proxy port mapping +``` +{{ range $port_map := .PROXY_PORT_MAP | split " " }} +{{ $port_map_list := $port_map | split ":" }} +{{ $scheme := index $port_map_list 0 }} +{{ $listen_port := index $port_map_list 1 }} +{{ $upstream_port := index $port_map_list 2 }} + +server { + listen [::]:{{ $listen_port }}; + listen {{ $listen_port }}; + server_name {{ $.NOSSL_SERVER_NAME }}; + access_log /var/log/nginx/{{ $.APP }}-access.log; + error_log /var/log/nginx/{{ $.APP }}-error.log; + + location / { + + gzip on; + gzip_min_length 1100; + gzip_buffers 4 32k; + gzip_types text/css text/javascript text/xml text/plain text/x-component application/javascript application/x-javascript application/json application/xml application/rss+xml font/truetype application/x-font-ttf font/opentype application/vnd.ms-fontobject image/svg+xml; + gzip_vary on; + gzip_comp_level 6; + + proxy_pass http://{{ $.APP }}-{{ $upstream_port }}; + proxy_http_version 1.1; + proxy_set_header Upgrade $http_upgrade; + proxy_set_header Connection "upgrade"; + proxy_set_header Host $http_host; + proxy_set_header X-Forwarded-Proto $scheme; + proxy_set_header X-Forwarded-For $remote_addr; + proxy_set_header X-Forwarded-Port $server_port; + proxy_set_header X-Request-Start $msec; + } + include {{ $.DOKKU_ROOT }}/{{ $.APP }}/nginx.conf.d/*.conf; +} + +{{ range $upstream_port := $.PROXY_UPSTREAM_PORTS | split " " }} +upstream {{ $.APP }}-{{ $upstream_port }} { +{{ range $listeners := $.DOKKU_APP_LISTENERS | split " " }} +{{ $listener_list := $listeners | split ":" }} +{{ $listener_ip := index $listener_list 0 }} +{{ $listener_port := index $listener_list 1 }} + server {{ $listener_ip }}:{{ $upstream_port }};{{ end }} +} +{{ end }} +``` + ### Customizing via configuration files included by the default templates The default nginx.conf template will include everything from your apps `nginx.conf.d/` subdirectory in the main `server {}` block (see above): diff --git a/docs/proxy.md b/docs/proxy.md index 8ca604f7b..2fcbd2256 100644 --- a/docs/proxy.md +++ b/docs/proxy.md @@ -5,9 +5,14 @@ As of dokku 0.5.0, the proxy functionality has been decoupled from the nginx-vhosts plugin into the proxy plugin. In the future this will allow other proxy software (HAproxy for example) to be used instead of nginx. ``` -proxy:disable Disable proxy for app -proxy:enable Enable proxy for app -proxy:set NOT IMPLEMENTED YET!! +proxy Show proxy settings for app +proxy:disable Disable proxy for app +proxy:enable Enable proxy for app +proxy:ports List proxy port mappings for app +proxy:ports-add :: [::...] Set proxy port mappings for app +proxy:ports-clear Clear all proxy port mappings for app +proxy:ports-remove [...] Unset proxy port mappings for app +proxy:set Set proxy type for app ``` ## Container network interface binding