From 9ecfa843f0e32ff2004a6770c563fe81d1c6c6e9 Mon Sep 17 00:00:00 2001 From: Jose Diaz-Gonzalez Date: Fri, 6 Aug 2021 01:29:25 -0400 Subject: [PATCH] feat: add support for routing an app to a specified host:port This is useful when there is a service not managed by Dokku but should be exposed via the Dokku routing layer. As an example, some binaries (consul, nomad, vault) expose web uis, and are traditionally run on the host directly vs in a container. Closes #4665 --- docs/deployment/builders/null.md | 15 ++++++ docs/deployment/schedulers/null.md | 15 ++++++ docs/development/plugin-triggers.md | 15 ++++++ docs/networking/network.md | 34 +++++++++++++ plugins/builder-null/commands | 16 ++++++ plugins/builder-null/help-functions | 23 +++++++++ plugins/builder-null/plugin.toml | 4 ++ plugins/network/Makefile | 2 +- plugins/network/network.go | 43 +++++++++++++++- plugins/network/report.go | 5 ++ plugins/network/src/triggers/triggers.go | 4 ++ plugins/network/triggers.go | 7 +++ plugins/nginx-vhosts/functions | 10 ++-- plugins/scheduler-null/commands | 16 ++++++ plugins/scheduler-null/help-functions | 23 +++++++++ plugins/scheduler-null/plugin.toml | 4 ++ plugins/scheduler-null/scheduler-is-deployed | 17 +++++++ tests/unit/proxied-app.bats | 52 ++++++++++++++++++++ 18 files changed, 298 insertions(+), 7 deletions(-) create mode 100644 docs/deployment/builders/null.md create mode 100644 docs/deployment/schedulers/null.md create mode 100755 plugins/builder-null/commands create mode 100755 plugins/builder-null/help-functions create mode 100644 plugins/builder-null/plugin.toml create mode 100755 plugins/scheduler-null/commands create mode 100755 plugins/scheduler-null/help-functions create mode 100644 plugins/scheduler-null/plugin.toml create mode 100755 plugins/scheduler-null/scheduler-is-deployed create mode 100644 tests/unit/proxied-app.bats diff --git a/docs/deployment/builders/null.md b/docs/deployment/builders/null.md new file mode 100644 index 000000000..88a1b2f2d --- /dev/null +++ b/docs/deployment/builders/null.md @@ -0,0 +1,15 @@ +# Null Builder + +> New as of 0.25.0 + +The `null` builder does nothing, and is useful for routing to services not managed by Dokku. It should not be used in normal operation. Please see the [network documentation](/docs/networking/network.md#routing-an-app-to-a-known-ip:port-combination) for more information on the aforementioned use case. + +## Usage + +### Detection + +This builder is _never_ auto-detected. The builder _must_ be specified via the `builder:set` command: + +```shell +dokku builder:set node-js-app selected null +``` diff --git a/docs/deployment/schedulers/null.md b/docs/deployment/schedulers/null.md new file mode 100644 index 000000000..ad375508b --- /dev/null +++ b/docs/deployment/schedulers/null.md @@ -0,0 +1,15 @@ +# Null Scheduler + +> New as of 0.25.0 + +The `null` scheduler does nothing, and is useful for routing to services not managed by Dokku. It should not be used in normal operation. Please see the [network documentation](/docs/networking/network.md#routing-an-app-to-a-known-ip:port-combination) for more information on the aforementioned use case. + +## Usage + +### Detection + +This scheduler is _never_ auto-detected. The scheduler _must_ be specified via the `config:set` command: + +```shell +dokku config:set node-js-app DOCKER_SCHEDULER=null +``` diff --git a/docs/development/plugin-triggers.md b/docs/development/plugin-triggers.md index a3bf42e4d..ded3a5092 100644 --- a/docs/development/plugin-triggers.md +++ b/docs/development/plugin-triggers.md @@ -940,6 +940,21 @@ set -eo pipefail; [[ $DOKKU_TRACE ]] && set -x # TODO ``` +### `network-get-static-listeners` + +- Description: Return the network value for an app's property +- Invoked by: `internally triggered by proxy-build-config` +- Arguments: `$APP $PROCESS_TYPE` +- Example: + +```shell +#!/usr/bin/env bash + +set -eo pipefail; [[ $DOKKU_TRACE ]] && set -x + +# TODO +``` + ### `network-write-ipaddr` - Description: Write the ipaddr for a given app index diff --git a/docs/networking/network.md b/docs/networking/network.md index 5014873d0..095e23c36 100644 --- a/docs/networking/network.md +++ b/docs/networking/network.md @@ -123,6 +123,40 @@ dokku network:info test-network // TODO ``` +### Routing an app to a known ip:port combination + +> New as of 0.25.0 + +In some cases, it may be necessary to route an app to an existing `$IP:$PORT` combination. This is particularly the case for internal admin tools or services that aren't run by Dokku but have a web ui that would benefit from being exposed by Dokku. This can be done by setting a value for `static-web-lister` and running a few other commands when creating an app. + +```shell +# for a service listening on: +# - ip address: 127.0.0.1 +# - port: 8080 + +# create the app +dokku apps:create local-app + +# set the builder to the null builder, which does nothing +dokku builder:set local-app selected null + +# set the scheduler to the null scheduler, which does nothing +dokku config:set local-app DOKKU_SCHEDULER=null + +# set the static-web-listener network property to the ip:port combination for your app. +dokku network:set local-app static-web-listener 127.0.0.1:8080 + +# set the port map as desired for the port specified in your static-web-listener +dokku proxy:ports-set local-app http:80:8080 + +# set the domains desired +dokku domains:set local-app local-app.dokku.me + +dokku proxy:build-config local-app +``` + +Only a single `$IP:$PORT` combination can be routed to for a given app, and that `$IP:$PORT` combination _must_ be accessible to the proxy, or requests to the app may not resolve. + ### Attaching an app to a network > New as of 0.20.0, Requires Docker 1.21+ diff --git a/plugins/builder-null/commands b/plugins/builder-null/commands new file mode 100755 index 000000000..e86428144 --- /dev/null +++ b/plugins/builder-null/commands @@ -0,0 +1,16 @@ +#!/usr/bin/env bash +[[ " help builder-null:help " == *" $1 "* ]] || exit "$DOKKU_NOT_IMPLEMENTED_EXIT" +source "$PLUGIN_AVAILABLE_PATH/builder-null/help-functions" +set -eo pipefail +[[ $DOKKU_TRACE ]] && set -x + +case "$1" in + help | builder-null:help) + cmd-builder-null-help "$@" + ;; + + *) + exit "$DOKKU_NOT_IMPLEMENTED_EXIT" + ;; + +esac diff --git a/plugins/builder-null/help-functions b/plugins/builder-null/help-functions new file mode 100755 index 000000000..2eb62722a --- /dev/null +++ b/plugins/builder-null/help-functions @@ -0,0 +1,23 @@ +#!/usr/bin/env bash +set -eo pipefail +[[ $DOKKU_TRACE ]] && set -x + +cmd-builder-null-help() { + declare desc="help command" + declare CMD="$1" + local plugin_name="builder-null" + local plugin_description="No-op builder plugin" + + if [[ "$CMD" == "${plugin_name}:help" ]]; then + echo -e "Usage: dokku ${plugin_name}[:COMMAND]" + echo '' + echo "$plugin_description" + echo '' + elif [[ $(ps -o command= $PPID) == *"--all"* ]]; then + true + else + cat </dev/null) - if ! verify_image "$IMAGE" 2>/dev/null; then - dokku_log_fail "Missing image for app" + if [[ "$(plugn trigger network-get-static-listeners "$APP" "web")" == "" ]]; then + local IMAGE_TAG=$(get_running_image_tag "$APP") + local IMAGE=$(get_deploying_app_image_name "$APP" "$IMAGE_TAG" 2>/dev/null) + if ! verify_image "$IMAGE" 2>/dev/null; then + dokku_log_fail "Missing image for app" + fi fi local NGINX_BUILD_CONFIG_TMP_WORK_DIR=$(mktemp -d "/tmp/dokku-${DOKKU_PID}-${FUNCNAME[0]}.XXXXXX") diff --git a/plugins/scheduler-null/commands b/plugins/scheduler-null/commands new file mode 100755 index 000000000..d4d495cac --- /dev/null +++ b/plugins/scheduler-null/commands @@ -0,0 +1,16 @@ +#!/usr/bin/env bash +[[ " help scheduler-null:help " == *" $1 "* ]] || exit "$DOKKU_NOT_IMPLEMENTED_EXIT" +source "$PLUGIN_AVAILABLE_PATH/scheduler-null/help-functions" +set -eo pipefail +[[ $DOKKU_TRACE ]] && set -x + +case "$1" in + help | scheduler-null:help) + cmd-scheduler-null-help "$@" + ;; + + *) + exit "$DOKKU_NOT_IMPLEMENTED_EXIT" + ;; + +esac diff --git a/plugins/scheduler-null/help-functions b/plugins/scheduler-null/help-functions new file mode 100755 index 000000000..ef24ae7c2 --- /dev/null +++ b/plugins/scheduler-null/help-functions @@ -0,0 +1,23 @@ +#!/usr/bin/env bash +set -eo pipefail +[[ $DOKKU_TRACE ]] && set -x + +cmd-scheduler-null-help() { + declare desc="help command" + declare CMD="$1" + local plugin_name="scheduler-null" + local plugin_description="No-op scheduler plugin" + + if [[ "$CMD" == "${plugin_name}:help" ]]; then + echo -e "Usage: dokku ${plugin_name}[:COMMAND]" + echo '' + echo "$plugin_description" + echo '' + elif [[ $(ps -o command= $PPID) == *"--all"* ]]; then + true + else + cat <