refactor: use ports-get plugn trigger for fetching port mappings
This removes use of ports internals from other plugins, which will make it easier to refactor the underlying property storage.
This commit is contained in:
@@ -1226,6 +1226,16 @@ set -eo pipefail; [[ $DOKKU_TRACE ]] && set -x
|
||||
nginx -t
|
||||
```
|
||||
|
||||
### `ports-get`
|
||||
- Description: Returns a list of port mappings, newline delimited
|
||||
- Invoked by: Various networking plugins
|
||||
- Arguments `$APP`
|
||||
```shell
|
||||
#!/usr/bin/env bash
|
||||
set -eo pipefail; [[ $DOKKU_TRACE ]] && set -x
|
||||
# TODO
|
||||
```
|
||||
|
||||
### `post-app-clone`
|
||||
|
||||
- Description: Allows you to run commands after an app was cloned.
|
||||
|
||||
1
plugins/20_events/ports-get
Symbolic link
1
plugins/20_events/ports-get
Symbolic link
@@ -0,0 +1 @@
|
||||
hook
|
||||
@@ -8,7 +8,7 @@ trigger-caddy-vhosts-docker-args-process-deploy() {
|
||||
declare desc="nginx-vhosts core-post-deploy plugin trigger"
|
||||
declare trigger="docker-args-process-deploy"
|
||||
declare APP="$1" IMAGE_SOURCE_TYPE="$2" IMAGE_TAG="$3" PROC_TYPE="$4" CONTAINER_INDEX="$5"
|
||||
local app_domains caddy_domains is_app_listening letsencrypt_email output proxy_container_port proxy_host_port port_map proxy_port_map proxy_scheme proxy_schemes scheme tls_internal
|
||||
local app_domains caddy_domains is_app_listening letsencrypt_email output proxy_container_port proxy_host_port port_map proxy_scheme proxy_schemes scheme tls_internal
|
||||
local proxy_container_http_port proxy_container_http_port_candidate proxy_host_http_port_candidate
|
||||
local proxy_container_https_port proxy_container_https_port_candidate proxy_host_https_port_candidate
|
||||
local STDIN=$(cat)
|
||||
@@ -37,8 +37,7 @@ trigger-caddy-vhosts-docker-args-process-deploy() {
|
||||
# so this block parses the port mappings and tries to find the correct
|
||||
# mapping to expose
|
||||
is_app_listening="false"
|
||||
proxy_port_map="$(plugn trigger config-get "$APP" DOKKU_PROXY_PORT_MAP)"
|
||||
for port_map in $proxy_port_map; do
|
||||
while read -r port_map; do
|
||||
proxy_scheme="$(awk -F ':' '{ print $1 }' <<<"$port_map")"
|
||||
proxy_host_port="$(awk -F ':' '{ print $2 }' <<<"$port_map")"
|
||||
proxy_container_port="$(awk -F ':' '{ print $3 }' <<<"$port_map")"
|
||||
@@ -66,7 +65,7 @@ trigger-caddy-vhosts-docker-args-process-deploy() {
|
||||
proxy_container_https_port="$proxy_container_port"
|
||||
fi
|
||||
fi
|
||||
done
|
||||
done < <(plugn trigger ports-get "$APP")
|
||||
|
||||
letsencrypt_email="$(fn-caddy-letsencrypt-email)"
|
||||
if [[ -n "$letsencrypt_email" ]] && [[ -z "$proxy_container_https_port" ]]; then
|
||||
|
||||
@@ -136,7 +136,7 @@ fn-domains-generate-urls() {
|
||||
|
||||
fn-domains-generate-urls-from-config() {
|
||||
declare APP="$1" SCHEME="$2" VHOST="$3" DEFAULT_LISTEN_PORT="$4"
|
||||
local DOKKU_PROXY_PORT_MAP=$(plugn trigger config-get "$APP" DOKKU_PROXY_PORT_MAP || true)
|
||||
local APP_PORT_MAP="$(plugn trigger ports-get "$APP")"
|
||||
local RAW_TCP_PORTS="$(get_app_raw_tcp_ports "$APP")"
|
||||
|
||||
if [[ "$(plugn trigger proxy-is-enabled "$APP")" == "false" ]]; then
|
||||
@@ -155,13 +155,13 @@ fn-domains-generate-urls-from-config() {
|
||||
done
|
||||
shopt -u nullglob
|
||||
fi
|
||||
elif [[ -n "$DOKKU_PROXY_PORT_MAP" ]]; then
|
||||
elif [[ -n "$APP_PORT_MAP" ]]; then
|
||||
local port_map
|
||||
for port_map in $DOKKU_PROXY_PORT_MAP; do
|
||||
while IFS= read -r port_map; do
|
||||
local scheme="$(awk -F ':' '{ print $1 }' <<<"$port_map")"
|
||||
local listen_port="$(awk -F ':' '{ print $2 }' <<<"$port_map")"
|
||||
fn-domains-generate-url "$SCHEME" "$VHOST" "$listen_port"
|
||||
done
|
||||
done <<<"$APP_PORT_MAP"
|
||||
elif [[ -n "$RAW_TCP_PORTS" ]]; then
|
||||
for listen_port in $RAW_TCP_PORTS; do
|
||||
fn-domains-generate-url "$SCHEME" "$VHOST" "$listen_port"
|
||||
|
||||
@@ -8,7 +8,7 @@ trigger-haproxy-vhosts-docker-args-process-deploy() {
|
||||
declare desc="nginx-vhosts core-post-deploy plugin trigger"
|
||||
declare trigger="docker-args-process-deploy"
|
||||
declare APP="$1" IMAGE_SOURCE_TYPE="$2" IMAGE_TAG="$3" PROC_TYPE="$4" CONTAINER_INDEX="$5"
|
||||
local app_domains haproxy_domains is_app_listening letsencrypt_email output proxy_container_port proxy_host_port port_map proxy_port_map proxy_scheme proxy_schemes scheme tls_internal
|
||||
local app_domains haproxy_domains is_app_listening letsencrypt_email output proxy_container_port proxy_host_port port_map proxy_scheme proxy_schemes scheme tls_internal
|
||||
local proxy_container_http_port proxy_container_http_port_candidate proxy_host_http_port_candidate
|
||||
local proxy_container_https_port proxy_container_https_port_candidate proxy_host_https_port_candidate proxy_redirect_ssl
|
||||
local STDIN=$(cat)
|
||||
@@ -40,8 +40,7 @@ trigger-haproxy-vhosts-docker-args-process-deploy() {
|
||||
# so this block parses the port mappings and tries to find the correct
|
||||
# mapping to expose
|
||||
is_app_listening="false"
|
||||
proxy_port_map="$(plugn trigger config-get "$APP" DOKKU_PROXY_PORT_MAP)"
|
||||
for port_map in $proxy_port_map; do
|
||||
while read -r port_map; do
|
||||
proxy_scheme="$(awk -F ':' '{ print $1 }' <<<"$port_map")"
|
||||
proxy_host_port="$(awk -F ':' '{ print $2 }' <<<"$port_map")"
|
||||
proxy_container_port="$(awk -F ':' '{ print $3 }' <<<"$port_map")"
|
||||
@@ -69,7 +68,7 @@ trigger-haproxy-vhosts-docker-args-process-deploy() {
|
||||
proxy_container_https_port="$proxy_container_port"
|
||||
fi
|
||||
fi
|
||||
done
|
||||
done < <(plugn trigger ports-get "$APP")
|
||||
|
||||
letsencrypt_email="$(fn-haproxy-letsencrypt-email)"
|
||||
if [[ -n "$letsencrypt_email" ]] && [[ -z "$proxy_container_https_port" ]]; then
|
||||
|
||||
@@ -321,10 +321,10 @@ nginx_build_config() {
|
||||
plugn trigger proxy-configure-ports "$APP"
|
||||
local PROXY_PORT=$(config_get "$APP" DOKKU_PROXY_PORT)
|
||||
local PROXY_SSL_PORT=$(config_get "$APP" DOKKU_PROXY_SSL_PORT)
|
||||
local PROXY_PORT_MAP=$(config_get "$APP" DOKKU_PROXY_PORT_MAP)
|
||||
local PROXY_PORT_MAP=$(plugn trigger ports-get "$APP")
|
||||
|
||||
local PORT_MAP proxy_port_map
|
||||
for PORT_MAP in $PROXY_PORT_MAP; do
|
||||
local PORT_MAP PROXY_PORT_MAP proxy_port_map
|
||||
while read -r PORT_MAP; do
|
||||
local PROXY_UPSTREAM_SCHEME="$(awk -F ':' '{ print $1 }' <<<"$PORT_MAP")"
|
||||
if [[ "$PROXY_UPSTREAM_SCHEME" == "https" ]] && [[ "$IS_SSL_ENABLED" == "false" ]]; then
|
||||
dokku_log_warn "Ignoring detected https port mapping without an accompanying ssl certificate (${PORT_MAP})"
|
||||
@@ -337,8 +337,8 @@ nginx_build_config() {
|
||||
if [[ "$(is_val_in_list "$PROXY_UPSTREAM_PORT" "$PROXY_UPSTREAM_PORTS" " ")" == "false" ]]; then
|
||||
local PROXY_UPSTREAM_PORTS+="$PROXY_UPSTREAM_PORT "
|
||||
fi
|
||||
done
|
||||
PROXY_PORT_MAP="$proxy_port_map"
|
||||
done < <(plugn trigger ports-get "$APP")
|
||||
PROXY_PORT_MAP="$(echo "$proxy_port_map" | xargs)" # trailing spaces mess up default template
|
||||
local PROXY_UPSTREAM_PORTS="$(echo "$PROXY_UPSTREAM_PORTS" | xargs)"
|
||||
|
||||
local SSL_INUSE=
|
||||
@@ -379,8 +379,6 @@ nginx_build_config() {
|
||||
HTTP2_PUSH_SUPPORTED="$(is_http2_push_enabled "$NGINX_VERSION")"
|
||||
GRPC_SUPPORTED="$(is_grpc_enabled "$NGINX_VERSION")"
|
||||
|
||||
PROXY_PORT_MAP=$(echo "$PROXY_PORT_MAP" | xargs) # trailing spaces mess up default template
|
||||
|
||||
local NGINX_LOG_ROOT="$(fn-nginx-log-root)"
|
||||
local NGINX_ACCESS_LOG_FORMAT="$(fn-nginx-access-log-format "$APP")"
|
||||
local NGINX_ACCESS_LOG_PATH="$(fn-nginx-access-log-path "$APP")"
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
SUBCOMMANDS = subcommands/list subcommands/add subcommands/clear subcommands/remove subcommands/set subcommands/report
|
||||
TRIGGERS = triggers/post-certs-remove triggers/post-certs-update triggers/report
|
||||
TRIGGERS = triggers/ports-get triggers/post-certs-remove triggers/post-certs-update triggers/report
|
||||
BUILD = commands subcommands triggers
|
||||
PLUGIN_NAME = ports
|
||||
|
||||
|
||||
@@ -18,6 +18,9 @@ func main() {
|
||||
|
||||
var err error
|
||||
switch trigger {
|
||||
case "ports-get":
|
||||
appName := flag.Arg(0)
|
||||
err = ports.TriggerPortsGet(appName)
|
||||
case "post-certs-remove":
|
||||
appName := flag.Arg(0)
|
||||
err = ports.TriggerPostCertsRemove(appName)
|
||||
|
||||
@@ -1,9 +1,24 @@
|
||||
package ports
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
|
||||
"github.com/dokku/dokku/plugins/config"
|
||||
)
|
||||
|
||||
// TriggerPortsGet prints out the port mapping for a given app
|
||||
func TriggerPortsGet(appName string) error {
|
||||
for _, portMap := range getPortMaps(appName) {
|
||||
if portMap.AllowsPersistence() {
|
||||
continue
|
||||
}
|
||||
|
||||
fmt.Println(portMap)
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
// TriggerPostCertsRemove unsets port config vars after SSL cert is added
|
||||
func TriggerPostCertsRemove(appName string) error {
|
||||
keys := []string{"DOKKU_PROXY_SSL_PORT"}
|
||||
|
||||
@@ -8,7 +8,7 @@ trigger-traefik-vhosts-docker-args-process-deploy() {
|
||||
declare desc="nginx-vhosts core-post-deploy plugin trigger"
|
||||
declare trigger="docker-args-process-deploy"
|
||||
declare APP="$1" IMAGE_SOURCE_TYPE="$2" IMAGE_TAG="$3" PROC_TYPE="$4" CONTAINER_INDEX="$5"
|
||||
local app_domains is_app_listening letsencrypt_email output proxy_container_port proxy_host_port port_map proxy_port_map priority proxy_scheme proxy_schemes traefik_domains
|
||||
local app_domains is_app_listening letsencrypt_email output proxy_container_port proxy_host_port port_map priority proxy_scheme proxy_schemes traefik_domains
|
||||
local proxy_container_http_port proxy_container_http_port_candidate proxy_host_http_port_candidate
|
||||
local proxy_container_https_port proxy_container_https_port_candidate proxy_host_https_port_candidate
|
||||
local STDIN=$(cat)
|
||||
@@ -37,8 +37,7 @@ trigger-traefik-vhosts-docker-args-process-deploy() {
|
||||
# so this block parses the port mappings and tries to find the correct
|
||||
# mapping to expose
|
||||
is_app_listening="false"
|
||||
proxy_port_map="$(plugn trigger config-get "$APP" DOKKU_PROXY_PORT_MAP)"
|
||||
for port_map in $proxy_port_map; do
|
||||
while read -r port_map; do
|
||||
proxy_scheme="$(awk -F ':' '{ print $1 }' <<<"$port_map")"
|
||||
proxy_host_port="$(awk -F ':' '{ print $2 }' <<<"$port_map")"
|
||||
proxy_container_port="$(awk -F ':' '{ print $3 }' <<<"$port_map")"
|
||||
@@ -66,7 +65,7 @@ trigger-traefik-vhosts-docker-args-process-deploy() {
|
||||
proxy_container_https_port="$proxy_container_port"
|
||||
fi
|
||||
fi
|
||||
done
|
||||
done < <(plugn trigger ports-get "$APP")
|
||||
|
||||
letsencrypt_email="$(fn-traefik-letsencrypt-email)"
|
||||
if [[ -n "$letsencrypt_email" ]] && [[ -z "$proxy_container_https_port" ]]; then
|
||||
|
||||
Reference in New Issue
Block a user