这是indexloc提供的服务,不要输入任何密码
Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions docs/appendices/0.31.0-migration-guide.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@
## Deprecations

- The `proxy:ports*` commands have been replaced with the new `ports` plugin. Users will be able to use the old `proxy:ports*` commands for a single minor release, and they will be removed in the next minor release.
- The `common#get_app_raw_tcp_ports()` function has been deprecated and will be removed in the next release. Users should avoid interacting with this function for dockerfile ports and instead use the `ports-get` plugin trigger for fetching ports for an app.
- The `proxy-configure-ports` plugin trigger has been deprecated and will be removed in the next release. Users should instead trigger the `ports-configure` plugin trigger.

## Un-Deprecations

Expand Down
34 changes: 34 additions & 0 deletions docs/development/plugin-triggers.md
Original file line number Diff line number Diff line change
Expand Up @@ -1226,6 +1226,38 @@ set -eo pipefail; [[ $DOKKU_TRACE ]] && set -x
nginx -t
```

### `ports-configure`

- Description: Configures the port mapping
- Invoked by: `internally triggered by proxy plugins`
- Arguments: `$APP`
- Example:

```shell
#!/usr/bin/env bash

set -eo pipefail; [[ $DOKKU_TRACE ]] && set -x

# TODO
```

### `ports-dockerfile-raw-tcp-ports`

> Warning: This trigger is for internal use and will be removed in a future release. Do not use it in your codebase.

- Description: Extracts raw tcp port numbers from DOCKERFILE_PORTS config variable
- Invoked by: `internally triggered by proxy plugins`
- Arguments: `$APP`
- Example:

```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.
Expand Down Expand Up @@ -1857,6 +1889,8 @@ set -eo pipefail; [[ $DOKKU_TRACE ]] && set -x

### `proxy-configure-ports`

> Warning: Deprecated, please use `ports-configure` instead

