diff --git a/docs/appendices/0.37.0-migration-guide.md b/docs/appendices/0.37.0-migration-guide.md index cb33e72df..6aa474994 100644 --- a/docs/appendices/0.37.0-migration-guide.md +++ b/docs/appendices/0.37.0-migration-guide.md @@ -5,3 +5,4 @@ - Support for the `DOKKU_DOCKERFILE_CACHE_BUILD` environment variable has been removed. Use the `docker-options` plugin to set build arguments for your app instead. - Support for the `DOKKU_DOCKER_BUILD_OPTS` environment variable has been removed. Use the `docker-options` plugin to set build arguments for your app instead. - Support for the `no-cache` nixpacks property has been removed. Use the `docker-options` plugin to set build arguments for your app instead. +- Support for customizing the label-key for the caddy proxy has been removed. Always use `caddy.` as a prefix for your caddy directives. diff --git a/docs/networking/proxies/caddy.md b/docs/networking/proxies/caddy.md index 7edaa6cdf..454086960 100644 --- a/docs/networking/proxies/caddy.md +++ b/docs/networking/proxies/caddy.md @@ -3,7 +3,7 @@ > [!IMPORTANT] > New as of 0.28.0 -Dokku provides integration with the [Caddy](https://caddyserver.com/) proxy service by utilizing the Docker label-based integration implemented by Caddy. +Dokku provides integration with the [Caddy](https://caddyserver.com/) proxy service by utilizing the Docker label-based integration implemented by [Caddy Docker Proxy](https://github.com/lucaslorentz/caddy-docker-proxy). ``` caddy:report [] [] # Displays a caddy report for one or more apps @@ -117,15 +117,53 @@ dokku caddy:set --global log-level DEBUG After modifying, the Caddy container will need to be restarted. -### Changing the label key for the app +### Label Management -The default label key for the app is `caddy`. This can be changed by setting the `label-key` property: +The Caddy plugin allows you to add custom container labels to apps. These labels are injected into containers during deployment and can be used to configure Caddy behavior beyond what the plugin provides by default. + +Refer to the upstream [caddy-docker-proxy](https://github.com/lucaslorentz/caddy-docker-proxy) documentation for more information on what labels are available. + +#### Adding a label + +To add a custom container label to an app, use the `caddy:labels:add` command: ```shell -dokku caddy:set node-js-app label-key caddy_0 +dokku caddy:labels:add node-js-app caddy.directive value ``` -This will update the app's label key to `caddy_0`. The label key is used to identify the app in the Caddy configuration. If you change the label key, you will need to restart or rebuild the app to apply the updates. +This will add the label `caddy.directive=value` to the app's containers. After adding a label, you will need to rebuild or redeploy the app for the label to be applied to running containers. + +```shell +dokku ps:rebuild node-js-app +``` + +#### Removing a label + +To remove a custom container label from an app, use the `caddy:labels:remove` command: + +```shell +dokku caddy:labels:remove node-js-app caddy.directive +``` + +This will remove the specified label from the app. After removing a label, you will need to rebuild or redeploy the app for the change to be applied to running containers. + +```shell +dokku ps:rebuild node-js-app +``` + +#### Showing labels + +To view all custom container labels for an app, use the `caddy:labels:show` command: + +```shell +dokku caddy:labels:show node-js-app +``` + +To view a specific label value, provide the label name: + +```shell +dokku caddy:labels:show node-js-app caddy.directive +``` ### SSL Configuration diff --git a/docs/networking/proxies/haproxy.md b/docs/networking/proxies/haproxy.md index eda8e27bd..13b0f2272 100644 --- a/docs/networking/proxies/haproxy.md +++ b/docs/networking/proxies/haproxy.md @@ -113,6 +113,54 @@ dokku haproxy:set --global log-level DEBUG After modifying, the Haproxy container will need to be restarted. +### Label Management + +The Haproxy plugin allows you to add custom container labels to apps. These labels are injected into containers during deployment and can be used to configure Haproxy behavior beyond what the plugin provides by default. + +Refer to the upstream [EasyHaproxy](https://github.com/byjg/docker-easy-haproxy) documentation for more information on what labels are available. + +#### Adding a label + +To add a custom container label to an app, use the `haproxy:labels:add` command: + +```shell +dokku haproxy:labels:add node-js-app haproxy.directive value +``` + +This will add the label `haproxy.directive=value` to the app's containers. After adding a label, you will need to rebuild or redeploy the app for the label to be applied to running containers. + +```shell +dokku ps:rebuild node-js-app +``` + +#### Removing a label + +To remove a custom container label from an app, use the `haproxy:labels:remove` command: + +```shell +dokku haproxy:labels:remove node-js-app haproxy.directive +``` + +This will remove the specified label from the app. After removing a label, you will need to rebuild or redeploy the app for the change to be applied to running containers. + +```shell +dokku ps:rebuild node-js-app +``` + +#### Showing labels + +To view all custom container labels for an app, use the `haproxy:labels:show` command: + +```shell +dokku haproxy:labels:show node-js-app +``` + +To view a specific label value, provide the label name: + +```shell +dokku haproxy:labels:show node-js-app haproxy.directive +``` + ### SSL Configuration The haproxy plugin only supports automatic ssl certificates from it's letsencrypt integration. Managed certificates provided by the `certs` plugin are ignored. diff --git a/docs/networking/proxies/openresty.md b/docs/networking/proxies/openresty.md index 1a275de05..d1597be95 100644 --- a/docs/networking/proxies/openresty.md +++ b/docs/networking/proxies/openresty.md @@ -124,6 +124,54 @@ The following folders within an app repository may have `*.conf` files that will - `openresty/http-includes/`: Injected in the `server` block serving http(s) requests for the app. - `openresty/http-location-includes/`: Injected in the `location` block that proxies to the app in the app's respective `server` block. +### Label Management + +The OpenResty plugin allows you to add custom container labels to apps. These labels are injected into containers during deployment and can be used to configure OpenResty behavior beyond what the plugin provides by default. + +Refer to the upstream [openresty-docker-proxy](https://github.com/dokku/openresty-docker-proxy) documentation for more information on what labels are available. + +#### Adding a label + +To add a custom container label to an app, use the `openresty:labels:add` command: + +```shell +dokku openresty:labels:add node-js-app openresty.directive value +``` + +This will add the label `openresty.directive=value` to the app's containers. After adding a label, you will need to rebuild or redeploy the app for the label to be applied to running containers. + +```shell +dokku ps:rebuild node-js-app +``` + +#### Removing a label + +To remove a custom container label from an app, use the `openresty:labels:remove` command: + +```shell +dokku openresty:labels:remove node-js-app openresty.directive +``` + +This will remove the specified label from the app. After removing a label, you will need to rebuild or redeploy the app for the change to be applied to running containers. + +```shell +dokku ps:rebuild node-js-app +``` + +#### Showing labels + +To view all custom container labels for an app, use the `openresty:labels:show` command: + +```shell +dokku openresty:labels:show node-js-app +``` + +To view a specific label value, provide the label name: + +```shell +dokku openresty:labels:show node-js-app openresty.directive +``` + ### SSL Configuration The OpenResty plugin only supports automatic ssl certificates from it's letsencrypt integration. Managed certificates provided by the `certs` plugin are ignored. diff --git a/docs/networking/proxies/traefik.md b/docs/networking/proxies/traefik.md index 3d8fe76f5..a6718f0fa 100644 --- a/docs/networking/proxies/traefik.md +++ b/docs/networking/proxies/traefik.md @@ -127,6 +127,54 @@ dokku traefik:set --global log-level DEBUG After modifying, the Traefik container will need to be restarted. +### Label Management + +The Traefik plugin allows you to add custom container labels to apps. These labels are injected into containers during deployment and can be used to configure Traefik behavior beyond what the plugin provides by default. + +Refer to the upstream [Traefik](https://doc.traefik.io/traefik/) documentation for more information on what labels are available. + +#### Adding a label + +To add a custom container label to an app, use the `traefik:labels:add` command: + +```shell +dokku traefik:labels:add node-js-app traefik.directive value +``` + +This will add the label `traefik.directive=value` to the app's containers. After adding a label, you will need to rebuild or redeploy the app for the label to be applied to running containers. + +```shell +dokku ps:rebuild node-js-app +``` + +#### Removing a label + +To remove a custom container label from an app, use the `traefik:labels:remove` command: + +```shell +dokku traefik:labels:remove node-js-app traefik.directive +``` + +This will remove the specified label from the app. After removing a label, you will need to rebuild or redeploy the app for the change to be applied to running containers. + +```shell +dokku ps:rebuild node-js-app +``` + +#### Showing labels + +To view all custom container labels for an app, use the `traefik:labels:show` command: + +```shell +dokku traefik:labels:show node-js-app +``` + +To view a specific label value, provide the label name: + +```shell +dokku traefik:labels:show node-js-app traefik.directive +``` + ### SSL Configuration The traefik plugin only supports automatic ssl certificates from it's letsencrypt integration. Managed certificates provided by the `certs` plugin are ignored. diff --git a/plugins/caddy-vhosts/command-functions b/plugins/caddy-vhosts/command-functions index 1f04357ff..56817212e 100755 --- a/plugins/caddy-vhosts/command-functions +++ b/plugins/caddy-vhosts/command-functions @@ -1,9 +1,34 @@ #!/usr/bin/env bash source "$PLUGIN_CORE_AVAILABLE_PATH/common/functions" +source "$PLUGIN_AVAILABLE_PATH/proxy/command-functions" source "$PLUGIN_AVAILABLE_PATH/caddy-vhosts/internal-functions" set -eo pipefail [[ $DOKKU_TRACE ]] && set -x +cmd-caddy-labels-add() { + declare desc="adds container label to app for specified proxy" + declare cmd="caddy:labels:add" + [[ "$1" == "$cmd" ]] && shift 1 + + cmd-proxy-labels-add "proxy:labels:add" "caddy" "$@" +} + +cmd-caddy-labels-remove() { + declare desc="removes container label from app for specified proxy" + declare cmd="caddy:labels:remove" + [[ "$1" == "$cmd" ]] && shift 1 + + cmd-proxy-labels-remove "proxy:labels:remove" "caddy" "$@" +} + +cmd-caddy-labels-show() { + declare desc="shows container labels for app for specified proxy" + declare cmd="caddy:labels:show" + [[ "$1" == "$cmd" ]] && shift 1 + + cmd-proxy-labels-show "proxy:labels:show" "caddy" "$@" +} + cmd-caddy-report() { declare desc="displays a caddy report for one or more apps" declare cmd="caddy:report" diff --git a/plugins/caddy-vhosts/commands b/plugins/caddy-vhosts/commands index 03e69b312..de26adef2 100755 --- a/plugins/caddy-vhosts/commands +++ b/plugins/caddy-vhosts/commands @@ -1,6 +1,7 @@ #!/usr/bin/env bash -[[ " caddy:help help " == *" $1 "* ]] || exit "$DOKKU_NOT_IMPLEMENTED_EXIT" +[[ " caddy:help caddy:labels:add caddy:labels:remove caddy:labels:show help " == *" $1 "* ]] || exit "$DOKKU_NOT_IMPLEMENTED_EXIT" source "$PLUGIN_AVAILABLE_PATH/caddy-vhosts/help-functions" +source "$PLUGIN_AVAILABLE_PATH/caddy-vhosts/command-functions" set -eo pipefail [[ $DOKKU_TRACE ]] && set -x @@ -9,6 +10,18 @@ case "$1" in cmd-caddy-help "$@" ;; + caddy:labels:add) + cmd-caddy-labels-add "$@" + ;; + + caddy:labels:remove) + cmd-caddy-labels-remove "$@" + ;; + + caddy:labels:show) + cmd-caddy-labels-show "$@" + ;; + *) exit "$DOKKU_NOT_IMPLEMENTED_EXIT" ;; diff --git a/plugins/caddy-vhosts/docker-args-process-deploy b/plugins/caddy-vhosts/docker-args-process-deploy index 9dd1f61f1..7b909315c 100755 --- a/plugins/caddy-vhosts/docker-args-process-deploy +++ b/plugins/caddy-vhosts/docker-args-process-deploy @@ -1,5 +1,6 @@ #!/usr/bin/env bash source "$PLUGIN_CORE_AVAILABLE_PATH/common/functions" +source "$PLUGIN_AVAILABLE_PATH/proxy/functions" source "$PLUGIN_AVAILABLE_PATH/caddy-vhosts/internal-functions" set -eo pipefail [[ $DOKKU_TRACE ]] && set -x @@ -8,7 +9,7 @@ trigger-caddy-vhosts-docker-args-process-deploy() { declare desc="nginx-vhosts core-post-deploy plugin trigger" declare trigger="docker-args-process-deploy" declare APP="$1" IMAGE_SOURCE_TYPE="$2" IMAGE_TAG="$3" PROC_TYPE="$4" CONTAINER_INDEX="$5" - local app_domains caddy_domains is_app_listening letsencrypt_email output proxy_container_port proxy_host_port port_map proxy_scheme proxy_schemes scheme tls_internal label_key + local app_domains caddy_domains is_app_listening letsencrypt_email output proxy_container_port proxy_host_port port_map proxy_scheme proxy_schemes scheme tls_internal local proxy_container_http_port proxy_container_http_port_candidate proxy_host_http_port_candidate local proxy_container_https_port proxy_container_https_port_candidate proxy_host_https_port_candidate local STDIN=$(cat) @@ -88,14 +89,13 @@ trigger-caddy-vhosts-docker-args-process-deploy() { if [[ -n "$is_app_listening" ]] && [[ -n "$caddy_domains" ]]; then has_443_mapping=false tls_internal="$(fn-caddy-tls-internal)" - label_key="$(fn-caddy-label-key "$APP")" if [[ -n "$proxy_container_https_port" ]] || [[ -n "$proxy_container_https_port_candidate" ]]; then has_443_mapping=true fi ssl_warning_mapping="https:443" if [[ "$tls_internal" == "true" ]]; then - output="--label ${label_key}.tls=internal" + output="--label caddy.tls=internal" if [[ "$has_443_mapping" == "false" ]]; then ssl_warning_mapping="http:80" proxy_host_https_port_candidate="$proxy_host_http_port_candidate" @@ -106,7 +106,7 @@ trigger-caddy-vhosts-docker-args-process-deploy() { scheme="http" if [[ -n "$letsencrypt_email" ]] && [[ "$has_443_mapping" == "true" ]]; then - output="--label '${label_key}=${caddy_domains}'" + output="--label 'caddy=${caddy_domains}'" scheme="https" if [[ -z "$proxy_container_https_port" ]]; then warning_scheme="$(awk -F ':' '{ print $1 }' <<<"$ssl_warning_mapping")" @@ -115,20 +115,28 @@ trigger-caddy-vhosts-docker-args-process-deploy() { proxy_container_https_port="$proxy_container_https_port_candidate" fi - output="$output --label \"${label_key}.reverse_proxy={{ upstreams $proxy_container_https_port }}\"" + output="$output --label \"caddy.reverse_proxy={{ upstreams $proxy_container_https_port }}\"" elif [[ -n "$proxy_container_http_port" ]] || [[ -n "$proxy_container_http_port_candidate" ]]; then caddy_domains="${caddy_domains//, /:80, }" - output="--label '${label_key}=${caddy_domains}:80'" + output="--label 'caddy=${caddy_domains}:80'" if [[ -z "$proxy_container_http_port" ]]; then dokku_log_warn "Warning: http:80 port mapping not found" dokku_log_warn "Utilizing first http port mapping, http:$proxy_host_http_port_candidate:$proxy_container_http_port_candidate" proxy_container_http_port="$proxy_container_http_port_candidate" fi - output="$output --label \"${label_key}.reverse_proxy={{ upstreams $proxy_container_http_port }}\"" + output="$output --label \"caddy.reverse_proxy={{ upstreams $proxy_container_http_port }}\"" fi fi + local proxy_labels_file_path=$(fn-proxy-get-labels-file-path "caddy" "$APP") + if [[ -f "$proxy_labels_file_path" ]]; then + while read -r line; do + [[ -z "$line" ]] && continue + output="$output --label '$line'" + done <"$proxy_labels_file_path" + fi + echo -n "$STDIN$output" } diff --git a/plugins/caddy-vhosts/help-functions b/plugins/caddy-vhosts/help-functions index 287ffed04..19d17a00e 100755 --- a/plugins/caddy-vhosts/help-functions +++ b/plugins/caddy-vhosts/help-functions @@ -30,6 +30,9 @@ fn-help-content() { caddy:report [] [], Displays an caddy report for one or more apps caddy:set (), Set or clear an caddy property for an app caddy:show-config , Display caddy compose config + caddy:labels:add