removal: configomat (submodule) (#3045)

This commit is contained in:
Georg Lauterbach 2023-02-05 12:39:05 +01:00 committed by GitHub
parent 9df71c27a0
commit 00b1d88ed7
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
11 changed files with 114 additions and 17 deletions

View file

@ -30,7 +30,7 @@ trim_trailing_whitespace = false
# --- Git Submodules ----------------------------
# -----------------------------------------------
[{test/bats/**,test/test_helper/**,target/docker-configomat/**}]
[{test/bats/**,test/test_helper/**}]
indent_style = none
indent_size = none
end_of_line = none

3
.gitmodules vendored
View file

@ -7,6 +7,3 @@
[submodule "test/test_helper/bats-assert"]
path = test/test_helper/bats-assert
url = https://github.com/bats-core/bats-assert
[submodule "target/docker-configomat"]
path = target/docker-configomat
url = https://github.com/alinmear/docker-configomat

View file

@ -253,7 +253,6 @@ COPY \
target/scripts/*.sh \
target/scripts/startup/*.sh \
target/scripts/wrapper/*.sh \
target/docker-configomat/configomat.sh \
/usr/local/bin/
RUN chmod +x /usr/local/bin/*

View file

@ -19,12 +19,6 @@ Or, you can clone and retrieve the submodules in one command:
git clone --recurse-submodules https://github.com/docker-mailserver/docker-mailserver
```
Retrieving the git submodules will fix the error:
```txt
COPY failed: file not found in build context or excluded by .dockerignore: stat target/docker-configomat/configomat.sh: file does not exist
```
### About Docker
#### Version

@ -1 +0,0 @@
Subproject commit 415550485438d7e6ca6136016cca4bbab99ccf6f

View file

@ -63,3 +63,54 @@ function _reload_postfix
_adjust_mtime_for_postfix_maincf
postfix reload
}
# Replaces values in configuration files given a set of specific environment
# variables. The environment variables follow a naming pattern, whereby every
# variable that is taken into account has a given prefix. The new value in the
# configuration will be the one the environment variable had at the time of
# calling this function.
#
# @option --shutdown-on-error = shutdown in case an error is detected
# @param ${1} = prefix for environment variables
# @param ${2} = file in which substitutions should take place
#
# ## Example
#
# If you want to set a new value for `readme_directory` in Postfix's `main.cf`,
# you can set the environment variable `POSTFIX_README_DIRECTORY='/new/dir/'`
# (`POSTFIX_` is an arbitrary prefix, you can choose the one you like),
# and then call this function:
# `_replace_by_env_in_file 'POSTFIX_' 'PATH TO POSTFIX's main.cf>`
#
# ## Panics
#
# This function will panic, i.e. shut down the whole container, if:
#
# 1. No first and second argument is supplied
# 2. The second argument is a path to a file that does not exist
function _replace_by_env_in_file
{
if [[ -z ${1+set} ]]
then
dms_panic__invalid_value 'first argument unset' 'utils.sh:_replace_by_env_in_file'
elif [[ -z ${2+set} ]]
then
dms_panic__invalid_value 'second argument unset' 'utils.sh:_replace_by_env_in_file'
elif [[ ! -f ${2} ]]
then
dms_panic__invalid_value "file '${2}' does not exist" 'utils.sh:_replace_by_env_in_file'
fi
local ENV_PREFIX=${1} CONFIG_FILE=${2}
local ESCAPED_VALUE ESCAPED_KEY
while IFS='=' read -r KEY VALUE
do
KEY=${KEY#"${ENV_PREFIX}"} # strip prefix
ESCAPED_KEY=$(sed -E 's#([\=\&\|\$\.\*\/\[\\^]|\])#\\\1#g' <<< "${KEY,,}")
ESCAPED_VALUE=$(sed -E 's#([\=\&\|\$\.\*\/\[\\^]|\])#\\\1#g' <<< "${VALUE}")
[[ -n ${ESCAPED_VALUE} ]] && ESCAPED_VALUE=" ${ESCAPED_VALUE}"
_log 'trace' "Setting value of '${KEY}' in '${CONFIG_FILE}' to '${VALUE}'"
sed -i -E "s#^${ESCAPED_KEY}[[:space:]]*=.*#${ESCAPED_KEY} =${ESCAPED_VALUE}#g" "${CONFIG_FILE}"
done < <(env | grep "^${ENV_PREFIX}")
}

View file

@ -380,7 +380,7 @@ function _setup_ldap
[[ ${FILE} =~ ldap-aliases ]] && export LDAP_QUERY_FILTER="${LDAP_QUERY_FILTER_ALIAS}"
[[ ${FILE} =~ ldap-domains ]] && export LDAP_QUERY_FILTER="${LDAP_QUERY_FILTER_DOMAIN}"
[[ ${FILE} =~ ldap-senders ]] && export LDAP_QUERY_FILTER="${LDAP_QUERY_FILTER_SENDERS}"
_log debug "$(configomat.sh "LDAP_" "${FILE}" 2>&1)"
[[ -f ${FILE} ]] && _replace_by_env_in_file 'LDAP_' "${FILE}"
done
_log 'trace' "Configuring Dovecot LDAP"
@ -407,7 +407,7 @@ function _setup_ldap
export "${VAR}=${DOVECOT_LDAP_MAPPING[${VAR}]}"
done
_log debug "$(configomat.sh "DOVECOT_" "/etc/dovecot/dovecot-ldap.conf.ext" 2>&1)"
_replace_by_env_in_file 'DOVECOT_' '/etc/dovecot/dovecot-ldap.conf.ext'
_log 'trace' 'Enabling Dovecot LDAP authentication'

View file

@ -0,0 +1,6 @@
key_1 = value
key_2 =
key_3 =value
key_4= value
key_5=value
key_6 = value

View file

@ -51,8 +51,7 @@ function _shellcheck
# File paths for shellcheck:
F_SH=$(find . -type f -iname '*.sh' \
-not -path './test/bats/*' \
-not -path './test/test_helper/*' \
-not -path './target/docker-configomat/*'
-not -path './test/test_helper/*'
)
# shellcheck disable=SC2248
F_BIN=$(find 'target/bin' -type f -not -name '*.py')

View file

@ -0,0 +1,52 @@
load "${REPOSITORY_ROOT}/test/helper/common"
source "${REPOSITORY_ROOT}/target/scripts/helpers/log.sh"
source "${REPOSITORY_ROOT}/target/scripts/helpers/utils.sh"
BATS_TEST_NAME_PREFIX='[Helper function] (_replace_by_env_in_file) '
function setup_file() {
export TMP_CONFIG_FILE=$(mktemp)
cp "${REPOSITORY_ROOT}/test/config/override-configs/replace_by_env_in_file.conf" "${TMP_CONFIG_FILE}"
}
function teardown_file() { rm "${TMP_CONFIG_FILE}" ; }
@test "substitute key-value pair (01) (normal substitutions)" {
export TEST_KEY_1='new_value_1'
_do_work "key_1 = ${TEST_KEY_1}"
export TEST_KEY_1='(&(objectClass=PostfixBookMailAccount)(|(uniqueIdentifier=%n)(mail=%u)))'
_do_work "key_1 = ${TEST_KEY_1}"
export TEST_KEY_1="*+=/_-%&"
_do_work "key_1 = ${TEST_KEY_1}"
export TEST_KEY_1='(&(objectClass=mailAccount)(uid=%n))'
_do_work "key_1 = ${TEST_KEY_1}"
export TEST_KEY_1='=home=/var/mail/%{ldap:mail}, =mail=maildir:/var/mail/%{ldap:mail}/Maildir'
_do_work "key_1 = ${TEST_KEY_1}"
export TEST_KEY_1='(&(objectClass=mailAccount)(uid=%n))'
_do_work "key_1 = ${TEST_KEY_1}"
export TEST_KEY_1='uid=user,userPassword=password'
_do_work "key_1 = ${TEST_KEY_1}"
}
@test "substitute key-value pair (08) (spaces / no values)" {
export TEST_KEY_2='new_value_2'
_do_work "key_2 = ${TEST_KEY_2}"
export TEST_KEY_3='new_value_3'
_do_work "key_3 = ${TEST_KEY_3}"
export TEST_KEY_4="new_value_4"
_do_work "key_4 = ${TEST_KEY_4}"
export TEST_KEY_5="new_value_5"
_do_work "key_5 = ${TEST_KEY_5}"
export TEST_KEY_6=
_do_work "key_6 ="
run grep -q -F "key_6 = " "${TMP_CONFIG_FILE}"
assert_failure
}
function _do_work() {
local FILTER_STRING=${1:?No string to filter by was provided}
run _replace_by_env_in_file 'TEST_' "${TMP_CONFIG_FILE}"
assert_success
run grep -q -F "${FILTER_STRING}" "${TMP_CONFIG_FILE}"
assert_success
}

View file

@ -23,7 +23,7 @@ function setup_file() {
--tty \
ldap # Image name
# _setup_ldap uses configomat with .ext files and ENV vars like DOVECOT_TLS with a prefix (eg DOVECOT_ or LDAP_)
# _setup_ldap uses _replace_by_env_in_file with ENV vars like DOVECOT_TLS with a prefix (eg. DOVECOT_ or LDAP_)
local PRIVATE_CONFIG
PRIVATE_CONFIG=$(duplicate_config_for_container .)
docker run -d --name mail_with_ldap \