Merge pull request #2260 from dokku/remove-port-mapping-tuple

Add ability to remove a specific port mapping tuple
This commit is contained in:
Jose Diaz-Gonzalez
2016-06-21 02:09:29 -04:00
committed by GitHub
4 changed files with 21 additions and 5 deletions

View File

@@ -12,7 +12,7 @@ proxy:enable <app>
proxy:ports <app> List proxy port mappings for app
proxy:ports-add <app> <scheme>:<host-port>:<container-port> [<scheme>:<host-port>:<container-port>...] Set proxy port mappings for app
proxy:ports-clear <app> Clear all proxy port mappings for app
proxy:ports-remove <app> <host-port> [<host-port>...] Unset proxy port mappings for app
proxy:ports-remove <app> <host-port> [<host-port>|<scheme>:<host-port>:<container-port>...] Unset proxy port mappings for app
proxy:set <app> <proxy-type> Set proxy type for app
```

View File

@@ -13,7 +13,7 @@ case "$1" in
proxy:ports <app>, List proxy port mappings for app
proxy:ports-clear <app>, Clear all proxy port mappings for app
proxy:ports-add <app> <scheme>:<host-port>:<container-port> [<scheme>:<host-port>:<container-port>...], Set proxy port mappings for app
proxy:ports-remove <app> <host-port> [<host-port>...], Unset proxy port mappings for app
proxy:ports-remove <app> <host-port> [<host-port>|<scheme>:<host-port>:<container-port>...], Unset proxy port mappings for app
proxy:set <app> <proxy-type>, Set proxy type for app
help_content
}

View File

@@ -9,13 +9,19 @@ proxy_ports_remove_cmd() {
local cmd="proxy:ports-remove"
local APP="$2"; verify_app_name "$APP"
local PROXY_PORT_MAP="$(config_get "$APP" DOKKU_PROXY_PORT_MAP || true)"
local RE_PORT='^[0-9]+$'
shift 2
local INPUT_PORTS="$*"
if [[ -n "$INPUT_PORTS" ]]; then
local port
PROXY_PORT_MAP=" $PROXY_PORT_MAP "
for port in $INPUT_PORTS; do
PROXY_PORT_MAP="$(sed -r "s/[[:alnum:]]+:$port:[[:alnum:]]+//g" <<< "$PROXY_PORT_MAP")"
if [[ "$port" =~ $RE_PORT ]]; then
PROXY_PORT_MAP="$(sed -r "s/[[:alnum:]]+:$port:[[:alnum:]]+//g" <<< "$PROXY_PORT_MAP")"
else
PROXY_PORT_MAP="$(sed -r "s/ $port / /g" <<< "$PROXY_PORT_MAP")"
fi
done
PROXY_PORT_MAP="$(echo "$PROXY_PORT_MAP" | xargs)"
PROXY_PORT_MAP="$(merge_dedupe_list "$PROXY_PORT_MAP" " ")"

View File

@@ -64,7 +64,7 @@ assert_external_port() {
}
@test "(proxy) proxy:ports (list/add/remove/clear)" {
run dokku proxy:ports-add $TEST_APP http:8080:5000 https:8443:5000
run dokku proxy:ports-add $TEST_APP http:8080:5000 https:8443:5000 http:1234:5001
echo "output: "$output
echo "status: "$status
assert_success
@@ -72,13 +72,23 @@ assert_external_port() {
run /bin/bash -c "dokku --quiet proxy:ports $TEST_APP | xargs"
echo "output: "$output
echo "status: "$status
assert_output "http 8080 5000 https 8443 5000"
assert_output "http 1234 5001 http 8080 5000 https 8443 5000"
run /bin/bash -c "dokku proxy:ports-remove $TEST_APP 8080"
echo "output: "$output
echo "status: "$status
assert_success
run /bin/bash -c "dokku --quiet proxy:ports $TEST_APP | xargs"
echo "output: "$output
echo "status: "$status
assert_output "http 1234 5001 https 8443 5000"
run /bin/bash -c "dokku proxy:ports-remove $TEST_APP http:1234:5001"
echo "output: "$output
echo "status: "$status
assert_success
run /bin/bash -c "dokku --quiet proxy:ports $TEST_APP | xargs"
echo "output: "$output
echo "status: "$status