diff --git a/docs/development/plugin-triggers.md b/docs/development/plugin-triggers.md index 0fba2a33a..5b560f956 100644 --- a/docs/development/plugin-triggers.md +++ b/docs/development/plugin-triggers.md @@ -374,6 +374,21 @@ set -eo pipefail; [[ $DOKKU_TRACE ]] && set -x # TODO ``` +### `network-config-exists` + +- Description: Returns whether the network configuration for a given app exists +- Invoked by: `internally triggered by core-post-deploy within proxy implementations` +- Arguments: `$APP` +- Example: + +```shell +#!/usr/bin/env bash + +set -eo pipefail; [[ $DOKKU_TRACE ]] && set -x + +# TODO +``` + ### `network-get-ipaddr` - Description: Return the ipaddr for a given app container diff --git a/plugins/network/Makefile b/plugins/network/Makefile index 0eab0fd09..5a8a6f690 100644 --- a/plugins/network/Makefile +++ b/plugins/network/Makefile @@ -9,7 +9,7 @@ build-in-docker: clean build: commands subcommands triggers subcommands: subcommands/rebuild subcommands/rebuildall -triggers: network-build-config network-compute-ports network-get-ipaddr network-get-listeners network-get-port network-write-ipaddr network-write-port +triggers: network-build-config network-compute-ports network-config-exists network-get-ipaddr network-get-listeners network-get-port network-write-ipaddr network-write-port commands: **/**/commands.go go build -a -o commands src/commands/commands.go @@ -25,6 +25,9 @@ network-build-config: **/**/**/network-build-config.go network-compute-ports: **/**/**/network-compute-ports.go go build -a -o network-compute-ports src/triggers/network-compute-ports/network-compute-ports.go +network-config-exists: **/**/**/network-config-exists.go + go build -a -o network-config-exists src/triggers/network-config-exists/network-config-exists.go + network-get-ipaddr: **/**/**/network-get-ipaddr.go go build -a -o network-get-ipaddr src/triggers/network-get-ipaddr/network-get-ipaddr.go diff --git a/plugins/network/network.go b/plugins/network/network.go index 69979c1d1..4e48f3f7a 100644 --- a/plugins/network/network.go +++ b/plugins/network/network.go @@ -76,6 +76,15 @@ func GetContainerPort(appName string, procType string, isHerokuishContainer bool return port } +// HasNetworkConfig returns whether the network configuration for a given app exists +func HasNetworkConfig(appName string) bool { + appRoot := strings.Join([]string{common.MustGetEnv("DOKKU_ROOT"), appName}, "/") + ipfile := fmt.Sprintf("%v/IP.web.1", appRoot) + portfile := fmt.Sprintf("%v/PORT.web.1", appRoot) + + return common.FileExists(ipfile) && common.FileExists(portfile) +} + // BuildConfig builds network config files func BuildConfig(appName string) { err := common.VerifyAppName(appName) diff --git a/plugins/network/src/triggers/network-config-exists/network-config-exists.go b/plugins/network/src/triggers/network-config-exists/network-config-exists.go new file mode 100644 index 000000000..43efedc95 --- /dev/null +++ b/plugins/network/src/triggers/network-config-exists/network-config-exists.go @@ -0,0 +1,22 @@ +package main + +import ( + "flag" + "fmt" + "os" + + network "github.com/dokku/dokku/plugins/network" +) + +// write the ipaddress to stdout for a given app container +func main() { + flag.Parse() + appName := flag.Arg(0) + + if network.HasNetworkConfig(appName) { + fmt.Fprintln(os.Stdout, "true") + return + } + + fmt.Fprintln(os.Stdout, "false") +} diff --git a/plugins/nginx-vhosts/core-post-deploy b/plugins/nginx-vhosts/core-post-deploy index 7bb7db877..493fd2da2 100755 --- a/plugins/nginx-vhosts/core-post-deploy +++ b/plugins/nginx-vhosts/core-post-deploy @@ -9,7 +9,10 @@ nginx_core_post_deploy() { declare desc="nginx-vhosts core-post-deploy plugin trigger" local trigger="nginx_core_post_deploy" local APP="$1" - if [[ -f "$DOKKU_ROOT/$APP/IP.web.1" ]] && [[ -f "$DOKKU_ROOT/$APP/PORT.web.1" ]]; then + local HAS_NETWORK_CONFIG + + HAS_NETWORK_CONFIG="$(plugn trigger network-config-exists "$APP")" + if [[ "$HAS_NETWORK_CONFIG" == "true" ]]; then if [[ "$(is_app_vhost_enabled "$APP")" == "false" ]]; then dokku_log_info1 "VHOST support disabled. Skipping domains setup" elif [[ ! -f "$DOKKU_ROOT/$APP/VHOST" ]]; then