diff --git a/docs/appendices/0.31.0-migration-guide.md b/docs/appendices/0.31.0-migration-guide.md index f873a9da17b..365cd3193f9 100644 --- a/docs/appendices/0.31.0-migration-guide.md +++ b/docs/appendices/0.31.0-migration-guide.md @@ -7,6 +7,7 @@ - The `traefik` integration now mounts config to `/data` instead of the path `/acme.json`, fixing permissions issues under certain architectures. To take advantage of the new functionality, the traefik container should be stopped (via `dokku traefik:stop`) and then started (via `dokku traefik:start`). - Users no longer need to clear the `source-image` git property when transitioning from image-based deploys (`git:from-image` and `git:load-image`) to other deployment methods (git push, `git:from-archive`, `git:sync`). - For deploys via the `git:from-image` and `git:load-image` commands, the `CHECKS` file is now extracted from the configured `WORKDIR` property of the image. For all other deploys - git push, `git:from-archive`, `git:sync` - will have the `CHECKS` extracted directly from the source code. The filename in both cases is `CHECKS` and cannot be modified. +- 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. ## Deprecations diff --git a/docs/development/plugin-triggers.md b/docs/development/plugin-triggers.md index 7e03191a880..8fd94e8f5d9 100644 --- a/docs/development/plugin-triggers.md +++ b/docs/development/plugin-triggers.md @@ -1256,6 +1256,23 @@ 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 +``` + ### `ports-get` - Description: Returns a list of port mappings, newline delimited diff --git a/plugins/20_events/ports-dockerfile-raw-tcp-ports b/plugins/20_events/ports-dockerfile-raw-tcp-ports new file mode 120000 index 00000000000..5178a749ff6 --- /dev/null +++ b/plugins/20_events/ports-dockerfile-raw-tcp-ports @@ -0,0 +1 @@ +hook \ No newline at end of file diff --git a/plugins/common/functions b/plugins/common/functions index f1f49bc8378..23043bbd556 100755 --- a/plugins/common/functions +++ b/plugins/common/functions @@ -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: this function should not be used in app code" + plugn trigger ports-dockerfile-raw-tcp-ports "$APP" | xargs } get_container_ports() { diff --git a/plugins/domains/internal-functions b/plugins/domains/internal-functions index f897c444293..cd5bcf2cdaa 100755 --- a/plugins/domains/internal-functions +++ b/plugins/domains/internal-functions @@ -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 APP_PORT_MAP="$(plugn trigger ports-get "$APP")" - 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 diff --git a/plugins/nginx-vhosts/functions b/plugins/nginx-vhosts/functions index 7b223834765..687a09f6bd7 100755 --- a/plugins/nginx-vhosts/functions +++ b/plugins/nginx-vhosts/functions @@ -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")" diff --git a/plugins/ports/Makefile b/plugins/ports/Makefile index 09ef51751f3..8a4da72d25d 100644 --- a/plugins/ports/Makefile +++ b/plugins/ports/Makefile @@ -1,5 +1,5 @@ SUBCOMMANDS = subcommands/list subcommands/add subcommands/clear subcommands/remove subcommands/set subcommands/report -TRIGGERS = triggers/ports-clear triggers/ports-get triggers/post-certs-remove triggers/post-certs-update triggers/report +TRIGGERS = triggers/ports-clear triggers/ports-dockerfile-raw-tcp-ports triggers/ports-get triggers/post-certs-remove triggers/post-certs-update triggers/report BUILD = commands subcommands triggers PLUGIN_NAME = ports diff --git a/plugins/ports/functions.go b/plugins/ports/functions.go index 4739c839eca..0f701a664c0 100644 --- a/plugins/ports/functions.go +++ b/plugins/ports/functions.go @@ -38,6 +38,37 @@ func filterAppPortMaps(appName string, scheme string, hostPort int) []PortMap { return filteredPortMaps } +func getDockerfileRawTCPPorts(appName string) []int { + b, _ := common.PlugnTriggerOutput("config-get", []string{appName, "DOKKU_DOCKERFILE_PORTS"}...) + dockerfilePorts := strings.TrimSpace(string(b[:])) + + ports := []int{} + for _, dockerfilePort := range strings.Split(dockerfilePorts, " ") { + dockerfilePort = strings.TrimSpace(dockerfilePort) + if strings.HasSuffix(dockerfilePort, "/udp") { + continue + } + + dockerfilePort = strings.TrimSuffix(dockerfilePort, "/tcp") + if dockerfilePort == "" { + continue + } + + port, err := strconv.Atoi(dockerfilePort) + if err != nil { + continue + } + + if port == 0 { + continue + } + + ports = append(ports, port) + } + + return ports +} + func getPortMaps(appName string) []PortMap { value := config.GetWithDefault(appName, "DOKKU_PROXY_PORT_MAP", "") portMaps, _ := parsePortMapString(value) diff --git a/plugins/ports/src/triggers/triggers.go b/plugins/ports/src/triggers/triggers.go index d7a1f8c8863..75d40616ddc 100644 --- a/plugins/ports/src/triggers/triggers.go +++ b/plugins/ports/src/triggers/triggers.go @@ -24,6 +24,9 @@ func main() { case "ports-clear": appName := flag.Arg(0) err = ports.TriggerPortsClear(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) diff --git a/plugins/ports/triggers.go b/plugins/ports/triggers.go index a444a4a3064..39aa0b49a72 100644 --- a/plugins/ports/triggers.go +++ b/plugins/ports/triggers.go @@ -3,9 +3,25 @@ package ports import ( "fmt" + "github.com/dokku/dokku/plugins/common" "github.com/dokku/dokku/plugins/config" ) +// TriggerPortsClear removes all ports for the specified app +func TriggerPortsClear(appName string) error { + return clearPorts(appName) +} + +// TriggerRawTCPPorts extracts raw tcp port numbers from DOCKERFILE_PORTS config variable +func TriggerPortsDockerfileRawTCPPorts(appName string) error { + ports := getDockerfileRawTCPPorts(appName) + for _, port := range ports { + common.Log(fmt.Sprint(port)) + } + + return nil +} + // TriggerPortsGet prints out the port mapping for a given app func TriggerPortsGet(appName string) error { for _, portMap := range getPortMaps(appName) { @@ -19,11 +35,6 @@ func TriggerPortsGet(appName string) error { return nil } -// TriggerPortsClear removes all ports for the specified app -func TriggerPortsClear(appName string) error { - return clearPorts(appName) -} - // TriggerPostCertsRemove unsets port config vars after SSL cert is added func TriggerPostCertsRemove(appName string) error { keys := []string{"DOKKU_PROXY_SSL_PORT"}