From cee40ae5b43556092f05a517990eaefd66eb2634 Mon Sep 17 00:00:00 2001 From: Valentin Lab Date: Mon, 10 Dec 2018 15:43:10 +0100 Subject: [PATCH] new: [apache] default value for domain name is service name if this one is a domain name. --- apache/lib/common | 24 ++++++++++++++++-------- 1 file changed, 16 insertions(+), 8 deletions(-) diff --git a/apache/lib/common b/apache/lib/common index b297cca..ed89d90 100644 --- a/apache/lib/common +++ b/apache/lib/common @@ -2,11 +2,22 @@ config_hash= + +get_domain () { + relation-get domain 2>/dev/null && return 0 + + ## is service name a regex ? + if [[ "$BASE_SERVICE_NAME" =~ ^([a-z0-9]+(-[a-z0-9]+)*\.)+[a-z]{2,}$ ]]; then + echo "$BASE_SERVICE_NAME" + return 0 + fi + + err "You must specify a ${WHITE}domain$NORMAL option in relation." + return 1 +} + apache_proxy_dir () { - DOMAIN=$(relation-get domain) || { - err "You must specify a ${WHITE}domain$NORMAL option in relation." - return 1 - } + DOMAIN=$(get_domain) || return 1 proxy=yes apache_vhost_create || return 1 info "Added $DOMAIN as a proxy to $TARGET." } @@ -14,10 +25,7 @@ export -f apache_proxy_dir apache_publish_dir () { - DOMAIN=$(relation-get domain) || { - err "You must specify a ${WHITE}domain$NORMAL option in relation." - return 1 - } + DOMAIN=$(get_domain) || return 1 DOCKER_SITE_PATH="/var/www/${DOMAIN}" LOCATION=$(relation-get location 2>/dev/null) || LOCATION="$DATASTORE/$BASE_SERVICE_NAME$DOCKER_SITE_PATH"