refactor: move code that fetches raw tcp ports for dockerfile deploys to ports plugin
This commit is contained in:
@@ -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
|
||||
|
||||
|
||||
@@ -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
|
||||
|
||||
1
plugins/20_events/ports-dockerfile-raw-tcp-ports
Symbolic link
1
plugins/20_events/ports-dockerfile-raw-tcp-ports
Symbolic link
@@ -0,0 +1 @@
|
||||
hook
|
||||
@@ -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() {
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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")"
|
||||
|
||||
@@ -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
|
||||
|
||||
|
||||
@@ -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)
|
||||
|
||||
@@ -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)
|
||||
|
||||
@@ -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"}
|
||||
|
||||
Reference in New Issue
Block a user