diff --git a/docs/appendices/0.31.0-migration-guide.md b/docs/appendices/0.31.0-migration-guide.md index 06f64469943..7ed392dc84a 100644 --- a/docs/appendices/0.31.0-migration-guide.md +++ b/docs/appendices/0.31.0-migration-guide.md @@ -7,15 +7,25 @@ - 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 environment variable `DOKKU_PROXY_PORT_MAP` has been migrated to the properties system. Direct changes to the value will be ignored, and users should interact with port maps via the `ports` plugin. +- Port mappings are now auto-detected during the build process. Users may override detected port mappings via the `ports` plugin. A default port mapping of `http:80:5000` will be used if none is otherwise specified. ## 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 `common#get_available_port()` function has been deprecated and will be removed in the next release. Users should avoid interacting with this function and instead use the `ports-get-available` plugin trigger for fetching an available port. - 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. +- The `common#get_dockerfile_exposed_ports()` function is deprecated and will be removed in the next release. There is no replacement for this as it's only use in Dokku core was in the `builder-dockerfile` plugin. +- The `common#get_exposed_ports_from_image()` function is deprecated and will be removed in the next release. There is no replacement for this as it's only use in Dokku core was during the build process. +- The environment variable `DOKKU_PROXY_PORT_MAP` has been migrated to the properties system. Direct changes to the value will be ignored, and users should interact with port maps via the `ports` plugin. ## Un-Deprecations - The bare `apps` and `config` cli aliases are no longer deprecated. This better follows Heroku's output and is more useful to users. The subcommands will be treated as the primary, documented versions, while the aliases are there for convenience. + +## Removals + +- The variable `RAW_TCP_PORTS` is no longer exposed for `nginx.conf.sigil` templating. +- The environment variable `DOKKU_DOCKERFILE_PORTS` is no longer in use. Users wishing to change port mappings should instead use the `ports` plugin. +- The `common#get_app_raw_tcp_ports()` function has been removed in the next release. Users should instead use the `ports-get` plugin trigger for fetching ports for an app. +- The plugin trigger `network-compute-ports` has been removed. It's only use was in the `scheduler-docker-local` plugin, for exposing ports. It's functionality is now implemented via the `ports` plugin. +- The plugin trigger `network-get-port` has been removed. It's only use was in the `scheduler-docker-local` plugin, for recording ports. It's functionality is now implemented via the `ports` plugin. diff --git a/docs/configuration/environment-variables.md b/docs/configuration/environment-variables.md index eb8c02b59aa..464211d4a69 100644 --- a/docs/configuration/environment-variables.md +++ b/docs/configuration/environment-variables.md @@ -111,7 +111,6 @@ The following config variables have special meanings and can be set in a variety | `DOKKU_DISABLE_APP_AUTOCREATION` | none | `dokku config:set` | Disables automatic creation of a non-existent app on deploy. | | `DOKKU_DOCKER_STOP_TIMEOUT` | `10` | `dokku config:set` | Configurable grace period given to the `docker stop` command. If a container has not stopped by this time, a `kill -9` signal or equivalent is sent in order to force-terminate the container. Both the `ps:stop` and `apps:destroy` commands _also_ respect this value. If not specified, the docker defaults for the [docker stop command](https://docs.docker.com/engine/reference/commandline/stop/) will be used.| | `DOKKU_DOCKERFILE_CACHE_BUILD` | none | `dokku config:set` | | -| `DOKKU_DOCKERFILE_PORTS` | dockerfile ports | `dokku config:set` | | | `DOKKU_DOCKERFILE_START_CMD` | none | `dokku config:set` | | | `DOKKU_PARALLEL_ARGUMENTS`. | none | `dokku config:set` | Allows passing custom arguments to parallel for `ps:*all` commands | | `DOKKU_PROXY_PORT` | automatically assigned | `/etc/environment`
`~dokku/.dokkurc`
`~dokku/.dokkurc/*`
`dokku config:set` | | diff --git a/docs/development/plugin-triggers.md b/docs/development/plugin-triggers.md index 4afe733545d..f326282ca42 100644 --- a/docs/development/plugin-triggers.md +++ b/docs/development/plugin-triggers.md @@ -1021,21 +1021,6 @@ set -eo pipefail; [[ $DOKKU_TRACE ]] && set -x # TODO ``` -### `network-compute-ports` - -- Description: Computes the ports for a given app container -- Invoked by: `internally triggered by proxy-build-config within proxy implementations` -- Arguments: `$APP $PROC_TYPE $IS_HEROKUISH_CONTAINER $CONTAINER_INDEX` -- Example: - -```shell -#!/usr/bin/env bash - -set -eo pipefail; [[ $DOKKU_TRACE ]] && set -x - -# TODO -``` - ### `network-config-exists` - Description: Returns whether the network configuration for a given app exists @@ -1081,21 +1066,6 @@ set -eo pipefail; [[ $DOKKU_TRACE ]] && set -x # TODO ``` -### `network-get-port` - -- Description: Return the port for a given app container -- Invoked by: `internally triggered by a deploy` -- Arguments: `$APP $PROCESS_TYPE $CONTAINER_ID $IS_HEROKUISH_CONTAINER` -- Example: - -```shell -#!/usr/bin/env bash - -set -eo pipefail; [[ $DOKKU_TRACE ]] && set -x - -# TODO -``` - ### `network-get-property` - Description: Return the value for an app's network property @@ -1258,7 +1228,7 @@ set -eo pipefail; [[ $DOKKU_TRACE ]] && set -x ### `ports-configure` -- Description: Configures the port mapping +- Description: Configures the initial proxy ports - Invoked by: `internally triggered by proxy plugins` - Arguments: `$APP` - Example: @@ -1271,12 +1241,10 @@ 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. +### `ports-get` -- Description: Extracts raw tcp port numbers from DOCKERFILE_PORTS config variable -- Invoked by: `internally triggered by proxy plugins` +- Description: Returns a list of port mappings, newline delimited +- Invoked by: Various networking plugins - Arguments: `$APP` - Example: @@ -1288,9 +1256,9 @@ set -eo pipefail; [[ $DOKKU_TRACE ]] && set -x # TODO ``` -### `ports-get` +### `ports-get-available` -- Description: Returns a list of port mappings, newline delimited +- Description: Prints out an available port greater than 1024 - Invoked by: Various networking plugins - Arguments: `$APP` - Example: @@ -1303,22 +1271,24 @@ set -eo pipefail; [[ $DOKKU_TRACE ]] && set -x # TODO ``` -### `ports-get-available` +### `ports-get-property` -- Description: Prints out an available port greater than 1024 -- Invoked by: Various networking plugins -- Arguments: `$APP` +- Description: Return the value for an app's ports property +- Invoked by: +- Arguments: `$APP $KEY` - Example: ```shell #!/usr/bin/env bash set -eo pipefail; [[ $DOKKU_TRACE ]] && set -x +APP="$1"; PROPERTY="$2" # TODO ``` ### `ports-set-detected` + - Description: Allows builders to specify detected port mappings for a given app - Invoked by: Builder plugins - Arguments: `$APP [$PORT_MAPPING...]` diff --git a/docs/networking/port-management.md b/docs/networking/port-management.md index f7a770de824..10d17a7ac81 100644 --- a/docs/networking/port-management.md +++ b/docs/networking/port-management.md @@ -180,28 +180,6 @@ Any application that does not use an `EXPOSE` directive will result in Dokku def - modify your application to support the `PORT` environment variable. - switch to using an `EXPOSE` directive in your Dockerfile. -#### Switching between `EXPOSE` usage modes - -When switching between `EXPOSE` usage modes, it is important to reset your port management. The following two commands can be used to reset your state and redeploy your application. - -```shell -# assuming your application is called `node-js-app` -dokku config:unset --no-restart node-js-app DOKKU_DOCKERFILE_PORTS PORT -dokku ports:clear node-js-app -``` - -### Docker Image - -When deploying an image, we will use `docker inspect` to extract the `ExposedPorts` configuration and if defined, use that to populate port mapping. If this behavior is not desired, you can override that configuration variable with the following commands. - -```shell -# assuming your application is called `node-js-app` -dokku config:set node-js-app DOKKU_DOCKERFILE_PORTS="1234/tcp 80/tcp" -dokku ports:clear node-js-app -``` - -All other port-related behavior is the same as when deploying via Dockerfile. - ### Displaying ports reports for an app You can get a report about the app's ports status using the `ports:report` command: diff --git a/docs/networking/proxies/nginx.md b/docs/networking/proxies/nginx.md index aa34d5b10dd..2c85783c515 100644 --- a/docs/networking/proxies/nginx.md +++ b/docs/networking/proxies/nginx.md @@ -378,7 +378,6 @@ Unsetting this value is the same as enabling custom nginx config usage. {{ .NOSSL_SERVER_NAME }} List of non-SSL VHOSTS {{ .PROXY_PORT_MAP }} List of port mappings (same as the `map` ports property) {{ .PROXY_UPSTREAM_PORTS }} List of configured upstream ports (derived from the `map` ports property) -{{ .RAW_TCP_PORTS }} List of exposed tcp ports as defined by Dockerfile `EXPOSE` directive (**Dockerfile apps only**) {{ .SSL_INUSE }} Boolean set when an app is SSL-enabled {{ .SSL_SERVER_NAME }} List of SSL VHOSTS ``` diff --git a/plugins/20_events/ports-dockerfile-raw-tcp-ports b/plugins/20_events/ports-dockerfile-raw-tcp-ports deleted file mode 120000 index 5178a749ff6..00000000000 --- a/plugins/20_events/ports-dockerfile-raw-tcp-ports +++ /dev/null @@ -1 +0,0 @@ -hook \ No newline at end of file diff --git a/plugins/builder-dockerfile/builder-build b/plugins/builder-dockerfile/builder-build index 42001d2eb33..c5b17b9d93d 100755 --- a/plugins/builder-dockerfile/builder-build +++ b/plugins/builder-dockerfile/builder-build @@ -23,10 +23,6 @@ trigger-builder-dockerfile-builder-build() { pushd "$SOURCECODE_WORK_DIR" &>/dev/null - # extract first port from Dockerfile - suppress_output dos2unix Dockerfile - local DOCKERFILE_PORTS=$(get_dockerfile_exposed_ports Dockerfile) - [[ -n "$DOCKERFILE_PORTS" ]] && config_set --no-restart "$APP" DOKKU_DOCKERFILE_PORTS="$DOCKERFILE_PORTS" plugn trigger pre-build-dockerfile "$APP" [[ "$DOKKU_DOCKERFILE_CACHE_BUILD" == "false" ]] && DOKKU_DOCKER_BUILD_OPTS="$DOKKU_DOCKER_BUILD_OPTS --no-cache" diff --git a/plugins/builder-dockerfile/internal-functions b/plugins/builder-dockerfile/internal-functions index 9a24879edc8..21e36208bb6 100755 --- a/plugins/builder-dockerfile/internal-functions +++ b/plugins/builder-dockerfile/internal-functions @@ -130,6 +130,8 @@ fn-builder-dockerfile-get-detect-port-map() { done echo "$port_map" | xargs else - echo "http:80:5000" + # ensure we have a port mapping + plugn trigger ports-configure "$APP" + echo "http:$(plugn trigger ports-get-property "$APP" proxy-port):5000" fi } diff --git a/plugins/builder-herokuish/builder-build b/plugins/builder-herokuish/builder-build index d09f6df28e5..a275bc0d14a 100755 --- a/plugins/builder-herokuish/builder-build +++ b/plugins/builder-herokuish/builder-build @@ -91,7 +91,10 @@ trigger-builder-herokuish-builder-build() { "$DOCKER_BIN" container commit "${DOCKER_COMMIT_LABEL_ARGS[@]}" "$CID" "$IMAGE" >/dev/null plugn trigger scheduler-register-retired "$APP" "$CID" - plugn trigger ports-set-detected "$APP" "http:80:5000" + + # ensure we have a port mapping + plugn trigger ports-configure "$APP" + plugn trigger ports-set-detected "$APP" "http:$(plugn trigger ports-get-property "$APP" proxy-port):5000" plugn trigger post-build-buildpack "$APP" "$SOURCECODE_WORK_DIR" } diff --git a/plugins/builder-lambda/builder-build b/plugins/builder-lambda/builder-build index 64beb30a0ff..0c6d708d86a 100755 --- a/plugins/builder-lambda/builder-build +++ b/plugins/builder-lambda/builder-build @@ -36,7 +36,9 @@ trigger-builder-lambda-builder-build() { cp "$SOURCECODE_WORK_DIR/Procfile" "${DOKKU_LIB_ROOT}/data/builder-lambda/$APP/$GIT_REV.Procfile" fi - plugn trigger ports-set-detected "$APP" "http:80:5000" + # ensure we have a port mapping + plugn trigger ports-configure "$APP" + plugn trigger ports-set-detected "$APP" "http:$(plugn trigger ports-get-property "$APP" proxy-port):5000" plugn trigger post-build-lambda "$APP" } diff --git a/plugins/builder-pack/builder-build b/plugins/builder-pack/builder-build index 8a2f865b165..c3b3f4b2fcc 100755 --- a/plugins/builder-pack/builder-build +++ b/plugins/builder-pack/builder-build @@ -35,7 +35,9 @@ trigger-builder-pack-builder-build() { pack build "$IMAGE" --builder "$DOKKU_CNB_BUILDER" --path "$SOURCECODE_WORK_DIR" --default-process web "${ENV_ARGS[@]}" docker-image-labeler --label=dokku --label=org.label-schema.schema-version=1.0 --label=org.label-schema.vendor=dokku --label=com.dokku.image-stage=build --label=com.dokku.builder-type=pack --label=com.dokku.app-name=$APP "$IMAGE" - plugn trigger ports-set-detected "$APP" "http:80:5000" + # ensure we have a port mapping + plugn trigger ports-configure "$APP" + plugn trigger ports-set-detected "$APP" "http:$(plugn trigger ports-get-property "$APP" proxy-port):5000" plugn trigger post-build-pack "$APP" "$SOURCECODE_WORK_DIR" } diff --git a/plugins/checks/subcommands/run b/plugins/checks/subcommands/run index 8f1466957a6..f753778cdd3 100755 --- a/plugins/checks/subcommands/run +++ b/plugins/checks/subcommands/run @@ -60,7 +60,17 @@ check_process() { dokku_log_info1 "Running checks for app ($APP.$PROC_TYPE.$CONTAINER_INDEX)" CONTAINER_ID=$(<"$DOKKU_CONTAINER_ID_FILE") IP="$(plugn trigger network-get-ipaddr "$APP" "$PROC_TYPE" "$CONTAINER_ID")" - PORT="$(plugn trigger network-get-port "$APP" "$PROC_TYPE" "$CONTAINER_ID" "$IS_HEROKUISH_CONTAINER")" + PORT=5000 + + 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")" + if [[ "$proxy_scheme" != "udp" ]]; then + PORT="${proxy_container_port:="$proxy_container_port"}" + fi + done < <(plugn trigger ports-get "$APP") + plugn trigger check-deploy "$APP" "$CONTAINER_ID" "$PROC_TYPE" "$PORT" "$IP" } diff --git a/plugins/common/functions b/plugins/common/functions index 5357269adf5..adf5066ae68 100755 --- a/plugins/common/functions +++ b/plugins/common/functions @@ -632,18 +632,9 @@ release_and_deploy() { local APP="$1" local IMAGE_TAG="${2:-latest}" local IMAGE=$(get_app_image_name "$APP" "$IMAGE_TAG") - local DOKKU_DOCKERFILE_PORTS if verify_image "$IMAGE"; then IMAGE_SOURCE_TYPE="$(get_image_builder_type "$IMAGE" "$APP")" - if [[ "$IMAGE_SOURCE_TYPE" == "dockerfile" ]]; then - DOKKU_DOCKERFILE_PORTS=$(config_get "$APP" DOKKU_DOCKERFILE_PORTS || true) - if [[ -z "$DOKKU_DOCKERFILE_PORTS" ]]; then - local DOCKER_IMAGE_PORTS=$(get_exposed_ports_from_image "$IMAGE") - [[ -n "$DOCKER_IMAGE_PORTS" ]] && config_set --no-restart "$APP" DOKKU_DOCKERFILE_PORTS="$DOCKER_IMAGE_PORTS" - fi - fi - local DOKKU_APP_SKIP_DEPLOY="$(config_get "$APP" DOKKU_SKIP_DEPLOY || true)" local DOKKU_GLOBAL_SKIP_DEPLOY="$(config_get --global DOKKU_SKIP_DEPLOY || true)" @@ -768,12 +759,16 @@ get_ipv6_regex() { get_dockerfile_exposed_ports() { declare desc="return all exposed ports from passed file path" + dokku_log_warn "Deprecated: this function should not be used in app code" + local DOCKERFILE_PORTS=$(grep -E "^EXPOSE " "$1" | awk '{ print $2 }' | xargs) || true echo "$DOCKERFILE_PORTS" } get_exposed_ports_from_image() { declare desc="return all exposed ports from passed image name" + dokku_log_warn "Deprecated: this function should not be used in app code" + local IMAGE="$1" verify_image "$IMAGE" # shellcheck disable=SC2016 @@ -806,14 +801,6 @@ extract_directive_from_dockerfile() { echo "$FOUND_LINE" } -get_app_raw_tcp_ports() { - declare desc="extracts raw tcp port numbers from DOCKERFILE_PORTS config variable" - declare APP="$1" - - 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() { declare desc="returns published ports from app containers" local APP="$1" diff --git a/plugins/common/ports-get-available b/plugins/common/ports-get-available deleted file mode 100755 index f7d9893334a..00000000000 --- a/plugins/common/ports-get-available +++ /dev/null @@ -1,6 +0,0 @@ -#!/usr/bin/env bash -source "$PLUGIN_CORE_AVAILABLE_PATH/common/functions" -set -eo pipefail -[[ $DOKKU_TRACE ]] && set -x - -get_available_port "$@" diff --git a/plugins/domains/internal-functions b/plugins/domains/internal-functions index cd5bcf2cdaa..c4a870c40cc 100755 --- a/plugins/domains/internal-functions +++ b/plugins/domains/internal-functions @@ -137,24 +137,15 @@ 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="$(plugn trigger ports-dockerfile-raw-tcp-ports "$APP" | xargs)" if [[ "$(plugn trigger proxy-is-enabled "$APP")" == "false" ]]; then - if [[ -n "$RAW_TCP_PORTS" ]]; then - local APP_CONTAINER_PORTS="$(get_container_ports "$APP")" - local app_port - for listen_port in $APP_CONTAINER_PORTS; do - fn-domains-generate-url "$SCHEME" "$VHOST" "$listen_port" - done - else - local DOKKU_APP_WEB_LISTENERS PORT - DOKKU_APP_WEB_LISTENERS="$(plugn trigger network-get-listeners "$APP" "web" | xargs)" - for DOKKU_APP_WEB_LISTENER in $DOKKU_APP_WEB_LISTENERS; do - listen_port="$(echo "$DOKKU_APP_WEB_LISTENER" | cut -d ':' -f2)" - fn-domains-generate-url "$SCHEME" "$VHOST" "$listen_port" - done - shopt -u nullglob - fi + local DOKKU_APP_WEB_LISTENERS PORT + DOKKU_APP_WEB_LISTENERS="$(plugn trigger network-get-listeners "$APP" "web" | xargs)" + for DOKKU_APP_WEB_LISTENER in $DOKKU_APP_WEB_LISTENERS; do + listen_port="$(echo "$DOKKU_APP_WEB_LISTENER" | cut -d ':' -f2)" + fn-domains-generate-url "$SCHEME" "$VHOST" "$listen_port" + done + shopt -u nullglob elif [[ -n "$APP_PORT_MAP" ]]; then local port_map while IFS= read -r port_map; do @@ -162,10 +153,6 @@ fn-domains-generate-urls-from-config() { local listen_port="$(awk -F ':' '{ print $2 }' <<<"$port_map")" fn-domains-generate-url "$SCHEME" "$VHOST" "$listen_port" 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" - done else fn-domains-generate-url "$SCHEME" "$VHOST" "$DEFAULT_LISTEN_PORT" fi diff --git a/plugins/network/Makefile b/plugins/network/Makefile index 7bf1212d6fd..094e1951339 100644 --- a/plugins/network/Makefile +++ b/plugins/network/Makefile @@ -1,5 +1,5 @@ SUBCOMMANDS = subcommands/create subcommands/destroy subcommands/exists subcommands/info subcommands/list subcommands/rebuild subcommands/rebuildall subcommands/report subcommands/set -TRIGGERS = triggers/core-post-deploy triggers/docker-args-process-build triggers/docker-args-process-deploy triggers/docker-args-process-run triggers/install triggers/network-build-config triggers/network-compute-ports triggers/network-config-exists triggers/network-get-ipaddr triggers/network-get-listeners triggers/network-get-port triggers/network-get-property triggers/network-get-static-listeners triggers/network-write-ipaddr triggers/network-write-port triggers/post-app-clone-setup triggers/post-app-rename-setup triggers/post-container-create triggers/post-create triggers/post-delete triggers/report +TRIGGERS = triggers/core-post-deploy triggers/docker-args-process-build triggers/docker-args-process-deploy triggers/docker-args-process-run triggers/install triggers/network-build-config triggers/network-config-exists triggers/network-get-ipaddr triggers/network-get-listeners triggers/network-get-property triggers/network-get-static-listeners triggers/network-write-ipaddr triggers/network-write-port triggers/post-app-clone-setup triggers/post-app-rename-setup triggers/post-container-create triggers/post-create triggers/post-delete triggers/report BUILD = commands subcommands triggers PLUGIN_NAME = network diff --git a/plugins/network/network.go b/plugins/network/network.go index 26e636aef17..13b1ed54b88 100644 --- a/plugins/network/network.go +++ b/plugins/network/network.go @@ -2,7 +2,6 @@ package network import ( "fmt" - "io/ioutil" "net" "os" "path/filepath" @@ -10,9 +9,6 @@ import ( "strings" "github.com/dokku/dokku/plugins/common" - "github.com/dokku/dokku/plugins/config" - - sh "github.com/codeskyblue/go-sh" ) var ( @@ -65,8 +61,6 @@ func BuildConfig(appName string) error { return nil } - image := common.GetAppImageName(appName, "", "") - isHerokuishContainer := common.IsImageHerokuishBased(image, appName) common.LogInfo1(fmt.Sprintf("Ensuring network configuration is in sync for %s", appName)) for processType, procCount := range scale { @@ -82,8 +76,6 @@ func BuildConfig(appName string) error { } ipAddress := GetContainerIpaddress(appName, processType, containerID) - port := GetContainerPort(appName, processType, containerID, isHerokuishContainer) - if ipAddress != "" { args := []string{appName, processType, containerIndexString, ipAddress} _, err := common.PlugnTriggerOutput("network-write-ipaddr", args...) @@ -91,14 +83,6 @@ func BuildConfig(appName string) error { common.LogWarn(err.Error()) } } - - if port != "" { - args := []string{appName, processType, containerIndexString, port} - _, err := common.PlugnTriggerOutput("network-write-port", args...) - if err != nil { - common.LogWarn(err.Error()) - } - } } } @@ -147,53 +131,6 @@ func GetContainerIpaddress(appName, processType, containerID string) (ipAddr str return } -// GetContainerPort returns the port for a given app container -func GetContainerPort(appName, processType string, containerID string, isHerokuishContainer bool) (port string) { - if processType == "web" { - if staticWebListener := reportStaticWebListener(appName); staticWebListener != "" { - _, port, err := net.SplitHostPort(staticWebListener) - if err == nil { - return port - } - - return "80" - } - } - - dockerfilePorts := make([]string, 0) - if !isHerokuishContainer { - configValue := config.GetWithDefault(appName, "DOKKU_DOCKERFILE_PORTS", "") - if configValue != "" { - dockerfilePorts = strings.Split(configValue, " ") - } - } - - if len(dockerfilePorts) > 0 { - for _, p := range dockerfilePorts { - if strings.HasSuffix(p, "/udp") { - continue - } - port = strings.TrimSuffix(p, "/tcp") - if port != "" { - break - } - } - - if port != "" { - cmd := sh.Command(common.DockerBin(), "container", "port", containerID, port) - cmd.Stderr = ioutil.Discard - b, err := cmd.Output() - if err == nil { - port = strings.Split(string(b[:]), ":")[1] - } - } - } else { - port = "5000" - } - - return -} - // GetListeners returns a string array of app listeners func GetListeners(appName string, processType string) []string { if processType == "web" { @@ -214,6 +151,9 @@ func GetListeners(appName string, processType string) []string { portfile := strings.Replace(ipfile, ipPrefix, portPrefix, 1) ipAddress := common.ReadFirstLine(ipfile) port := common.ReadFirstLine(portfile) + if port == "" { + port = "5000" + } listeners = append(listeners, fmt.Sprintf("%s:%s", ipAddress, port)) } return listeners diff --git a/plugins/network/src/triggers/triggers.go b/plugins/network/src/triggers/triggers.go index c78856d4433..1a54d0f43a1 100644 --- a/plugins/network/src/triggers/triggers.go +++ b/plugins/network/src/triggers/triggers.go @@ -32,11 +32,6 @@ func main() { case "network-build-config": appName := flag.Arg(0) err = network.BuildConfig(appName) - case "network-compute-ports": - appName := flag.Arg(0) - processType := flag.Arg(1) - isHerokuishContainer := common.ToBool(flag.Arg(2)) - err = network.TriggerNetworkComputePorts(appName, processType, isHerokuishContainer) case "network-config-exists": appName := flag.Arg(0) err = network.TriggerNetworkConfigExists(appName) @@ -49,12 +44,6 @@ func main() { appName := flag.Arg(0) processType := flag.Arg(1) err = network.TriggerNetworkGetListeners(appName, processType) - case "network-get-port": - appName := flag.Arg(0) - processType := flag.Arg(1) - containerID := flag.Arg(2) - isHerokuishContainer := common.ToBool(flag.Arg(3)) - err = network.TriggerNetworkGetPort(appName, processType, containerID, isHerokuishContainer) case "network-get-property": appName := flag.Arg(0) property := flag.Arg(1) diff --git a/plugins/network/triggers.go b/plugins/network/triggers.go index 02673cdca0e..0669a858127 100644 --- a/plugins/network/triggers.go +++ b/plugins/network/triggers.go @@ -5,10 +5,8 @@ import ( "io/ioutil" "os" "strings" - "unicode/utf8" "github.com/dokku/dokku/plugins/common" - "github.com/dokku/dokku/plugins/config" ) // TriggerDockerArgsProcess outputs the network plugin docker options for an app @@ -58,33 +56,6 @@ func TriggerInstall() error { return nil } -// TriggerNetworkComputePorts computes the ports for a given app container -func TriggerNetworkComputePorts(appName string, processType string, isHerokuishContainer bool) error { - var dockerfilePorts []string - if !isHerokuishContainer { - dokkuDockerfilePorts := strings.Trim(config.GetWithDefault(appName, "DOKKU_DOCKERFILE_PORTS", ""), " ") - if utf8.RuneCountInString(dokkuDockerfilePorts) > 0 { - dockerfilePorts = strings.Split(dokkuDockerfilePorts, " ") - } - } - - var ports []string - if len(dockerfilePorts) == 0 { - ports = append(ports, "5000") - } else { - for _, port := range dockerfilePorts { - port = strings.TrimSuffix(strings.TrimSpace(port), "/tcp") - if port == "" || strings.HasSuffix(port, "/udp") { - continue - } - ports = append(ports, port) - } - } - - fmt.Println(strings.Join(ports, " ")) - return nil -} - // TriggerNetworkConfigExists writes true or false to stdout whether a given app has network config func TriggerNetworkConfigExists(appName string) error { if HasNetworkConfig(appName) { @@ -114,13 +85,6 @@ func TriggerNetworkGetListeners(appName string, processType string) error { return nil } -// TriggerNetworkGetPort writes the port to stdout for a given app container -func TriggerNetworkGetPort(appName string, processType string, containerID string, isHerokuishContainer bool) error { - port := GetContainerPort(appName, processType, containerID, isHerokuishContainer) - fmt.Println(port) - return nil -} - // TriggerNetworkGetProperty writes the network property to stdout for a given app container func TriggerNetworkGetProperty(appName string, property string) error { computedValueMap := map[string]common.ReportFunc{ diff --git a/plugins/nginx-vhosts/functions b/plugins/nginx-vhosts/functions index 902f3eb7d7d..6bfc9762223 100755 --- a/plugins/nginx-vhosts/functions +++ b/plugins/nginx-vhosts/functions @@ -336,7 +336,6 @@ nginx_build_config() { local SCHEME=http local NGINX_TEMPLATE_SOURCE="built-in" local APP_SSL_PATH="$DOKKU_ROOT/$APP/tls" - 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")" @@ -363,7 +362,6 @@ nginx_build_config() { 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=$(plugn trigger ports-get "$APP") local PORT_MAP PROXY_PORT_MAP proxy_port_map while read -r PORT_MAP; do @@ -492,7 +490,7 @@ nginx_build_config() { PROXY_BUSY_BUFFERS_SIZE="$PROXY_BUSY_BUFFERS_SIZE" # Deprecated: Remove this after a few versions NGINX_PORT="$PROXY_PORT" NGINX_SSL_PORT="$PROXY_SSL_PORT" - PROXY_PORT="$PROXY_PORT" PROXY_SSL_PORT="$PROXY_SSL_PORT" RAW_TCP_PORTS="$RAW_TCP_PORTS" + PROXY_PORT="$PROXY_PORT" PROXY_SSL_PORT="$PROXY_SSL_PORT" PROXY_PORT_MAP="$PROXY_PORT_MAP" PROXY_UPSTREAM_PORTS="$PROXY_UPSTREAM_PORTS" PROXY_X_FORWARDED_FOR="$PROXY_X_FORWARDED_FOR" PROXY_X_FORWARDED_PORT="$PROXY_X_FORWARDED_PORT" diff --git a/plugins/ports/Makefile b/plugins/ports/Makefile index f1d13cfbdd7..6affadf3aac 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/install triggers/ports-clear triggers/ports-configure triggers/ports-dockerfile-raw-tcp-ports triggers/ports-get triggers/ports-get-available triggers/ports-set-detected triggers/post-app-clone-setup triggers/post-app-rename-setup triggers/post-certs-remove triggers/post-certs-update triggers/post-delete triggers/report +TRIGGERS = triggers/install triggers/ports-clear triggers/ports-configure triggers/ports-get triggers/ports-get-available triggers/ports-get-property triggers/ports-set-detected triggers/post-app-clone-setup triggers/post-app-rename-setup triggers/post-certs-remove triggers/post-certs-update triggers/post-delete triggers/report BUILD = commands subcommands triggers PLUGIN_NAME = ports diff --git a/plugins/ports/functions.go b/plugins/ports/functions.go index ba9358b203c..84216613615 100644 --- a/plugins/ports/functions.go +++ b/plugins/ports/functions.go @@ -5,7 +5,6 @@ import ( "fmt" "net" "os" - "path/filepath" "sort" "strconv" "strings" @@ -23,7 +22,11 @@ func addPortMaps(appName string, portMaps []PortMap) error { } func clearPorts(appName string) error { - return common.PropertyDelete("ports", appName, "map") + if err := common.PropertyDelete("ports", appName, "map"); err != nil { + return err + } + + return common.PropertyDelete("ports", appName, "map-detected") } func doesCertExist(appName string) bool { @@ -63,11 +66,33 @@ func getAvailablePort() int { } } +func getComputedProxyPort(appName string) int { + port := getProxyPort(appName) + if port == 0 { + port = getGlobalProxyPort() + } + + return port +} + +func getComputedProxySSLPort(appName string) int { + port := getProxySSLPort(appName) + if port == 0 { + port = getGlobalProxySSLPort() + } + + return port +} + func getDetectedPortMaps(appName string) []PortMap { + basePort := getComputedProxyPort(appName) + if basePort == 0 { + basePort = 80 + } defaultMapping := []PortMap{ { ContainerPort: 5000, - HostPort: 80, + HostPort: basePort, Scheme: "http", }, } @@ -84,6 +109,11 @@ func getDetectedPortMaps(appName string) []PortMap { if doesCertExist(appName) { setSSLPort := false + baseSSLPort := getComputedProxySSLPort(appName) + if baseSSLPort == 0 { + baseSSLPort = 443 + } + for _, portMap := range portMaps { if portMap.Scheme != "http" || portMap.HostPort != 80 { continue @@ -92,7 +122,7 @@ func getDetectedPortMaps(appName string) []PortMap { setSSLPort = true portMaps = append(portMaps, PortMap{ ContainerPort: portMap.ContainerPort, - HostPort: 443, + HostPort: baseSSLPort, Scheme: "https", }) } @@ -111,37 +141,6 @@ func getDetectedPortMaps(appName string) []PortMap { return portMaps } -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 getGlobalProxyPort() int { port := 0 b, _ := common.PlugnTriggerOutput("config-get-global", []string{"DOKKU_PROXY_PORT"}...) @@ -192,21 +191,18 @@ func getProxySSLPort(appName string) int { return port } -func initializeProxyPort(appName string, rawTCPPorts []int) error { +func initializeProxyPort(appName string) error { port := getProxyPort(appName) if port != 0 { return nil } - if len(rawTCPPorts) > 0 { - return nil - } - if isAppVhostEnabled(appName) { port = getGlobalProxyPort() } else { common.LogInfo1("No port set, setting to random open high port") port = getAvailablePort() + common.LogInfo1(fmt.Sprintf("Random port %d", port)) } if port == 0 { @@ -219,7 +215,7 @@ func initializeProxyPort(appName string, rawTCPPorts []int) error { return nil } -func initializeProxySSLPort(appName string, rawTCPPorts []int) error { +func initializeProxySSLPort(appName string) error { port := getProxySSLPort(appName) if port != 0 { return nil @@ -234,7 +230,7 @@ func initializeProxySSLPort(appName string, rawTCPPorts []int) error { port = 443 } - if len(rawTCPPorts) == 0 && !isAppVhostEnabled(appName) { + if !isAppVhostEnabled(appName) { common.LogInfo1("No ssl port set, setting to random open high port") port = getAvailablePort() } @@ -246,55 +242,6 @@ func initializeProxySSLPort(appName string, rawTCPPorts []int) error { return nil } -func initializePortMap(appName string, rawTCPPorts []int) error { - portMaps := getPortMaps(appName) - if len(portMaps) > 0 { - return nil - } - - if len(rawTCPPorts) > 0 { - for _, rawTcpPort := range rawTCPPorts { - portMaps = append(portMaps, PortMap{ - ContainerPort: rawTcpPort, - HostPort: rawTcpPort, - Scheme: "http", - }) - } - } else { - upstreamPort := 5000 - portFile := filepath.Join(common.AppRoot(appName), "PORT.web.1") - if common.FileExists(portFile) { - if port, err := strconv.Atoi(common.ReadFirstLine(portFile)); err == nil { - upstreamPort = port - } - } - - dokkuProxyPort := getProxyPort(appName) - dokkuProxySSLPort := getProxySSLPort(appName) - - if dokkuProxyPort != 0 { - portMaps = append(portMaps, PortMap{ - ContainerPort: upstreamPort, - HostPort: dokkuProxyPort, - Scheme: "http", - }) - } - if dokkuProxySSLPort != 0 { - portMaps = append(portMaps, PortMap{ - ContainerPort: upstreamPort, - HostPort: dokkuProxySSLPort, - Scheme: "https", - }) - } - } - - if len(portMaps) > 0 { - return setPortMaps(appName, portMaps) - } - - return nil -} - func inRange(value int, min int, max int) bool { return min < value && value < max } diff --git a/plugins/ports/src/triggers/triggers.go b/plugins/ports/src/triggers/triggers.go index 3adc5c27ab4..d0e7cfe259e 100644 --- a/plugins/ports/src/triggers/triggers.go +++ b/plugins/ports/src/triggers/triggers.go @@ -26,14 +26,15 @@ func main() { 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 "ports-get": appName := flag.Arg(0) err = ports.TriggerPortsGet(appName) case "ports-get-available": err = ports.TriggerPortsGetAvailable() + case "ports-get-property": + appName := flag.Arg(0) + property := flag.Arg(1) + err = ports.TriggerPortsGetProperty(appName, property) case "ports-set-detected": appName := flag.Arg(0) appName, portMapString := common.ShiftString(flag.Args()) diff --git a/plugins/ports/triggers.go b/plugins/ports/triggers.go index 0bb59ddf67e..e872aea2d09 100644 --- a/plugins/ports/triggers.go +++ b/plugins/ports/triggers.go @@ -52,36 +52,25 @@ func TriggerPortsClear(appName string) error { // TriggerPortsConfigure ensures we have a port mapping func TriggerPortsConfigure(appName string) error { - rawTCPPorts := getDockerfileRawTCPPorts(appName) - - if err := initializeProxyPort(appName, rawTCPPorts); err != nil { - return err - } - - if err := initializeProxySSLPort(appName, rawTCPPorts); err != nil { + if err := initializeProxyPort(appName); err != nil { return err } - if err := initializePortMap(appName, rawTCPPorts); err != nil { + if err := initializeProxySSLPort(appName); err != nil { return err } return nil } -// 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) { + portMaps := getPortMaps(appName) + if len(portMaps) == 0 { + portMaps = getDetectedPortMaps(appName) + } + + for _, portMap := range portMaps { if portMap.AllowsPersistence() { continue } @@ -102,7 +91,23 @@ func TriggerPortsGetAvailable() error { return nil } -// TriggerPortsGetAvailable prints out an available port greater than 1024 +// TriggerPortsGetProperty writes the ports key to stdout for a given app container +func TriggerPortsGetProperty(appName string, key string) error { + if key == "proxy-port" { + fmt.Println(getComputedProxyPort(appName)) + return nil + } + + if key == "proxy-ssl-port" { + fmt.Println(getComputedProxySSLPort(appName)) + return nil + } + + fmt.Println(common.PropertyGet("ports", appName, key)) + return nil +} + +// TriggerPortsSetDetected writes out detected ports func TriggerPortsSetDetected(appName string, portMapString string) error { portMaps, _ := parsePortMapString(portMapString) diff --git a/plugins/scheduler-docker-local/bin/scheduler-deploy-process-container b/plugins/scheduler-docker-local/bin/scheduler-deploy-process-container index 772ee88c587..511e52348f9 100755 --- a/plugins/scheduler-docker-local/bin/scheduler-deploy-process-container +++ b/plugins/scheduler-docker-local/bin/scheduler-deploy-process-container @@ -33,14 +33,16 @@ main() { local DOKKU_PORT="" if [[ "$PROC_TYPE" == "web" ]]; then - ports=($(plugn trigger network-compute-ports "$APP" "$PROC_TYPE" "$DOKKU_HEROKUISH" "$CONTAINER_INDEX")) - for p in "${ports[@]}"; do - if [[ ! "$p" =~ .*udp.* ]]; then - DOKKU_PORT=${DOKKU_PORT:="$p"} + ports=($(plugn trigger ports-get "$APP")) + for port_map in "${ports[@]}"; do + local scheme="$(echo "$port_map" | cut -d':' -f1)" + local container_port="$(echo "$port_map" | cut -d':' -f3)" + if [[ "$scheme" != "udp" ]]; then + DOKKU_PORT="${DOKKU_PORT:="$container_port"}" fi if [[ "$DOKKU_NETWORK_BIND_ALL" == "true" ]]; then - DOCKER_ARGS+=" -p $p" + DOCKER_ARGS+=" -p $container_port" fi done fi @@ -59,7 +61,6 @@ main() { "$DOCKER_BIN" container start "$cid" >/dev/null || true ipaddr=$(plugn trigger network-get-ipaddr "$APP" "$PROC_TYPE" "$cid") - port=$(plugn trigger network-get-port "$APP" "$PROC_TYPE" "$cid" "$DOKKU_HEROKUISH") kill_new() { declare desc="wrapper function to kill newly started app container" @@ -81,7 +82,7 @@ main() { trap "kill_new $cid $PROC_TYPE $CONTAINER_INDEX" INT TERM EXIT if [[ "$DOKKU_CHECKS_DISABLED" == "false" ]]; then dokku_log_verbose "Attempting pre-flight checks ($PROC_TYPE.$CONTAINER_INDEX)" - plugn trigger check-deploy "$APP" "$cid" "$PROC_TYPE" "$port" "$ipaddr" "$CONTAINER_INDEX" + plugn trigger check-deploy "$APP" "$cid" "$PROC_TYPE" "$DOKKU_PORT" "$ipaddr" "$CONTAINER_INDEX" fi trap - INT TERM EXIT @@ -94,7 +95,7 @@ main() { # now using the new container [[ -n "$cid" ]] && echo "$cid" >"$DOKKU_CONTAINER_ID_FILE" [[ -n "$ipaddr" ]] && plugn trigger network-write-ipaddr "$APP" "$PROC_TYPE" "$CONTAINER_INDEX" "$ipaddr" - [[ -n "$port" ]] && plugn trigger network-write-port "$APP" "$PROC_TYPE" "$CONTAINER_INDEX" "$port" + [[ -n "$DOKKU_PORT" ]] && plugn trigger network-write-port "$APP" "$PROC_TYPE" "$CONTAINER_INDEX" "$DOKKU_PORT" # cleanup pre-migration files rm -f "$DOKKU_ROOT/$APP/CONTAINER" "$DOKKU_ROOT/$APP/IP" "$DOKKU_ROOT/$APP/PORT" diff --git a/tests/unit/builder-dockerfile.bats b/tests/unit/builder-dockerfile.bats index 1f304287bbf..34c80520bd2 100644 --- a/tests/unit/builder-dockerfile.bats +++ b/tests/unit/builder-dockerfile.bats @@ -4,9 +4,11 @@ load test_helper setup() { create_app + DOCKERFILE="$BATS_TMPDIR/Dockerfile" } teardown() { + rm -f "$DOCKERFILE" destroy_app } @@ -66,3 +68,29 @@ teardown() { assert_success assert_output_contains "TOKEN is: custom-value" 2 } + +@test "(builder-dockerfile) port exposure (dockerfile raw port)" { + source "$PLUGIN_CORE_AVAILABLE_PATH/builder-dockerfile/internal-functions" + cat <$DOCKERFILE +EXPOSE 3001/udp +EXPOSE 3003 +EXPOSE 3000/tcp +EOF + run fn-builder-dockerfile-get-ports-from-dockerfile $DOCKERFILE + echo "output: $output" + echo "status: $status" + assert_output "3001/udp 3003 3000/tcp" +} + +@test "(builder-dockerfile) port exposure (dockerfile tcp port)" { + source "$PLUGIN_CORE_AVAILABLE_PATH/builder-dockerfile/internal-functions" + cat <$DOCKERFILE +EXPOSE 3001/udp +EXPOSE 3000/tcp +EXPOSE 3003 +EOF + run fn-builder-dockerfile-get-ports-from-dockerfile $DOCKERFILE + echo "output: $output" + echo "status: $status" + assert_output "3001/udp 3000/tcp 3003" +} diff --git a/tests/unit/caddy.bats b/tests/unit/caddy.bats index 7a3c38651ec..f105d2347a2 100644 --- a/tests/unit/caddy.bats +++ b/tests/unit/caddy.bats @@ -137,7 +137,12 @@ teardown() { assert_success assert_output "$TEST_APP.dokku.me" - run /bin/bash -c "dokku ports:report $TEST_APP --ports-map" + run /bin/bash -c "dokku --quiet ports:report $TEST_APP --ports-map" + echo "output: $output" + echo "status: $status" + assert_output_not_exists + + run /bin/bash -c "dokku --quiet ports:report $TEST_APP --ports-map-detected" echo "output: $output" echo "status: $status" assert_output "http:80:5000" diff --git a/tests/unit/core_1.bats b/tests/unit/core_1.bats index 23a5a47f6d2..1c9d32606a7 100644 --- a/tests/unit/core_1.bats +++ b/tests/unit/core_1.bats @@ -46,32 +46,6 @@ teardown() { docker rm $RANDOM_RUN_CID } -@test "(core) port exposure (dockerfile raw port)" { - source "$PLUGIN_CORE_AVAILABLE_PATH/common/functions" - cat <$DOCKERFILE -EXPOSE 3001/udp -EXPOSE 3003 -EXPOSE 3000/tcp -EOF - run get_dockerfile_exposed_ports $DOCKERFILE - echo "output: $output" - echo "status: $status" - assert_output "3001/udp 3003 3000/tcp" -} - -@test "(core) port exposure (dockerfile tcp port)" { - source "$PLUGIN_CORE_AVAILABLE_PATH/common/functions" - cat <$DOCKERFILE -EXPOSE 3001/udp -EXPOSE 3000/tcp -EXPOSE 3003 -EOF - run get_dockerfile_exposed_ports $DOCKERFILE - echo "output: $output" - echo "status: $status" - assert_output "3001/udp 3000/tcp 3003" -} - @test "(core) image type detection (herokuish default user)" { run deploy_app echo "output: $output" diff --git a/tests/unit/haproxy.bats b/tests/unit/haproxy.bats index faa757bf122..0486a6e50fc 100644 --- a/tests/unit/haproxy.bats +++ b/tests/unit/haproxy.bats @@ -154,7 +154,12 @@ teardown() { assert_success assert_output "true" - run /bin/bash -c "dokku ports:report $TEST_APP --ports-map" + run /bin/bash -c "dokku --quiet ports:report $TEST_APP --ports-map" + echo "output: $output" + echo "status: $status" + assert_output_not_exists + + run /bin/bash -c "dokku --quiet ports:report $TEST_APP --ports-map-detected" echo "output: $output" echo "status: $status" assert_output "http:80:5000" diff --git a/tests/unit/nginx-vhosts_4.bats b/tests/unit/nginx-vhosts_4.bats index e1d0d9eb38e..757942b2b00 100644 --- a/tests/unit/nginx-vhosts_4.bats +++ b/tests/unit/nginx-vhosts_4.bats @@ -26,6 +26,11 @@ teardown() { echo "status: $status" assert_success + run /bin/bash -c "dokku ports:report $TEST_APP" + echo "output: $output" + echo "status: $status" + assert_success + HOSTNAME="$(hostname -f)" check_urls http://${HOSTNAME}:[0-9]+ diff --git a/tests/unit/nginx-vhosts_5.bats b/tests/unit/nginx-vhosts_5.bats index 663e20d5e27..f162ef21f55 100644 --- a/tests/unit/nginx-vhosts_5.bats +++ b/tests/unit/nginx-vhosts_5.bats @@ -63,6 +63,9 @@ teardown() { @test "(nginx-vhosts) proxy:build-config (global DOKKU_PROXY_PORT)" { local GLOBAL_PORT=30999 run /bin/bash -c "dokku config:set --global DOKKU_PROXY_PORT=${GLOBAL_PORT}" + echo "output: $output" + echo "status: $status" + assert_success run deploy_app echo "output: $output" @@ -72,4 +75,7 @@ teardown() { assert_http_success http://${TEST_APP}.dokku.me:${GLOBAL_PORT} run /bin/bash -c "dokku config:unset --global DOKKU_PROXY_PORT" + echo "output: $output" + echo "status: $status" + assert_success } diff --git a/tests/unit/nginx-vhosts_7.bats b/tests/unit/nginx-vhosts_7.bats index 32a4f543c00..a7ab2af7836 100644 --- a/tests/unit/nginx-vhosts_7.bats +++ b/tests/unit/nginx-vhosts_7.bats @@ -43,7 +43,7 @@ teardown() { echo "status: $status" assert_success - run deploy_app nodejs-express dokku@dokku.me:$TEST_APP custom_nginx_template + run deploy_app python dokku@dokku.me:$TEST_APP custom_nginx_template echo "output: $output" echo "status: $status" assert_success @@ -73,7 +73,7 @@ teardown() { echo "status: $status" assert_success - run deploy_app nodejs-express dokku@dokku.me:$TEST_APP custom_nginx_template + run deploy_app python dokku@dokku.me:$TEST_APP custom_nginx_template echo "output: $output" echo "status: $status" assert_success diff --git a/tests/unit/nginx-vhosts_8.bats b/tests/unit/nginx-vhosts_8.bats index caf8885e478..c56a3cca03d 100644 --- a/tests/unit/nginx-vhosts_8.bats +++ b/tests/unit/nginx-vhosts_8.bats @@ -133,19 +133,25 @@ teardown() { echo "status: $status" assert_output_contains "Ignoring detected https port mapping without an accompanying ssl certificate" 0 - teardown_test_tls - run /bin/bash -c "dokku ports:report $TEST_APP --ports-map" + run /bin/bash -c "dokku ports:report $TEST_APP --ports-map-detected" echo "output: $output" echo "status: $status" assert_output "http:80:5000 https:443:5000" + teardown_test_tls + + run /bin/bash -c "dokku ports:report $TEST_APP --ports-map-detected" + echo "output: $output" + echo "status: $status" + assert_output "http:80:5000" run /bin/bash -c "dokku proxy:build-config $TEST_APP" echo "output: $output" echo "status: $status" - assert_output_contains "Ignoring detected https port mapping without an accompanying ssl certificate" 1 + run /bin/bash -c "dokku nginx:show-config $TEST_APP" + assert_output_contains "Ignoring detected https port mapping without an accompanying ssl certificate" 0 - run /bin/bash -c "dokku ports:report $TEST_APP --ports-map" + run /bin/bash -c "dokku ports:report $TEST_APP --ports-map-detected" echo "output: $output" echo "status: $status" - assert_output "http:80:5000 https:443:5000" + assert_output "http:80:5000" } diff --git a/tests/unit/ports.bats b/tests/unit/ports.bats index 82df146186a..2dbb307725d 100644 --- a/tests/unit/ports.bats +++ b/tests/unit/ports.bats @@ -34,60 +34,65 @@ teardown() { echo "status: $status" assert_success - run /bin/bash -c "dokku --quiet ports:list $TEST_APP | xargs" + run /bin/bash -c "dokku --quiet ports:report $TEST_APP --ports-map" echo "output: $output" echo "status: $status" - assert_output "http 1234 5001" + assert_output "http:1234:5001" run /bin/bash -c "dokku ports:add $TEST_APP http:8080:5002 https:8443:5003" echo "output: $output" echo "status: $status" assert_success - run /bin/bash -c "dokku --quiet ports:list $TEST_APP | xargs" + run /bin/bash -c "dokku --quiet ports:report $TEST_APP --ports-map" echo "output: $output" echo "status: $status" - assert_output "http 1234 5001 http 8080 5002 https 8443 5003" + assert_output "http:1234:5001 http:8080:5002 https:8443:5003" run /bin/bash -c "dokku ports:set $TEST_APP http:8080:5000 https:8443:5000 http:1234:5001" echo "output: $output" echo "status: $status" assert_success - run /bin/bash -c "dokku --quiet ports:list $TEST_APP | xargs" + run /bin/bash -c "dokku --quiet ports:report $TEST_APP --ports-map" echo "output: $output" echo "status: $status" - assert_output "http 1234 5001 http 8080 5000 https 8443 5000" + assert_output "http:1234:5001 http:8080:5000 https:8443:5000" run /bin/bash -c "dokku ports:remove $TEST_APP 8080" echo "output: $output" echo "status: $status" assert_success - run /bin/bash -c "dokku --quiet ports:list $TEST_APP | xargs" + run /bin/bash -c "dokku --quiet ports:report $TEST_APP --ports-map" echo "output: $output" echo "status: $status" - assert_output "http 1234 5001 https 8443 5000" + assert_output "http:1234:5001 https:8443:5000" run /bin/bash -c "dokku ports:remove $TEST_APP http:1234:5001" echo "output: $output" echo "status: $status" assert_success - run /bin/bash -c "dokku --quiet ports:list $TEST_APP | xargs" + run /bin/bash -c "dokku --quiet ports:report $TEST_APP --ports-map" echo "output: $output" echo "status: $status" - assert_output "https 8443 5000" + assert_output "https:8443:5000" run /bin/bash -c "dokku ports:clear $TEST_APP" echo "output: $output" echo "status: $status" assert_success - run /bin/bash -c "dokku --quiet ports:list $TEST_APP | xargs" + run /bin/bash -c "dokku --quiet ports:report $TEST_APP --ports-map" echo "output: $output" echo "status: $status" - assert_output "http 80 5000" + assert_output_not_exists + + run /bin/bash -c "dokku --quiet ports:report $TEST_APP --ports-map-detected" + echo "output: $output" + echo "status: $status" + assert_output "http:80:5000" } @test "(ports:add) post-deploy add" { @@ -138,7 +143,7 @@ teardown() { run /bin/bash -c "dokku ports:report $TEST_APP --ports-map" echo "output: $output" echo "status: $status" - assert_output "http:80:5000 https:443:5000" + assert_output_not_exists run /bin/bash -c "dokku ports:report $TEST_APP --ports-map-detected" echo "output: $output" @@ -155,7 +160,7 @@ teardown() { run /bin/bash -c "dokku ports:report $TEST_APP --ports-map" echo "output: $output" echo "status: $status" - assert_output "http:3000:3000 http:3003:3003" + assert_output_not_exists run /bin/bash -c "dokku ports:report $TEST_APP --ports-map-detected" echo "output: $output" @@ -170,7 +175,7 @@ teardown() { run /bin/bash -c "dokku ports:report $TEST_APP --ports-map" echo "output: $output" echo "status: $status" - assert_output "http:3000:3000 http:3003:3003" + assert_output_not_exists run /bin/bash -c "dokku ports:report $TEST_APP --ports-map-detected" echo "output: $output" diff --git a/tests/unit/test_helper.bash b/tests/unit/test_helper.bash index 88993b5c34f..9aea3bc3258 100644 --- a/tests/unit/test_helper.bash +++ b/tests/unit/test_helper.bash @@ -224,7 +224,7 @@ assert_http_success() { assert_http_localhost_success() { local scheme="$1" domain="$2" port="${3:-80}" path="${4:-}" run curl --connect-to "$domain:$port:localhost:$port" -kSso /dev/null -w "%{http_code}" "$scheme://$domain:$port$path" - echo "curl: curl --connect-to $domain:$port:localhost:$port-kSso /dev/null -w %{http_code} $scheme://$domain:$port$path" + echo "curl: curl --connect-to $domain:$port:localhost:$port -kSso /dev/null -w %{http_code} $scheme://$domain:$port$path" echo "output: $output" echo "status: $status" assert_output "200" diff --git a/tests/unit/traefik.bats b/tests/unit/traefik.bats index f4a326c45c6..3f7de41b592 100644 --- a/tests/unit/traefik.bats +++ b/tests/unit/traefik.bats @@ -233,7 +233,12 @@ teardown() { assert_success assert_output "5000" - run /bin/bash -c "dokku ports:report $TEST_APP --ports-map" + run /bin/bash -c "dokku --quiet ports:report $TEST_APP --ports-map" + echo "output: $output" + echo "status: $status" + assert_output_not_exists + + run /bin/bash -c "dokku --quiet ports:report $TEST_APP --ports-map-detected" echo "output: $output" echo "status: $status" assert_output "http:80:5000"