From a444d16bd691e406f838d2bcb00cf29fc44c6cb7 Mon Sep 17 00:00:00 2001 From: Valentin Lab Date: Wed, 20 Feb 2019 12:03:29 +0100 Subject: [PATCH] new: dev: [apache] store a ``url`` argument instead of a ``protocol`` argument. --- apache/lib/common | 16 ++++----- apache/test/vhost_files | 34 ++++++++++--------- .../hooks/web_proxy-relation-joined | 7 ++-- .../hooks/web_proxy-relation-joined | 8 ++--- drone/hooks/web_proxy-relation-joined | 8 ++--- gitea/hooks/web_proxy-relation-joined | 5 ++- 6 files changed, 37 insertions(+), 41 deletions(-) diff --git a/apache/lib/common b/apache/lib/common index ea727c4..3bf0109 100644 --- a/apache/lib/common +++ b/apache/lib/common @@ -78,6 +78,10 @@ apache_vhost_create() { } if is_protocol_enabled https "$protocols"; then + [ "$RELATION_DATA_FILE" ] && { + relation-set url "https://$domain" + } + if [ -z "$domain" ]; then err "You must specify a domain for ssl to work." return 1 @@ -109,17 +113,11 @@ $(if [ "$custom_rules" ]; then echo "- |"$'\n'"$(echo "$custom_rules" | prefix " ")" fi)")") || return 1 fi - [ "$RELATION_DATA_FILE" ] && \ - relation-set protocol https - else - ## Both services are available and different, don't do anything then ? - #[ "$RELATION_DATA_FILE" ] && \ - # relation-set protocol https - : fi else - [ "$RELATION_DATA_FILE" ] && \ - relation-set protocol http + [ "$RELATION_DATA_FILE" ] && { + relation-set url "http://$domain" + } fi vhost_statement=$(apache_vhost_statement "$type" "$protocols" "$cfg" "$domain") || { err "Failed to get vhost statement for type $type on ${protocols:1:-1}" diff --git a/apache/test/vhost_files b/apache/test/vhost_files index fa470b4..3a2884b 100644 --- a/apache/test/vhost_files +++ b/apache/test/vhost_files @@ -145,8 +145,8 @@ domain: www.example.com '" is errlvl 0 is err part "\ -relation-set protocol: - | http" +relation-set url: + | http://www.example.com" is out reg '^file_put \$SERVICE_CONFIGSTORE/.*/www.example.com.conf' try " @@ -172,8 +172,8 @@ apache_vhost_create publish_dir \"\$CFG\" is errlvl 0 is err part "## Auto-redirection from http to https" is err part "\ -relation-set protocol: - | https" +relation-set url: + | https://www.example.com" is out reg '^file_put \$SERVICE_CONFIGSTORE/.*/www.example.com.conf' @@ -207,8 +207,8 @@ apache_vhost_create publish_dir \"\$CFG\" is errlvl 0 is err part "## Auto-redirection from http to https" is err part "\ -relation-set protocol: - | https" +relation-set url: + | https://www.example.com" is out part 'file_put $CONFIGSTORE/$BASE_SERVICE_NAME/etc/ssl/certs/www.example.com.pem | c' is out part 'file_put $CONFIGSTORE/$BASE_SERVICE_NAME/etc/ssl/private/www.example.com.key @@ -234,19 +234,21 @@ apache_vhost_create publish_dir \"\$CFG\" " is errlvl 0 is err part "\ -relation-set protocol: - | http" +relation-set url: + | http://www.example.com" is out reg "htpasswd -bc '/etc/apache2/sites-enabled/www.example.com.passwd' 'toto' 'xxx'" is out reg 'docker run -i --entrypoint /bin/bash .* docker/apache' -try " -export SERVICE_CONFIGSTORE='\$SERVICE_CONFIGSTORE' -apache_vhost_create publish_dir '' ',http,' '000-default'" -is errlvl 0 -is err part "\ -relation-set protocol: - | http" -is out reg '^file_put \$SERVICE_CONFIGSTORE/.*/000-default.conf' + +## XXXvlab: we don't need this feature anymore it seems +# try " +# export SERVICE_CONFIGSTORE='\$SERVICE_CONFIGSTORE' +# apache_vhost_create publish_dir '' ',http,' '000-default'" +# is errlvl 0 +# is err part "\ +# relation-set url: +# | http://" ## XXXvlab: this isn't right, is it ? +# is out reg '^file_put \$SERVICE_CONFIGSTORE/.*/000-default.conf' diff --git a/docker-registry-auth/hooks/web_proxy-relation-joined b/docker-registry-auth/hooks/web_proxy-relation-joined index e5c9ddc..58d55d2 100755 --- a/docker-registry-auth/hooks/web_proxy-relation-joined +++ b/docker-registry-auth/hooks/web_proxy-relation-joined @@ -4,9 +4,6 @@ set -e . lib/common -DOMAIN=$(relation-get domain) || exit 1 -PROTO=$(relation-get protocol) || true -PROTO=${PROTO:-https} +URL=$(relation-get url) || return 1 - -echo "$PROTO://$DOMAIN" > $SERVICE_CONFIGSTORE/etc/docker-auth/realm \ No newline at end of file +echo "$URL" > $SERVICE_CONFIGSTORE/etc/docker-auth/realm \ No newline at end of file diff --git a/docker-registry/hooks/web_proxy-relation-joined b/docker-registry/hooks/web_proxy-relation-joined index 1dd3672..b1da899 100755 --- a/docker-registry/hooks/web_proxy-relation-joined +++ b/docker-registry/hooks/web_proxy-relation-joined @@ -5,18 +5,18 @@ set -e . lib/common DOMAIN=$(relation-get domain) || exit 1 -PROTO=$(relation-get protocol) || true -PROTO=${PROTO:-https} ## These are mainly to setup the correct web-hook if [ "$MASTER_BASE_SERVICE_NAME" == "$DOMAIN" ]; then ## This is because the IP will be the docker container version - PROTO=http + URL="http://$DOMAIN" +else + URL="$(relation-get url)" || exit 1 fi ini_merge <