From 237aae9eec932bc786c4732e09766aecfd5c417e Mon Sep 17 00:00:00 2001 From: Jose Diaz-Gonzalez Date: Wed, 17 Aug 2022 18:37:32 -0400 Subject: [PATCH] feat: first pass at haproxy plugin implementation --- docs/appendices/0.28.0-migration-guide.md | 4 +- docs/networking/proxies/haproxy.md | 132 +++++++++++++++++ docs/template.html | 1 + plugins/haproxy-vhosts/command-functions | 135 ++++++++++++++++++ plugins/haproxy-vhosts/commands | 15 ++ plugins/haproxy-vhosts/core-post-deploy | 20 +++ .../haproxy-vhosts/docker-args-process-deploy | 86 +++++++++++ plugins/haproxy-vhosts/help-functions | 36 +++++ plugins/haproxy-vhosts/install | 17 +++ plugins/haproxy-vhosts/internal-functions | 45 ++++++ plugins/haproxy-vhosts/plugin.toml | 4 + plugins/haproxy-vhosts/subcommands/default | 6 + plugins/haproxy-vhosts/subcommands/logs | 6 + plugins/haproxy-vhosts/subcommands/report | 6 + plugins/haproxy-vhosts/subcommands/set | 37 +++++ .../haproxy-vhosts/subcommands/show-config | 7 + plugins/haproxy-vhosts/subcommands/start | 6 + plugins/haproxy-vhosts/subcommands/stop | 6 + .../templates/compose.yml.sigil | 20 +++ 19 files changed, 587 insertions(+), 2 deletions(-) create mode 100644 docs/networking/proxies/haproxy.md create mode 100755 plugins/haproxy-vhosts/command-functions create mode 100755 plugins/haproxy-vhosts/commands create mode 100755 plugins/haproxy-vhosts/core-post-deploy create mode 100755 plugins/haproxy-vhosts/docker-args-process-deploy create mode 100755 plugins/haproxy-vhosts/help-functions create mode 100755 plugins/haproxy-vhosts/install create mode 100755 plugins/haproxy-vhosts/internal-functions create mode 100644 plugins/haproxy-vhosts/plugin.toml create mode 100755 plugins/haproxy-vhosts/subcommands/default create mode 100755 plugins/haproxy-vhosts/subcommands/logs create mode 100755 plugins/haproxy-vhosts/subcommands/report create mode 100755 plugins/haproxy-vhosts/subcommands/set create mode 100755 plugins/haproxy-vhosts/subcommands/show-config create mode 100755 plugins/haproxy-vhosts/subcommands/start create mode 100755 plugins/haproxy-vhosts/subcommands/stop create mode 100644 plugins/haproxy-vhosts/templates/compose.yml.sigil diff --git a/docs/appendices/0.28.0-migration-guide.md b/docs/appendices/0.28.0-migration-guide.md index 34e68f4fe..e308cf388 100644 --- a/docs/appendices/0.28.0-migration-guide.md +++ b/docs/appendices/0.28.0-migration-guide.md @@ -19,7 +19,7 @@ Ubuntu 18.04 is now a deprecated installation target. The operating system will ## Additions -New in 0.28.0 are the Caddy and Traefik plugins. As community plugins wrapping these proxies exist, users should: +New in 0.28.0 are the Caddy, Haproxy and Traefik plugins. As community plugins wrapping these proxies exist, users should: - Recommended: Uninstall the community plugin in question and switch all config to the new plugins. -- Upgrade the community plugin to a version that does not use the `proxy:set` value of `caddy` or `traefik`. +- Upgrade the community plugin to a version that does not use the `proxy:set` value of `caddy`, `haproxy` or `traefik`. diff --git a/docs/networking/proxies/haproxy.md b/docs/networking/proxies/haproxy.md new file mode 100644 index 000000000..198576d62 --- /dev/null +++ b/docs/networking/proxies/haproxy.md @@ -0,0 +1,132 @@ +# Haproxy Proxy + +> New as of 0.28.0 + +Dokku provides integration with the [Haproxy](http://www.haproxy.org) proxy service by utilizing the Docker label-based integration implemented by [EasyHaproxy](https://github.com/byjg/docker-easy-haproxy). + +``` +haproxy:report [] [] # Displays a haproxy report for one or more apps +haproxy:logs [--num num] [--tail] # Display haproxy log output +haproxy:set () # Set or clear an haproxy property for an app +haproxy:show-config # Display haproxy compose config +haproxy:start # Starts the haproxy server +haproxy:stop # Stops the haproxy server +``` + +## Usage + +> Warning: As using multiple proxy plugins on a single Dokku installation can lead to issues routing requests to apps, doing so should be avoided. As the default proxy implementation is nginx, users are encouraged to stop the nginx service before switching to Haproxy. + +The Haproxy plugin has specific rules for routing requests: + +- Haproxy integration is exposed via docker labels attached to containers. Changes in labels require either app deploys or rebuilds. +- While Haproxy will respect labels associated with other containers, only `web` containers have Haproxy labels injected by the plugin. +- Only `http:80` port mappings are supported at this time. +- Requests are routed as soon as the container is running and passing healthchecks. + +### Switching to Haproxy + +To use the Haproxy plugin, use the `proxy:set` command for the app in question: + +```shell +dokku proxy:set node-js-app haproxy +``` + +This will enable the docker label-based Haproxy integration. All future deploys will inject the correct labels for Haproxy to read and route requests to containers. Due to the docker label-based integration used by Haproxy, a single deploy or rebuild will be required before requests will route successfully. + +```shell +dokku ps:rebuild node-js-app +``` + +Any changes to domains or port mappings will also require either a deploy or rebuild. + +### Starting Haproxy container + +Haproxy can be started via the `haproxy:start` command. This will start a Haproxy container via the `docker compose up` command. + +```shell +dokku haproxy:start +``` + +### Stopping the Haproxy container + +Haproxy may be stopped via the `haproxy:stop` command. + +```shell +dokku haproxy:stop +``` + +The Haproxy container will be stopped and removed from the system. If the container is not running, this command will do nothing. + +### Showing the Haproxy compose config + +For debugging purposes, it may be useful to show the Haproxy compose config. This can be achieved via the `haproxy:show-config` command. + +```shell +dokku haproxy:show-config +``` + +### Customizing the Haproxy container image + +While the default Haproxy image is hardcoded, users may specify an alternative by setting the `image` property with the `--global` flag: + +```shell +dokku haproxy:set --global image byjg/easy-haproxy:4.0.0 +``` + +#### Checking the Haproxy container's logs + +It may be necessary to check the Haproxy container's logs to ensure that Haproxy is operating as expected. This can be performed with the `haproxy:logs` command. + +```shell +dokku haproxy:logs +``` + +This command also supports the following modifiers: + +```shell +--num NUM # the number of lines to display +--tail # continually stream logs +``` + +You can use these modifiers as follows: + +```shell +dokku haproxy:logs --tail --num 10 +``` + +The above command will show logs continually from the vector container, with an initial history of 10 log lines + +## Displaying Haproxy reports for an app + +You can get a report about the app's Haproxy config using the `haproxy:report` command: + +```shell +dokku haproxy:report +``` + +``` +=====> node-js-app haproxy information + Haproxy image: byjg/easy-haproxy:4.0.0 +=====> python-app haproxy information + Haproxy image: byjg/easy-haproxy:4.0.0 +=====> ruby-app haproxy information + Haproxy image: byjg/easy-haproxy:4.0.0 +``` + +You can run the command for a specific app also. + +```shell +dokku haproxy:report node-js-app +``` + +``` +=====> node-js-app haproxy information + Haproxy image: byjg/easy-haproxy:4.0.0 +``` + +You can pass flags which will output only the value of the specific information you want. For example: + +```shell +dokku haproxy:report node-js-app --haproxy-image +``` diff --git a/docs/template.html b/docs/template.html index d258aa950..df6b69c44 100644 --- a/docs/template.html +++ b/docs/template.html @@ -176,6 +176,7 @@ Proxy Management Caddy Proxy + Haproxy Proxy Nginx Proxy Traefik Proxy diff --git a/plugins/haproxy-vhosts/command-functions b/plugins/haproxy-vhosts/command-functions new file mode 100755 index 000000000..283416120 --- /dev/null +++ b/plugins/haproxy-vhosts/command-functions @@ -0,0 +1,135 @@ +#!/usr/bin/env bash +source "$PLUGIN_CORE_AVAILABLE_PATH/common/functions" +source "$PLUGIN_AVAILABLE_PATH/haproxy-vhosts/internal-functions" +set -eo pipefail +[[ $DOKKU_TRACE ]] && set -x + +cmd-haproxy-report() { + declare desc="displays a haproxy report for one or more apps" + declare cmd="haproxy:report" + [[ "$1" == "$cmd" ]] && shift 1 + declare APP="$1" INFO_FLAG="$2" + + if [[ -n "$APP" ]] && [[ "$APP" == --* ]]; then + INFO_FLAG="$APP" + APP="" + fi + + if [[ -z "$APP" ]] && [[ -z "$INFO_FLAG" ]]; then + INFO_FLAG="true" + fi + + if [[ -z "$APP" ]]; then + for app in $(dokku_apps); do + cmd-haproxy-report-single "$app" "$INFO_FLAG" | tee || true + done + else + cmd-haproxy-report-single "$APP" "$INFO_FLAG" + fi +} + +cmd-haproxy-report-single() { + declare APP="$1" INFO_FLAG="$2" + if [[ "$INFO_FLAG" == "true" ]]; then + INFO_FLAG="" + fi + verify_app_name "$APP" + local flag_map=( + "--haproxy-image: $(fn-haproxy-image)" + ) + + if [[ -z "$INFO_FLAG" ]]; then + dokku_log_info2_quiet "${APP} haproxy information" + for flag in "${flag_map[@]}"; do + key="$(echo "${flag#--}" | cut -f1 -d' ' | tr - ' ')" + dokku_log_verbose "$(printf "%-30s %-25s" "${key^}" "${flag#*: }")" + done + else + local match=false + local value_exists=false + for flag in "${flag_map[@]}"; do + valid_flags="${valid_flags} $(echo "$flag" | cut -d':' -f1)" + if [[ "$flag" == "${INFO_FLAG}:"* ]]; then + value=${flag#*: } + size="${#value}" + if [[ "$size" -ne 0 ]]; then + echo "$value" && match=true && value_exists=true + else + match=true + fi + fi + done + [[ "$match" == "true" ]] || dokku_log_fail "Invalid flag passed, valid flags:${valid_flags}" + fi +} + +cmd-haproxy-logs() { + declare desc="display haproxy logs from command line" + declare cmd="haproxy:logs" + [[ "$1" == "$cmd" ]] && shift 1 + local NUM="100" TAIL=false + + local TEMP=$(getopt -o htn: --long help,tail,num: -n 'dokku haproxy:logs' -- "$@") + local EXIT_CODE="$?" + if [[ "$EXIT_CODE" != 0 ]]; then + fn-haproxy-logs-usage >&2 + exit 1 + fi + eval set -- "$TEMP" + + while true; do + case "$1" in + -t | --tail) + local TAIL=true + shift + ;; + -n | --num) + local NUM="$2" + shift 2 + ;; + --) + shift + break + ;; + *) dokku_log_fail "Internal error" ;; + esac + done + + fn-haproxy-logs "$TAIL" "$NUM" +} + +cmd-haproxy-show-config() { + declare desc="display haproxy config" + declare cmd="haproxy:show-config" + [[ "$1" == "$cmd" ]] && shift 1 + + local TMP_COMPOSE_FILE=$(mktemp "/tmp/dokku-${DOKKU_PID}-${FUNCNAME[0]}.XXXXXX") + trap "rm -rf '$TMP_COMPOSE_FILE' >/dev/null" RETURN INT TERM EXIT + + fn-haproxy-template-compose-file "$TMP_COMPOSE_FILE" + cat "$TMP_COMPOSE_FILE" +} + +cmd-haproxy-start() { + declare desc="Starts the haproxy server" + declare cmd="haproxy:start" + [[ "$1" == "$cmd" ]] && shift 1 + + local TMP_COMPOSE_FILE=$(mktemp "/tmp/dokku-${DOKKU_PID}-${FUNCNAME[0]}.XXXXXX") + trap "rm -rf '$TMP_COMPOSE_FILE' >/dev/null" RETURN INT TERM EXIT + + fn-haproxy-template-compose-file "$TMP_COMPOSE_FILE" + "$DOCKER_BIN" compose -f "$TMP_COMPOSE_FILE" -p haproxy up -d --quiet-pull +} + +cmd-haproxy-stop() { + declare desc="Starts the haproxy server" + declare cmd="haproxy:start" + [[ "$1" == "$cmd" ]] && shift 1 + + local TMP_COMPOSE_FILE=$(mktemp "/tmp/dokku-${DOKKU_PID}-${FUNCNAME[0]}.XXXXXX") + trap "rm -rf '$TMP_COMPOSE_FILE' >/dev/null" RETURN INT TERM EXIT + + fn-haproxy-template-compose-file "$TMP_COMPOSE_FILE" + "$DOCKER_BIN" compose -f "$TMP_COMPOSE_FILE" -p haproxy down --remove-orphans +} diff --git a/plugins/haproxy-vhosts/commands b/plugins/haproxy-vhosts/commands new file mode 100755 index 000000000..945869e42 --- /dev/null +++ b/plugins/haproxy-vhosts/commands @@ -0,0 +1,15 @@ +#!/usr/bin/env bash +[[ " haproxy:help help " == *" $1 "* ]] || exit "$DOKKU_NOT_IMPLEMENTED_EXIT" +source "$PLUGIN_AVAILABLE_PATH/haproxy-vhosts/help-functions" +set -eo pipefail +[[ $DOKKU_TRACE ]] && set -x + +case "$1" in + help | haproxy:help) + cmd-haproxy-help "$@" + ;; + + *) + exit "$DOKKU_NOT_IMPLEMENTED_EXIT" + ;; +esac diff --git a/plugins/haproxy-vhosts/core-post-deploy b/plugins/haproxy-vhosts/core-post-deploy new file mode 100755 index 000000000..7b7c4c968 --- /dev/null +++ b/plugins/haproxy-vhosts/core-post-deploy @@ -0,0 +1,20 @@ +#!/usr/bin/env bash +source "$PLUGIN_CORE_AVAILABLE_PATH/common/functions" +source "$PLUGIN_AVAILABLE_PATH/haproxy-vhosts/internal-functions" +set -eo pipefail +[[ $DOKKU_TRACE ]] && set -x + +trigger-haproxy-vhosts-core-post-deploy() { + declare desc="haproxy-vhosts core-post-deploy plugin trigger" + declare trigger="core-post-deploy" + declare APP="$1" + local tls_internal + + if [[ "$(plugn trigger proxy-type "$APP")" != "haproxy" ]]; then + return + fi + + dokku_log_info1 "Routing app via haproxy" +} + +trigger-haproxy-vhosts-core-post-deploy "$@" diff --git a/plugins/haproxy-vhosts/docker-args-process-deploy b/plugins/haproxy-vhosts/docker-args-process-deploy new file mode 100755 index 000000000..2918f252e --- /dev/null +++ b/plugins/haproxy-vhosts/docker-args-process-deploy @@ -0,0 +1,86 @@ +#!/usr/bin/env bash +source "$PLUGIN_CORE_AVAILABLE_PATH/common/functions" +source "$PLUGIN_AVAILABLE_PATH/haproxy-vhosts/internal-functions" +set -eo pipefail +[[ $DOKKU_TRACE ]] && set -x + +trigger-haproxy-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 haproxy_domains is_app_listening letsencrypt_email output proxy_container_port proxy_host_port port_map proxy_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 app_urls_path="$DOKKU_ROOT/$APP/URLS" + local STDIN=$(cat) + + if [[ "$PROC_TYPE" != "web" ]]; then + return + fi + + if [[ "$(plugn trigger proxy-type "$APP")" != "haproxy" ]]; then + return + fi + + if [[ "$(plugn trigger proxy-is-enabled "$APP")" != "true" ]]; then + return + fi + + if ! plugn trigger domains-vhost-enabled "$APP" 2>/dev/null; then + return + fi + + # run this silently or the output will be set as a label + plugn trigger domains-setup "$APP" >/dev/null + + # ensure we have a port mapping + plugn trigger proxy-configure-ports "$APP" + + app_domains="$(plugn trigger domains-list "$APP")" + if [[ -n "$app_domains" ]]; then + haproxy_domains="$(echo "$app_domains" | xargs)" + haproxy_domains="${haproxy_domains// /,}" + fi + + output="" + # gather port mapping information + is_app_listening="false" + proxy_port_map="$(plugn trigger config-get "$APP" DOKKU_PROXY_PORT_MAP)" + for port_map in $proxy_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")" + + # ignore https for now + if [[ "$proxy_scheme" != "http" ]] && [[ "$proxy_scheme" != "tcp" ]]; then + continue + fi + + # ignore 443 for now + if [[ "$proxy_host_port" == "443" ]]; then + continue + fi + + # ignore everything but 80 for now + if [[ "$proxy_host_port" != "80" ]]; then + continue + fi + + is_app_listening="true" + output="$output --label easyhaproxy.$APP-$PROC_TYPE.mode=$proxy_scheme" + output="$output --label easyhaproxy.$APP-$PROC_TYPE.port=$proxy_host_port" + output="$output --label easyhaproxy.$APP-$PROC_TYPE.localport=$proxy_container_port" + output="$output --label easyhaproxy.$APP-$PROC_TYPE.host=$haproxy_domains" + done + + # add the labels for haproxy here + # prefer the https:443 mapping to http:80 mapping + if [[ -n "$is_app_listening" ]] && [[ -n "$haproxy_domains" ]]; then + echo "# THIS FILE IS GENERATED BY DOKKU - DO NOT EDIT, YOUR CHANGES WILL BE OVERWRITTEN" >"$app_urls_path" + xargs -I{} echo "$scheme://{}" <<<"$(echo "${app_domains}" | tr ' ' '\n' | sort -u)" >>"$app_urls_path" + fi + + echo -n "$STDIN$output" +} + +trigger-haproxy-vhosts-docker-args-process-deploy "$@" diff --git a/plugins/haproxy-vhosts/help-functions b/plugins/haproxy-vhosts/help-functions new file mode 100755 index 000000000..80da34667 --- /dev/null +++ b/plugins/haproxy-vhosts/help-functions @@ -0,0 +1,36 @@ +#!/usr/bin/env bash +set -eo pipefail +[[ $DOKKU_TRACE ]] && set -x + +cmd-haproxy-help() { + declare desc="help command" + declare CMD="$1" + local plugin_name="haproxy" + local plugin_description="Manage mounted volumes" + + if [[ "$CMD" == "${plugin_name}:help" ]]; then + echo -e "Usage: dokku ${plugin_name}[:COMMAND]" + echo '' + echo "$plugin_description" + echo '' + echo 'Additional commands:' + fn-help-content | sort | column -c2 -t -s, + elif [[ $(ps -o command= $PPID) == *"--all"* ]]; then + fn-help-content + else + cat <] [], Displays an haproxy report for one or more apps + haproxy:set (), Set or clear an haproxy property for an app + haproxy:show-config , Display haproxy compose config + haproxy:start, Starts the haproxy server + haproxy:stop, Stops the haproxy server +help_content +} diff --git a/plugins/haproxy-vhosts/install b/plugins/haproxy-vhosts/install new file mode 100755 index 000000000..75e6c3b84 --- /dev/null +++ b/plugins/haproxy-vhosts/install @@ -0,0 +1,17 @@ +#!/usr/bin/env bash +source "$PLUGIN_CORE_AVAILABLE_PATH/common/functions" +source "$PLUGIN_CORE_AVAILABLE_PATH/common/property-functions" +set -eo pipefail +[[ $DOKKU_TRACE ]] && set -x + +trigger-haproxy-install() { + declare desc="installs the haproxy plugin" + declare trigger="install" + + mkdir -p "${DOKKU_LIB_ROOT}/data/haproxy" + chown -R "${DOKKU_SYSTEM_USER}:${DOKKU_SYSTEM_GROUP}" "${DOKKU_LIB_ROOT}/data/haproxy" + + fn-plugin-property-setup "haproxy" +} + +trigger-caddy-install "$@" diff --git a/plugins/haproxy-vhosts/internal-functions b/plugins/haproxy-vhosts/internal-functions new file mode 100755 index 000000000..cd14271ec --- /dev/null +++ b/plugins/haproxy-vhosts/internal-functions @@ -0,0 +1,45 @@ +#!/usr/bin/env bash +source "$PLUGIN_CORE_AVAILABLE_PATH/common/functions" +source "$PLUGIN_CORE_AVAILABLE_PATH/common/property-functions" +set -eo pipefail +[[ $DOKKU_TRACE ]] && set -x + +fn-haproxy-logs() { + declare desc="shows the logs for the haproxy container" + declare TAIL="$1" NUM="$2" + local dokku_logs_args=("--tail" "$NUM") + + if [[ "$TAIL" == "true" ]]; then + dokku_logs_args+=("--follow") + fi + + "$DOCKER_BIN" logs haproxy-haproxy-1 "${dokku_logs_args[@]}" +} + +fn-haproxy-logs-usage() { + declare desc="logs specific usage" + echo "Usage: dokku haproxy:logs" + echo " display recent haproxy log output" + echo "" + echo " -n, --num NUM # the number of lines to display" + echo " -t, --tail # continually stream logs" +} + +fn-haproxy-template-compose-file() { + declare desc="templates out the compose file" + declare OUTPUT_PATH="$1" + local COMPOSE_TEMPLATE="$PLUGIN_AVAILABLE_PATH/haproxy-vhosts/templates/compose.yml.sigil" + + CUSTOM_COMPOSE_TEMPLATE="$(plugn trigger haproxy-template-source "$APP")" + if [[ -n "$CUSTOM_COMPOSE_TEMPLATE" ]]; then + COMPOSE_TEMPLATE="$CUSTOM_COMPOSE_TEMPLATE" + fi + + local SIGIL_PARAMS=(HAPROXY_IMAGE="$(fn-haproxy-image)") + + sigil -f "$COMPOSE_TEMPLATE" "${SIGIL_PARAMS[@]}" | cat -s >"$OUTPUT_PATH" +} + +fn-haproxy-image() { + fn-plugin-property-get-default "haproxy" "--global" "image" "byjg/easy-haproxy:4.0.0" +} diff --git a/plugins/haproxy-vhosts/plugin.toml b/plugins/haproxy-vhosts/plugin.toml new file mode 100644 index 000000000..39b6df8eb --- /dev/null +++ b/plugins/haproxy-vhosts/plugin.toml @@ -0,0 +1,4 @@ +[plugin] +description = "dokku core caddy-vhosts plugin" +version = "0.27.10" +[plugin.config] diff --git a/plugins/haproxy-vhosts/subcommands/default b/plugins/haproxy-vhosts/subcommands/default new file mode 100755 index 000000000..dfdd058d7 --- /dev/null +++ b/plugins/haproxy-vhosts/subcommands/default @@ -0,0 +1,6 @@ +#!/usr/bin/env bash +set -eo pipefail +[[ $DOKKU_TRACE ]] && set -x +source "$PLUGIN_AVAILABLE_PATH/haproxy-vhosts/help-functions" + +cmd-haproxy-help "haproxy:help" diff --git a/plugins/haproxy-vhosts/subcommands/logs b/plugins/haproxy-vhosts/subcommands/logs new file mode 100755 index 000000000..2112086fd --- /dev/null +++ b/plugins/haproxy-vhosts/subcommands/logs @@ -0,0 +1,6 @@ +#!/usr/bin/env bash +source "$PLUGIN_AVAILABLE_PATH/haproxy-vhosts/command-functions" +set -eo pipefail +[[ $DOKKU_TRACE ]] && set -x + +cmd-haproxy-logs "$@" diff --git a/plugins/haproxy-vhosts/subcommands/report b/plugins/haproxy-vhosts/subcommands/report new file mode 100755 index 000000000..0e483c438 --- /dev/null +++ b/plugins/haproxy-vhosts/subcommands/report @@ -0,0 +1,6 @@ +#!/usr/bin/env bash +source "$PLUGIN_AVAILABLE_PATH/haproxy-vhosts/command-functions" +set -eo pipefail +[[ $DOKKU_TRACE ]] && set -x + +cmd-haproxy-report "$@" diff --git a/plugins/haproxy-vhosts/subcommands/set b/plugins/haproxy-vhosts/subcommands/set new file mode 100755 index 000000000..54f7388dc --- /dev/null +++ b/plugins/haproxy-vhosts/subcommands/set @@ -0,0 +1,37 @@ +#!/usr/bin/env bash +source "$PLUGIN_CORE_AVAILABLE_PATH/common/functions" +source "$PLUGIN_CORE_AVAILABLE_PATH/common/property-functions" +set -eo pipefail +[[ $DOKKU_TRACE ]] && set -x + +cmd-haproxy-set() { + declare desc="set or clear an haproxy property for an app" + declare cmd="haproxy:set" + [[ "$1" == "$cmd" ]] && shift 1 + declare APP="$1" KEY="$2" VALUE="$3" + local VALID_KEYS=("image") + local GLOBAL_KEYS=("image") + + [[ -z "$KEY" ]] && dokku_log_fail "No key specified" + + if ! fn-in-array "$KEY" "${VALID_KEYS[@]}"; then + dokku_log_fail "Invalid key specified, valid keys include: image" + fi + + if ! fn-in-array "$KEY" "${GLOBAL_KEYS[@]}"; then + if [[ "$APP" == "--global" ]]; then + dokku_log_fail "The key '$KEY' cannot be set globally" + fi + verify_app_name "$APP" + fi + + if [[ -n "$VALUE" ]]; then + dokku_log_info2_quiet "Setting ${KEY} to ${VALUE}" + fn-plugin-property-write "haproxy" "$APP" "$KEY" "$VALUE" + else + dokku_log_info2_quiet "Unsetting ${KEY}" + fn-plugin-property-delete "haproxy" "$APP" "$KEY" + fi +} + +cmd-haproxy-set "$@" diff --git a/plugins/haproxy-vhosts/subcommands/show-config b/plugins/haproxy-vhosts/subcommands/show-config new file mode 100755 index 000000000..0b58d12a4 --- /dev/null +++ b/plugins/haproxy-vhosts/subcommands/show-config @@ -0,0 +1,7 @@ +#!/usr/bin/env bash +set -eo pipefail +[[ $DOKKU_TRACE ]] && set -x +source "$PLUGIN_CORE_AVAILABLE_PATH/common/functions" +source "$PLUGIN_AVAILABLE_PATH/haproxy-vhosts/command-functions" + +cmd-haproxy-show-config "$@" diff --git a/plugins/haproxy-vhosts/subcommands/start b/plugins/haproxy-vhosts/subcommands/start new file mode 100755 index 000000000..7b73b1fc2 --- /dev/null +++ b/plugins/haproxy-vhosts/subcommands/start @@ -0,0 +1,6 @@ +#!/usr/bin/env bash +set -eo pipefail +[[ $DOKKU_TRACE ]] && set -x +source "$PLUGIN_AVAILABLE_PATH/haproxy-vhosts/command-functions" + +cmd-haproxy-start "$@" diff --git a/plugins/haproxy-vhosts/subcommands/stop b/plugins/haproxy-vhosts/subcommands/stop new file mode 100755 index 000000000..4e6119885 --- /dev/null +++ b/plugins/haproxy-vhosts/subcommands/stop @@ -0,0 +1,6 @@ +#!/usr/bin/env bash +set -eo pipefail +[[ $DOKKU_TRACE ]] && set -x +source "$PLUGIN_AVAILABLE_PATH/haproxy-vhosts/command-functions" + +cmd-haproxy-stop "$@" diff --git a/plugins/haproxy-vhosts/templates/compose.yml.sigil b/plugins/haproxy-vhosts/templates/compose.yml.sigil new file mode 100644 index 000000000..1b63072f8 --- /dev/null +++ b/plugins/haproxy-vhosts/templates/compose.yml.sigil @@ -0,0 +1,20 @@ +--- +version: "3.7" + +services: + caddy: + image: "{{ $.HAPROXY_IMAGE }}" + + environment: + - EASYHAPROXY_DISCOVER=docker + - EASYHAPROXY_LABEL_PREFIX=haproxy + + network_mode: bridge + + ports: + - "80:80" + + restart: unless-stopped + + volumes: + - "/var/run/docker.sock:/var/run/docker.sock:ro"