这是indexloc提供的服务,不要输入任何密码
Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
17 commits
Select commit Hold shift + click to select a range
3684b88
refactor: only use detected port mapping if override is not specified
josegonzalez Jul 12, 2023
2fb9163
fix: use ports:report for checking port mappings in tests
josegonzalez Jul 30, 2023
7394ffa
fix: correct issues in tests where we checked the wrong value for the…
josegonzalez Jul 30, 2023
45ebc71
fix: correct issue in nginx tls detection tests
josegonzalez Jul 30, 2023
d4b2d34
fix: correct tests
josegonzalez Jul 31, 2023
0ec7fb5
fix: use the correct port
josegonzalez Jul 31, 2023
7840e7e
refactor: talk directly to localhost backend in test to ensure test s…
josegonzalez Jul 31, 2023
b153747
fix: remove re-implemented trigger
josegonzalez Jul 31, 2023
5569582
feat: respect the proxy/proxy-ssl ports when constructing mappings
josegonzalez Jul 31, 2023
f91d6de
fix: additionally clear detected ports when clearing the port mapping
josegonzalez Jul 31, 2023
5e0ba4a
fix: handle default 0 ports for the proxy/proxy-ssl port
josegonzalez Jul 31, 2023
e95da39
chore: use python instead of nodejs-express
josegonzalez Jul 31, 2023
9088917
fix: hardcode port 5000 if no port is specified
josegonzalez Jul 31, 2023
a3e4943
fix: set correct port for checks
josegonzalez Aug 1, 2023
f5a45f1
fix: set correct scheme and don't override DOKKU_PORT if set
josegonzalez Aug 1, 2023
241f71b
fix: add assertion to test and respect the global ports when detectin…
josegonzalez Aug 2, 2023
0a11f16
feat: respect detected proxy-port configuration when writing detected…
josegonzalez Aug 5, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 12 additions & 2 deletions docs/appendices/0.31.0-migration-guide.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.
1 change: 0 additions & 1 deletion docs/configuration/environment-variables.md
Original file line number Diff line number Diff line change
Expand Up @@ -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` | |
Expand Down
54 changes: 12 additions & 42 deletions docs/development/plugin-triggers.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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:
Expand All @@ -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:

Expand All @@ -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:
Expand All @@ -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...]`
Expand Down
22 changes: 0 additions & 22 deletions docs/networking/port-management.md
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
1 change: 0 additions & 1 deletion docs/networking/proxies/nginx.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
```
Expand Down
1 change: 0 additions & 1 deletion plugins/20_events/ports-dockerfile-raw-tcp-ports

This file was deleted.

4 changes: 0 additions & 4 deletions plugins/builder-dockerfile/builder-build
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
4 changes: 3 additions & 1 deletion plugins/builder-dockerfile/internal-functions
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
5 changes: 4 additions & 1 deletion plugins/builder-herokuish/builder-build
Original file line number Diff line number Diff line change
Expand Up @@ -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"
}

Expand Down
4 changes: 3 additions & 1 deletion plugins/builder-lambda/builder-build
Original file line number Diff line number Diff line change
Expand Up @@ -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"
}

Expand Down
4 changes: 3 additions & 1 deletion plugins/builder-pack/builder-build
Original file line number Diff line number Diff line change
Expand Up @@ -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"
}

Expand Down
12 changes: 11 additions & 1 deletion plugins/checks/subcommands/run
Original file line number Diff line number Diff line change
Expand Up @@ -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"
}

Expand Down
21 changes: 4 additions & 17 deletions plugins/common/functions
Original file line number Diff line number Diff line change
Expand Up @@ -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)"

Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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"
Expand Down
6 changes: 0 additions & 6 deletions plugins/common/ports-get-available

This file was deleted.

27 changes: 7 additions & 20 deletions plugins/domains/internal-functions
Original file line number Diff line number Diff line change
Expand Up @@ -137,35 +137,22 @@ 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
local scheme="$(awk -F ':' '{ print $1 }' <<<"$port_map")"
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
Expand Down
2 changes: 1 addition & 1 deletion plugins/network/Makefile
Original file line number Diff line number Diff line change
@@ -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

Expand Down
Loading