From b17b4db0c73a51cd7085e723c3e60301f932dda4 Mon Sep 17 00:00:00 2001 From: Valentin Lab Date: Thu, 14 Feb 2019 11:57:40 +0100 Subject: [PATCH] new: dev: [apache] use only ``init-config-add``. --- apache/lib/common | 42 ++++++++++++++++----------------- apache/test/vhost_cert_provider | 28 ++++++++++++---------- apache/test/vhost_files | 26 +++++++++++++++++--- 3 files changed, 60 insertions(+), 36 deletions(-) diff --git a/apache/lib/common b/apache/lib/common index 0204f9d..4d2c67d 100644 --- a/apache/lib/common +++ b/apache/lib/common @@ -323,15 +323,14 @@ ssl_fallback_prepare() { echo "$content" | file_put "$dst$location" config_hash=$(printf "%s\0" "$config_hash" "$label" "$content" | md5_compat) volumes="$volumes - - $dst$location:$location:ro" + - $dst$location:$location:ro" fi done if [ "$volumes" ]; then - config-add "\ -services: - $MASTER_TARGET_SERVICE_NAME: - volumes: + init-config-add "\ +$MASTER_TARGET_SERVICE_NAME: + volumes: $volumes " fi @@ -365,11 +364,10 @@ ssl_plugin_cert-provider_prepare() { err "Failed to launch letsencrypt for certificate creation." return 1 } - config-add "\ -services: - $MASTER_TARGET_SERVICE_NAME: - volumes: - - $DATASTORE/$service/etc/letsencrypt:/etc/letsencrypt:ro + init-config-add "\ +$SERVICE_NAME: + volumes: + - $DATASTORE/$service/etc/letsencrypt:/etc/letsencrypt:ro " || return 1 } @@ -437,8 +435,8 @@ apache_code_dir() { setfacl -R -m g:"$www_data_gid":rx "$host_path" info "Set permission for read and traversal on '$host_path'." - config-add " -$MASTER_BASE_SERVICE_NAME: + init-config-add " +$SERVICE_NAME: volumes: - $host_path:$local_path " @@ -475,8 +473,8 @@ apache_data_dirs() { setfacl -R -m g:"$www_data_gid":rwx "${dirs[@]}" setfacl -R -d -m g:"$www_data_gid":rwx "${dirs[@]}" - config-add " -$MASTER_BASE_SERVICE_NAME: + init-config-add " +$SERVICE_NAME: volumes: $( for d in "${data[@]}"; do @@ -502,14 +500,14 @@ export -f deploy_files apache_core_rules_add() { - local conf="$1" dst="/etc/apache2/conf-enabled/$BASE_SERVICE_NAME.conf" + local conf="$1" dst="/etc/apache2/conf-enabled/$SERVICE_NAME.conf" debug "Adding core rule." - echo "$conf" | file_put "$CONFIGSTORE/$BASE_SERVICE_NAME$dst" + echo "$conf" | file_put "$CONFIGSTORE/$SERVICE_NAME$dst" config_hash=$(printf "%s\0" "$config_hash" "$conf" | md5_compat) - config-add " -$MASTER_BASE_SERVICE_NAME: + init-config-add " +$SERVICE_NAME: volumes: - - $CONFIGSTORE/$BASE_SERVICE_NAME$dst:$dst:ro + - $CONFIGSTORE/$SERVICE_NAME$dst:$dst:ro " } @@ -851,8 +849,10 @@ apache_config_hash() { -name \*.conf -exec md5sum {} \; } | md5_compat) || exit 1 init-config-add " -$MASTER_BASE_SERVICE_NAME: +$SERVICE_NAME: labels: - - compose.config_hash=$config_hash + - compose.config_hash=$config_hash " } + + diff --git a/apache/test/vhost_cert_provider b/apache/test/vhost_cert_provider index 69a7af0..a024cdc 100644 --- a/apache/test/vhost_cert_provider +++ b/apache/test/vhost_cert_provider @@ -104,6 +104,12 @@ config-add() { } export -f config-add +init-config-add() { + echo "config-add" + echo "$1" | prefix " | " +} +export -f init-config-add + mkdir() { echo "called: $FUNCNAME $@" >&2 } @@ -165,6 +171,7 @@ try " export SERVICE_CONFIGSTORE='\$SERVICE_CONFIGSTORE' export CONFIGSTORE='\$CONFIGSTORE' export DATASTORE='\$DATASTORE' +export SERVICE_NAME='\$SERVICE_NAME' export BASE_SERVICE_NAME='\$BASE_SERVICE_NAME' export MASTER_TARGET_SERVICE_NAME='\$MASTER_TARGET_SERVICE_NAME' CFG=' @@ -198,10 +205,9 @@ relation-set apache-custom-rules: |" is out reg 'Calling: compose .*foo: options: .*run --rm --service-ports foo.*' is out part 'config-add - | services: - | $MASTER_TARGET_SERVICE_NAME: - | volumes: - | - $DATASTORE/foo/etc/letsencrypt:/etc/letsencrypt:ro' + | $SERVICE_NAME: + | volumes: + | - $DATASTORE/foo/etc/letsencrypt:/etc/letsencrypt:ro' is out part ' | ## Auto-redirection from http to https | RewriteEngine On @@ -251,10 +257,9 @@ relation-set apache-custom-rules: is out reg 'Calling: compose .*foo: options: .*run --rm --service-ports foo crt create www.example.com\s* ' RTRIM is out part 'config-add - | services: - | $MASTER_TARGET_SERVICE_NAME: - | volumes: - | - $DATASTORE/foo/etc/letsencrypt:/etc/letsencrypt:ro' + | $SERVICE_NAME: + | volumes: + | - $DATASTORE/foo/etc/letsencrypt:/etc/letsencrypt:ro' is out part 'file_put $SERVICE_CONFIGSTORE/etc/apache2/sites-enabled/www.example.com.conf | | @@ -313,10 +318,9 @@ relation-set apache-custom-rules: is out reg 'Calling: compose .*foo: options: .*run --rm --service-ports foo crt create www.example.com example.fr example.de\s+ ' is out part 'config-add - | services: - | $MASTER_TARGET_SERVICE_NAME: - | volumes: - | - $DATASTORE/foo/etc/letsencrypt:/etc/letsencrypt:ro' + | $SERVICE_NAME: + | volumes: + | - $DATASTORE/foo/etc/letsencrypt:/etc/letsencrypt:ro' is out part 'file_put $SERVICE_CONFIGSTORE/etc/apache2/sites-enabled/www.example.com.conf | | diff --git a/apache/test/vhost_files b/apache/test/vhost_files index 4d268ac..fa470b4 100644 --- a/apache/test/vhost_files +++ b/apache/test/vhost_files @@ -60,6 +60,12 @@ config-add() { } export -f config-add +init-config-add() { + echo "init-config-add" + echo "$1" | prefix " | " +} +export -f init-config-add + mkdir() { echo "called: $FUNCNAME $@" >&2 } @@ -208,7 +214,7 @@ is out part 'file_put $CONFIGSTORE/$BASE_SERVICE_NAME/etc/ssl/certs/www.example. is out part 'file_put $CONFIGSTORE/$BASE_SERVICE_NAME/etc/ssl/private/www.example.com.key | a | b' -is out reg 'config-add' +is out reg 'init-config-add' is out reg ' - \$CONFIGSTORE/\$BASE_SERVICE_NAME/etc/ssl/certs/www.example.com.pem:/etc/ssl/certs/www.example.com.pem:ro' is out reg ' - \$CONFIGSTORE/\$BASE_SERVICE_NAME/etc/ssl/private/www.example.com.key:/etc/ssl/private/www.example.com.key:ro' @@ -233,6 +239,16 @@ relation-set protocol: 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' + + ## ## apache_publish_dir @@ -296,6 +312,7 @@ export DATASTORE='\$DATASTORE' export DOCKER_BASE_IMAGE=docker/apache export SERVICE_CONFIGSTORE='\$SERVICE_CONFIGSTORE' export CONFIGSTORE='\$CONFIGSTORE' +export SERVICE_NAME='\$SERVICE_NAME' export BASE_SERVICE_NAME='\$BASE_SERVICE_NAME' export MASTER_BASE_SERVICE_NAME='\$MASTER_BASE_SERVICE_NAME' export MASTER_TARGET_SERVICE_NAME='\$MASTER_TARGET_SERVICE_NAME' @@ -313,9 +330,12 @@ data-dirs: is errlvl 0 is err reg 'mkdir -p /opt/apps/newlocation' is err reg 'setfacl -R -m g::rx /opt/apps/newlocation' -is out part ' | $MASTER_BASE_SERVICE_NAME: +is out part ' +init-config-add + | + | $SERVICE_NAME: | volumes: - | - /opt/apps/newlocation:/var/www/www.example.com' + | - /opt/apps/newlocation:/var/www/www.example.com' RTRIM