1
0
mirror of https://github.com/zokradonh/kopano-docker synced 2025-06-07 16:06:14 +00:00

make webapp configurable from env (#112)

* make webapp configurable from env
inspired by https://github.com/mlan/docker-kopano/blob/master/assets/entrypoint.sh#L80-L92 and a7c2134347/meet/start-service.sh (L22-L27)
  * updating is in a dedicated function and has verbose error handling
* add documentation for env variables
This commit is contained in:
Felix Bartels 2019-03-18 12:45:03 +01:00 committed by GitHub
parent c8c55ae2aa
commit 4e367badc5
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 86 additions and 9 deletions

View File

@ -206,12 +206,15 @@ check-scripts:
git ls-files --exclude='Dockerfile*' --ignored | xargs --max-lines=1 hadolint
test:
docker-compose -f $(COMPOSE_FILE) down -v || true
docker-compose -f $(COMPOSE_FILE) down -v --remove-orphans || true
make build-all
docker-compose -f $(COMPOSE_FILE) build
docker-compose -f $(COMPOSE_FILE) up -d
docker-compose -f $(COMPOSE_FILE) ps
test-update-env:
docker-compose -f $(COMPOSE_FILE) up -d
test-quick:
docker-compose -f $(COMPOSE_FILE) stop || true
docker-compose -f $(COMPOSE_FILE) up -d

View File

@ -32,12 +32,53 @@ Yes, indeed. You could for example use this to easily try out newer Kopano WebAp
And last but not least this project also offers a `zokradonh/kopano_utils` image to easily run tools such as `kopano-backup`, `kopano-migration-pst`, `kopano-migration-imap` and all the other utilities that are bundles with Kopano. See [below](#some-more-commands-for-those-unfamilar-with-docker-compose) to see how to run `zokradonh/kopano_utils`.
### Need to adjust any values after the initial run of `setup.sh`?
### Additional configuration / Need to adjust any values after the initial run of `setup.sh`?
If you want to modify some of the values from the `setup.sh` run you can simply edit `.env` in your favourite editor. Repeated runs of `setup.sh` will neither modify `docker-compose.yml` nor `.env`. In the ´.env´ file you will also find some given defaults like ldap query filters and the local ports for the reverse proxy.
Additionally a dedicated env file is created for each container (at least where that would make sense). The env file has the container name as part of the file name. For example for the `kopano_server` container the filename is `kopano_server.env`. These additional env files are auto created when running `setup.sh`
Any additional configuration should be done through environment variables and not done in the actual container. The images working with configuration files (e.g. `kopano_core`, `kopano_webapp`, `kopano_meet`) have a mechanism built in to translate env variables into configuration files. For services that can directly work with env variables (e.g. `kopano_konnect`, ´kopano_kwmserver´) these can be specified directly.
Examples of env variables:
```
KCCONF_KWEBD_TLS=no
^ ^ ^ ^
| | | |
General prefix |
| | |
Name of the relevant configuration file (kwebd.cfg in this case)
| |
Name of the configuration option in the configuration file
|
Value of the configuration option
KCCONF_WEBAPP_CLIENT_TIMEOUT=3600
^ ^ ^ ^
| | | |
General prefix| |
| | |
Special value to signal the change should go into config.php belonging to WebApp
| |
Name of the configuration option in the configuration file
|
Value of the configuration option
KCCONF_WEBAPPPLUGIN_MDM_PLUGIN_MDM_USER_DEFAULT_ENABLE_MDM=true
^ ^ ^ ^ ^
| | | | |
General prefix | | |
| | | |
Special value to signal the change should go into config-$identifier.php (located in /etc/kopano/webapp)
| | |
Identifier for the configuration file (config-$identifier.php)
| |
Name of the configuration option in the configuration file
|
Value of the configuration option
```
### How to use a newer version than the one available from the Docker Hub?
In this repository you can also find a Makefile that automates the process of building newer images.

View File

@ -8,6 +8,28 @@ ADDITIONAL_KOPANO_WEBAPP_PLUGINS=${ADDITIONAL_KOPANO_WEBAPP_PLUGINS:-""}
set -eu # unset variables are errors & non-zero return values exit the whole script
php_cfg_gen() {
local cfg_file="$1"
local cfg_setting="$2"
local cfg_value="$3"
if [ -e "$cfg_file" ]; then
if grep -q "$cfg_setting" "$cfg_file"; then
echo "Setting $cfg_setting = $cfg_value in $cfg_file"
sed -ri "s#(\s*define).+${cfg_setting}.+#\define(\x27${cfg_setting}\x27, \x27${cfg_value}\x27\);#g" "$cfg_file"
else
echo "Error: Config option $cfg_setting not found in $cfg_file"
cat "$cfg_file"
exit 1
fi
else
echo "Error: Config file $cfg_file not found. Plugin not installed?"
local dir
dir=$(dirname "$cfg_file")
ls -la "$dir"
exit 1
fi
}
ADDITIONAL_KOPANO_PACKAGES="$ADDITIONAL_KOPANO_PACKAGES $ADDITIONAL_KOPANO_WEBAPP_PLUGINS"
[ -n "${ADDITIONAL_KOPANO_PACKAGES// }" ] && apt update
@ -18,22 +40,33 @@ ADDITIONAL_KOPANO_PACKAGES="$ADDITIONAL_KOPANO_PACKAGES $ADDITIONAL_KOPANO_WEBAP
fi
done
echo "Ensure directories"
# Ensure directories exist
mkdir -p /run/sessions /tmp/webapp
if [ "$KCCONF_SERVERHOSTNAME" == "127.0.0.1" ]; then
echo "Kopano WebApp is using the default: connection"
else
echo "Kopano WebApp is using an ip connection"
sed -e "s#define(\"DEFAULT_SERVER\",\s*\".*\"#define(\"DEFAULT_SERVER\", \"https://${KCCONF_SERVERHOSTNAME}:${KCCONF_SERVERPORT}/kopano\"#" \
-i /etc/kopano/webapp/config.php
php_cfg_gen /etc/kopano/webapp/config.php DEFAULT_SERVER "https://${KCCONF_SERVERHOSTNAME}:${KCCONF_SERVERPORT}/kopano"
fi
# TODO is enabling this really neccesary when reverse proxying webapp?
echo "Configuring Kopano WebApp for use behind a reverse proxy"
sed \
-e "s#define(\"INSECURE_COOKIES\",\s*.*)#define(\"INSECURE_COOKIES\", true)#" \
-i /etc/kopano/webapp/config.php
php_cfg_gen /etc/kopano/webapp/config.php INSECURE_COOKIES true
# configuring webapp from env
for setting in $(compgen -A variable KCCONF_WEBAPP_); do
setting2=${setting#KCCONF_WEBAPP_}
php_cfg_gen /etc/kopano/webapp/config.php "${setting2}" "${!setting}"
done
# configuring webapp plugins from env
for setting in $(compgen -A variable KCCONF_WEBAPPPLUGIN_); do
setting2=${setting#KCCONF_WEBAPPPLUGIN_}
filename="${setting2%%_*}"
setting3=${setting#KCCONF_WEBAPPPLUGIN_${filename}_}
identifier="${filename,,}"
php_cfg_gen /etc/kopano/webapp/config-"$identifier".php "${setting3}" "${!setting}"
done
echo "Ensure config ownership"
chown -R www-data:www-data /run/sessions /tmp/webapp