mirror of
https://github.com/dokku/dokku.git
synced 2025-12-16 03:57:43 +01:00
refactor: only use detected port mapping if override is not specified
Previously, we would always set the port mapping during a dockerfile build, making it difficult for users to override mappings. We also only _sometimes_ updated the detected port mapping, further confusing issues when users were migrating from Dockerfile to Buildpacks for builds. Now, we always detect the port mapping during the build process, and only use that detected port mapping if an override is not specified. This greatly simplifies the experience around port mapping, as now a user can create an app, set a port mapping, and that first deploy will respect the port mapping without an additional deploy. The builder always has the best context for what the app should be listening on, and thus we can always specify a "default" port mapping at this stage. Users can override this map as desired later. This change also results in the removal of a ton of internal code that is now centralized in the ports plugin. Closes #4067
This commit is contained in:
@@ -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.
|
||||
|
||||
@@ -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` <br /> `~dokku/.dokkurc` <br /> `~dokku/.dokkurc/*` <br /> `dokku config:set` | |
|
||||
|
||||
@@ -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,24 +1228,7 @@ set -eo pipefail; [[ $DOKKU_TRACE ]] && set -x
|
||||
|
||||
### `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
|
||||
- Description: Configures the initial proxy ports
|
||||
- Invoked by: `internally triggered by proxy plugins`
|
||||
- Arguments: `$APP`
|
||||
- Example:
|
||||
@@ -1318,7 +1271,24 @@ set -eo pipefail; [[ $DOKKU_TRACE ]] && set -x
|
||||
# TODO
|
||||
```
|
||||
|
||||
### `ports-get-property`
|
||||
|
||||
- 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...]`
|
||||
|
||||
@@ -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:
|
||||
|
||||
@@ -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
|
||||
```
|
||||
|
||||
@@ -1 +0,0 @@
|
||||
hook
|
||||
@@ -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"
|
||||
|
||||
@@ -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
|
||||
}
|
||||
|
||||
@@ -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"
|
||||
}
|
||||
|
||||
|
||||
@@ -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"
|
||||
}
|
||||
|
||||
|
||||
@@ -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"
|
||||
}
|
||||
|
||||
|
||||
@@ -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"
|
||||
}
|
||||
|
||||
|
||||
@@ -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"
|
||||
|
||||
@@ -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 "$@"
|
||||
@@ -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
|
||||
|
||||
@@ -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
|
||||
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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)
|
||||
|
||||
@@ -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{
|
||||
|
||||
@@ -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"
|
||||
|
||||
@@ -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
|
||||
|
||||
|
||||
@@ -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
|
||||
}
|
||||
|
||||
@@ -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())
|
||||
|
||||
@@ -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 {
|
||||
if err := initializeProxyPort(appName); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
if err := initializeProxySSLPort(appName, rawTCPPorts); err != nil {
|
||||
if err := initializeProxySSLPort(appName); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
if err := initializePortMap(appName, rawTCPPorts); 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)
|
||||
|
||||
|
||||
@@ -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"
|
||||
|
||||
@@ -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 <<EOF >$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 <<EOF >$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"
|
||||
}
|
||||
|
||||
@@ -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"
|
||||
|
||||
@@ -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 <<EOF >$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 <<EOF >$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"
|
||||
|
||||
@@ -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"
|
||||
|
||||
@@ -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]+
|
||||
|
||||
|
||||
@@ -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
|
||||
}
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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"
|
||||
}
|
||||
|
||||
@@ -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"
|
||||
|
||||
@@ -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"
|
||||
|
||||
@@ -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"
|
||||
|
||||
Reference in New Issue
Block a user