From d7d5d373c9b598415741e37e1eb238cbb82c50f5 Mon Sep 17 00:00:00 2001 From: Jose Diaz-Gonzalez Date: Fri, 21 Apr 2017 02:44:25 -0600 Subject: [PATCH] feat: refactor to retrieve listeners from network plugin --- plugins/network/functions | 15 +++++++++++++++ plugins/network/network-get-listeners | 5 +++++ plugins/nginx-vhosts/functions | 8 +------- 3 files changed, 21 insertions(+), 7 deletions(-) create mode 100755 plugins/network/network-get-listeners diff --git a/plugins/network/functions b/plugins/network/functions index 106dfdd28..75393c391 100755 --- a/plugins/network/functions +++ b/plugins/network/functions @@ -94,6 +94,21 @@ network-get-container-ipaddr() { echo "$IP_ADDRESS" } +network-get-container-listeners() { + declare desc="Return the listeners (host:port combinations) for a given app container" + declare APP="$1" + + local IP_FILE LISTENER_IP LISTENER_PORT LISTENERS PORT_FILE + for IP_FILE in $DOKKU_ROOT/$APP/IP.web.*; do + local PORT_FILE="${IP_FILE//IP/PORT}" + local LISTENER_IP=$(< "$IP_FILE") + local LISTENER_PORT=$(< "$PORT_FILE") + local LISTENERS+="$LISTENER_IP:$LISTENER_PORT " + done + + echo "$LISTENERS" +} + network-get-container-port() { declare desc="Return the port for a given app container" declare APP="$1" PROC_TYPE="$2" CID="$3" diff --git a/plugins/network/network-get-listeners b/plugins/network/network-get-listeners new file mode 100755 index 000000000..9d71e0d11 --- /dev/null +++ b/plugins/network/network-get-listeners @@ -0,0 +1,5 @@ +#!/usr/bin/env bash +set -eo pipefail; [[ $DOKKU_TRACE ]] && set -x +source "$PLUGIN_AVAILABLE_PATH/network/functions" + +network-get-container-listeners "$@" diff --git a/plugins/nginx-vhosts/functions b/plugins/nginx-vhosts/functions index 4792550df..82e3ab0bb 100755 --- a/plugins/nginx-vhosts/functions +++ b/plugins/nginx-vhosts/functions @@ -229,13 +229,7 @@ nginx_build_config() { if [[ -z "$DOKKU_DISABLE_PROXY" ]]; then if [[ -z "$DOKKU_APP_LISTEN_PORT" ]] && [[ -z "$DOKKU_APP_LISTEN_IP" ]]; then shopt -s nullglob - local DOKKU_APP_IP_FILE - for DOKKU_APP_IP_FILE in $DOKKU_ROOT/$APP/IP.web.*; do - local DOKKU_APP_PORT_FILE="${DOKKU_APP_IP_FILE//IP/PORT}" - local DOKKU_APP_LISTENER_IP=$(< "$DOKKU_APP_IP_FILE") - local DOKKU_APP_LISTENER_PORT=$(< "$DOKKU_APP_PORT_FILE") - local DOKKU_APP_LISTENERS+="$DOKKU_APP_LISTENER_IP:$DOKKU_APP_LISTENER_PORT " - done + local DOKKU_APP_LISTENERS="$(plugn trigger network-get-listeners "$APP")" local DOKKU_APP_LISTENERS="$(echo "$DOKKU_APP_LISTENERS" | xargs)" shopt -u nullglob elif [[ -n "$DOKKU_APP_LISTEN_PORT" ]] && [[ -n "$DOKKU_APP_LISTEN_IP" ]]; then