- Description: Configures the port mapping
- Invoked by: `internally triggered by proxy plugins`
- Arguments: `$APP`
Expand Down
1 change: 1 addition & 0 deletions plugins/20_events/ports-configure
1 change: 1 addition & 0 deletions plugins/20_events/ports-dockerfile-raw-tcp-ports
1 change: 1 addition & 0 deletions plugins/20_events/ports-get-available
2 changes: 1 addition & 1 deletion plugins/caddy-vhosts/docker-args-process-deploy
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ trigger-caddy-vhosts-docker-args-process-deploy() {
fi

# ensure we have a port mapping
plugn trigger proxy-configure-ports "$APP"
plugn trigger ports-configure "$APP"

# gather port mapping information
# we only support proxying a single port for http and https listeners
Expand Down
14 changes: 3 additions & 11 deletions plugins/common/functions
Original file line number Diff line number Diff line change
Expand Up @@ -815,18 +815,10 @@ extract_directive_from_dockerfile() {

get_app_raw_tcp_ports() {
declare desc="extracts raw tcp port numbers from DOCKERFILE_PORTS config variable"
source "$PLUGIN_AVAILABLE_PATH/config/functions"
declare APP="$1"

local APP="$1"
local DOCKERFILE_PORTS="$(config_get "$APP" DOKKU_DOCKERFILE_PORTS)"
for p in $DOCKERFILE_PORTS; do
if [[ ! "$p" =~ .*udp.* ]]; then
p=${p//\/tcp/}
raw_tcp_ports+="$p "
fi
done
local raw_tcp_ports="$(echo "$raw_tcp_ports" | xargs)"
echo "$raw_tcp_ports"
dokku_log_warn "Deprecated: please use the 'ports-dockerfile-raw-tcp-ports' plugin trigger instead"
plugn trigger ports-dockerfile-raw-tcp-ports "$APP" | xargs
}

get_container_ports() {
Expand Down
6 changes: 6 additions & 0 deletions plugins/common/ports-get-available
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
#!/usr/bin/env bash
source "$PLUGIN_CORE_AVAILABLE_PATH/common/functions"
set -eo pipefail
[[ $DOKKU_TRACE ]] && set -x

get_available_port "$@"
2 changes: 1 addition & 1 deletion plugins/domains/internal-functions
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,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 RAW_TCP_PORTS="$(get_app_raw_tcp_ports "$APP")"
local RAW_TCP_PORTS="$(plugn trigger ports-dockerfile-raw-tcp-ports "$APP" | xargs)"

if [[ "$(plugn trigger proxy-is-enabled "$APP")" == "false" ]]; then
if [[ -n "$RAW_TCP_PORTS" ]]; then
Expand Down
2 changes: 1 addition & 1 deletion plugins/haproxy-vhosts/docker-args-process-deploy
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ trigger-haproxy-vhosts-docker-args-process-deploy() {
plugn trigger domains-setup "$APP" >/dev/null

# ensure we have a port mapping
plugn trigger proxy-configure-ports "$APP"
plugn trigger ports-configure "$APP"

# gather port mapping information
# we only support proxying a single port for http and https listeners
Expand Down
4 changes: 2 additions & 2 deletions plugins/nginx-vhosts/functions
Original file line number Diff line number Diff line change
Expand Up @@ -294,7 +294,7 @@ nginx_build_config() {
local SCHEME=http
local NGINX_TEMPLATE_SOURCE="built-in"
local APP_SSL_PATH="$DOKKU_ROOT/$APP/tls"
local RAW_TCP_PORTS="$(get_app_raw_tcp_ports "$APP")"
local RAW_TCP_PORTS="$(plugn trigger ports-dockerfile-raw-tcp-ports "$APP" | xargs)"
local DOKKU_APP_LISTENERS

CUSTOM_NGINX_TEMPLATE="$(plugn trigger nginx-app-template-source "$APP" "app-config")"
Expand All @@ -318,7 +318,7 @@ nginx_build_config() {
fi

# setup nginx listen ports
plugn trigger proxy-configure-ports "$APP"
plugn trigger ports-configure "$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)
Expand Down
1 change: 1 addition & 0 deletions plugins/ports/.gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,6 @@
/triggers/*
/triggers
/install
/ports-*
/post-*
/report
2 changes: 1 addition & 1 deletion plugins/ports/Makefile
Original file line number Diff line number Diff line change
@@ -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-configure triggers/ports-dockerfile-raw-tcp-ports triggers/post-certs-remove triggers/post-certs-update triggers/report
BUILD = commands subcommands triggers
PLUGIN_NAME = ports

Expand Down
22 changes: 22 additions & 0 deletions plugins/ports/functions.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,28 @@ func filterAppPortMaps(appName string, scheme string, hostPort int) []PortMap {
return filteredPortMaps
}

func getDockerfileRawTCPPorts(appName string) []string {
b, _ := common.PlugnTriggerOutput("config-get", []string{appName, "DOKKU_DOCKERFILE_PORTS"}...)
dockerfilePorts := strings.TrimSpace(string(b[:]))

ports := []string{}
for _, port := range strings.Split(dockerfilePorts, " ") {
port = strings.TrimSpace(port)
if strings.HasSuffix(port, "/udp") {
continue
}

port = strings.TrimSuffix(port, "/tcp")
if port == "" {
continue
}

ports = append(ports, port)
}

return ports
}

func getPortMaps(appName string) []PortMap {
value := config.GetWithDefault(appName, "DOKKU_PROXY_PORT_MAP", "")
portMaps, _ := parsePortMapString(value)
Expand Down
54 changes: 2 additions & 52 deletions plugins/ports/proxy-configure-ports
Original file line number Diff line number Diff line change
@@ -1,65 +1,15 @@
#!/usr/bin/env bash
source "$PLUGIN_CORE_AVAILABLE_PATH/common/functions"
source "$PLUGIN_AVAILABLE_PATH/config/functions"
set -eo pipefail
[[ $DOKKU_TRACE ]] && set -x

trigger-ports-proxy-configure-ports() {
declare desc="ports proxy-configure-ports plugin trigger"
declare trigger="proxy-configure-ports"
declare APP="$1"
local RAW_TCP_PORTS="$(get_app_raw_tcp_ports "$APP")"
local DOKKU_PROXY_PORT=$(config_get "$APP" DOKKU_PROXY_PORT)
local DOKKU_PROXY_SSL_PORT=$(config_get "$APP" DOKKU_PROXY_SSL_PORT)
local DOKKU_PROXY_PORT_MAP=$(config_get "$APP" DOKKU_PROXY_PORT_MAP)
local IS_APP_VHOST_ENABLED=true
local UPSTREAM_PORT="5000"

plugn trigger domains-vhost-enabled "$APP" 2>/dev/null || IS_APP_VHOST_ENABLED=false

if [[ -z "$DOKKU_PROXY_PORT" ]] && [[ -z "$RAW_TCP_PORTS" ]]; then
if [[ "$IS_APP_VHOST_ENABLED" == "false" ]]; then
dokku_log_info1 "No port set, setting to random open high port"
local PROXY_PORT=$(get_available_port)
else
local PROXY_PORT=$(config_get --global DOKKU_PROXY_PORT)
PROXY_PORT=${PROXY_PORT:=80}
fi
DOKKU_QUIET_OUTPUT=1 config_set --no-restart "$APP" DOKKU_PROXY_PORT="$PROXY_PORT"
fi
if [[ -z "$DOKKU_PROXY_SSL_PORT" ]]; then
if [[ "$(plugn trigger certs-exists "$APP")" == "true" ]]; then
local PROXY_SSL_PORT=$(config_get --global DOKKU_PROXY_SSL_PORT)
PROXY_SSL_PORT=${PROXY_SSL_PORT:=443}
if [[ -z "$RAW_TCP_PORTS" ]] && [[ "$IS_APP_VHOST_ENABLED" == "false" ]]; then
dokku_log_info1 "No ssl port set, setting to random open high port"
PROXY_SSL_PORT=$(get_available_port)
fi
DOKKU_QUIET_OUTPUT=1 config_set --no-restart "$APP" DOKKU_PROXY_SSL_PORT="$PROXY_SSL_PORT"
fi
fi
if [[ -z "$DOKKU_PROXY_PORT_MAP" ]]; then
if [[ -n "$RAW_TCP_PORTS" ]]; then
local RAW_TCP_PORT
for RAW_TCP_PORT in $RAW_TCP_PORTS; do
local PROXY_PORT_MAP+=" http:${RAW_TCP_PORT}:${RAW_TCP_PORT} "
done
else
local PROXY_PORT=${PROXY_PORT:-$DOKKU_PROXY_PORT}
local PROXY_SSL_PORT=${PROXY_SSL_PORT:-$DOKKU_PROXY_SSL_PORT}
[[ -f "$DOKKU_ROOT/$APP/PORT.web.1" ]] && local UPSTREAM_PORT="$(<"$DOKKU_ROOT/$APP/PORT.web.1")"
if [[ -n "$PROXY_PORT" ]] && [[ -n "$PROXY_SSL_PORT" ]]; then
local PROXY_PORT_MAP+=" http:${PROXY_PORT}:$UPSTREAM_PORT https:${PROXY_SSL_PORT}:$UPSTREAM_PORT "
elif [[ -n "$PROXY_PORT" ]]; then
local PROXY_PORT_MAP+=" http:${PROXY_PORT}:$UPSTREAM_PORT "
fi
fi
if [[ -n "$PROXY_PORT_MAP" ]]; then
local PROXY_PORT_MAP="$(echo "$PROXY_PORT_MAP" | xargs)"
local PROXY_PORT_MAP+=" $(merge_dedupe_list "$(remove_val_from_list "$PORT_MAP" "$DOKKU_PROXY_PORT_MAP" " ")" " ") "
DOKKU_QUIET_OUTPUT=1 config_set --no-restart "$APP" DOKKU_PROXY_PORT_MAP="$PROXY_PORT_MAP"
fi
fi
dokku_log_warn "Deprecated: please use the 'ports-configure' plugin trigger instead"
plugn trigger ports-configure "$APP"
}

trigger-ports-proxy-configure-ports "$@"
6 changes: 6 additions & 0 deletions plugins/ports/src/triggers/triggers.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,12 @@ func main() {

var err error
switch trigger {
case "ports-configure":
appName := flag.Arg(0)
err = ports.TriggerPortsConfigure(appName)
case "ports-dockerfile-raw-tcp-ports":
appName := flag.Arg(0)
err = ports.TriggerPortsDockerfileRawTCPPorts(appName)
case "post-certs-remove":
appName := flag.Arg(0)
err = ports.TriggerPostCertsRemove(appName)
Expand Down
Loading