1
0
mirror of https://github.com/zokradonh/kopano-docker.git synced 2026-08-21 21:33:02 +00:00

make docker-compose easier to use (also by introducing variables and a setup script)

update Dockerfiles/Makefile for use with kopano supported build
introduce a local ldap image with some demo users
include caddy for reverse proxying
add proper documentation and remove obsolete build and push scripts

Signed-off-by: Felix Bartels <felix@host-consultants.de>
This commit is contained in:
Felix Bartels
2018-10-17 08:46:58 +02:00
parent f82bcfed03
commit 4728072dd5
26 changed files with 27631 additions and 789 deletions
+7 -5
View File
@@ -1,4 +1,5 @@
FROM zokradonh/kopano_base
ARG docker_repo=zokradonh
FROM ${docker_repo}/kopano_base
ARG ADDITIONAL_KOPANO_PACKAGES=""
ARG DOWNLOAD_COMMUNITY_PACKAGES=1
@@ -15,10 +16,8 @@ RUN \
dl_and_package_community "core"; \
fi; \
echo "deb [${KOPANO_REPOSITORY_FLAGS}] ${KOPANO_CORE_REPOSITORY_URL} ./" > /etc/apt/sources.list.d/kopano.list; \
# save kopano version if supported kopano
if [ ! -f /kopano/buildversion ]; then \
echo "core-${KOPANO_CORE_VERSION}" > /kopano/buildversion; \
fi; \
# save kopano version
echo "core-${KOPANO_CORE_VERSION}" > /kopano/buildversion; \
# install apt key if supported kopano
if [ ${RELEASE_KEY_DOWNLOAD} -eq 1 ]; then \
curl -s -S -o - "${KOPANO_CORE_REPOSITORY_URL}/Release.key" | apt-key add -; \
@@ -47,3 +46,6 @@ COPY kcconf.py defaultconfigs/ start-service.sh /kopano/
ENTRYPOINT ["/usr/bin/dumb-init", "--"]
CMD [ "/kopano/start-service.sh" ]
HEALTHCHECK --interval=30s --timeout=60s \
CMD /kopano/healthcheck.sh
+1 -1
View File
@@ -9,7 +9,7 @@ kcconf.configkopano({
'log_level': "3",
'attachment_path': "/kopano/data/attachments/",
'user_plugin': "ldap",
'server_listen': "",
'server_listen': "*:236",
'server_listen_tls': "*:237"
}
})
+5
View File
@@ -0,0 +1,5 @@
#!/bin/bash
set -ex
exit 0
+77 -77
View File
@@ -1,77 +1,77 @@
"""This module provides functions for easy editing of kopano config files
via environment variables"""
import re
import os
import os.path
def configkopano(configs):
""" Changes configuration files according to configs typically returned from parseenvironmentvariables(..)"""
for filename, config in configs.items():
if not os.path.exists(filename):
return
# read configuration file
with open(filename) as f:
contents = f.read()
f.close()
for key, newvalue in config.items():
if key == "kccomment":
# comment lines
for line in newvalue:
contents = re.sub(r"^\s*" + re.escape(line), r"#{}".format(line), contents, 0, re.MULTILINE)
elif key == "kcuncomment":
# uncomment lines
for line in newvalue:
contents = re.sub(r"^\s*#\s*" + re.escape(line) , line, contents, 0, re.MULTILINE)
else:
# find config line
if re.search(r"^\s*#?\s*{}\s*=.*".format(key), contents, re.MULTILINE) == None:
# add configuration as new line
contents += "\n{} = {}".format(key, newvalue)
else:
# change existing line
contents = re.sub(r"^\s*#?\s*{}\s*=.*".format(key), r"{} = {}".format(key, newvalue), contents, 0, re.MULTILINE)
# save new configuration
with open(filename, "w") as f:
f.write(contents)
f.close()
def parseenvironmentvariables(prependingpath):
""" Parse all environment variables starting with KCCONF_, KCCOMMENT_ and KCUNCOMMENT_ and
return as multi dimensional dict """
configs = dict()
for name, value in os.environ.items():
# parse change/add configuration commands
namematch = re.match(r"^KCCONF_([A-Z]+)_([A-Z0-9_]+)$", name)
if namematch != None:
filename = namematch.group(1).lower() + ".cfg"
if prependingpath + filename not in configs:
configs[prependingpath + filename] = dict()
confkey = namematch.group(2).lower()
configs[prependingpath + filename][confkey] = value
# parse comment configuration commands
commentmatch = re.match(r"^KCCOMMENT_([A-Z]+)_([A-Z0-9_]+)$", name)
if commentmatch != None:
filename = commentmatch.group(1).lower() + ".cfg"
if prependingpath + filename not in configs:
configs[prependingpath + filename] = dict()
try:
configs[prependingpath + filename]["kccomment"].append(value)
except KeyError:
configs[prependingpath + filename]["kccomment"] = []
configs[prependingpath + filename]["kccomment"].append(value)
# parse uncomment configuration commands
uncommentmatch = re.match(r"^KCUNCOMMENT_([A-Z]+)_([A-Z0-9_]+)$", name)
if uncommentmatch != None:
filename = uncommentmatch.group(1).lower() + ".cfg"
if prependingpath + filename not in configs:
configs[prependingpath + filename] = dict()
try:
configs[prependingpath + filename]["kcuncomment"].append(value)
except KeyError:
configs[prependingpath + filename]["kcuncomment"] = []
configs[prependingpath + filename]["kcuncomment"].append(value)
return configs
"""This module provides functions for easy editing of kopano config files
via environment variables"""
import re
import os
import os.path
def configkopano(configs):
""" Changes configuration files according to configs typically returned from parseenvironmentvariables(..)"""
for filename, config in configs.items():
if not os.path.exists(filename):
return
# read configuration file
with open(filename) as f:
contents = f.read()
f.close()
for key, newvalue in config.items():
if key == "kccomment":
# comment lines
for line in newvalue:
contents = re.sub(r"^\s*" + re.escape(line), r"#{}".format(line), contents, 0, re.MULTILINE)
elif key == "kcuncomment":
# uncomment lines
for line in newvalue:
contents = re.sub(r"^\s*#\s*" + re.escape(line) , line, contents, 0, re.MULTILINE)
else:
# find config line
if re.search(r"^\s*#?\s*{}\s*=.*".format(key), contents, re.MULTILINE) == None:
# add configuration as new line
contents += "\n{} = {}".format(key, newvalue)
else:
# change existing line
contents = re.sub(r"^\s*#?\s*{}\s*=.*".format(key), r"{} = {}".format(key, newvalue), contents, 0, re.MULTILINE)
# save new configuration
with open(filename, "w") as f:
f.write(contents)
f.close()
def parseenvironmentvariables(prependingpath):
""" Parse all environment variables starting with KCCONF_, KCCOMMENT_ and KCUNCOMMENT_ and
return as multi dimensional dict """
configs = dict()
for name, value in os.environ.items():
# parse change/add configuration commands
namematch = re.match(r"^KCCONF_([A-Z]+)_([A-Z0-9_]+)$", name)
if namematch != None:
filename = namematch.group(1).lower() + ".cfg"
if prependingpath + filename not in configs:
configs[prependingpath + filename] = dict()
confkey = namematch.group(2).lower()
configs[prependingpath + filename][confkey] = value
# parse comment configuration commands
commentmatch = re.match(r"^KCCOMMENT_([A-Z]+)_([A-Z0-9_]+)$", name)
if commentmatch != None:
filename = commentmatch.group(1).lower() + ".cfg"
if prependingpath + filename not in configs:
configs[prependingpath + filename] = dict()
try:
configs[prependingpath + filename]["kccomment"].append(value)
except KeyError:
configs[prependingpath + filename]["kccomment"] = []
configs[prependingpath + filename]["kccomment"].append(value)
# parse uncomment configuration commands
uncommentmatch = re.match(r"^KCUNCOMMENT_([A-Z]+)_([A-Z0-9_]+)$", name)
if uncommentmatch != None:
filename = uncommentmatch.group(1).lower() + ".cfg"
if prependingpath + filename not in configs:
configs[prependingpath + filename] = dict()
try:
configs[prependingpath + filename]["kcuncomment"].append(value)
except KeyError:
configs[prependingpath + filename]["kcuncomment"] = []
configs[prependingpath + filename]["kcuncomment"].append(value)
return configs
+57 -27
View File
@@ -1,5 +1,7 @@
#!/bin/bash
ADDITIONAL_KOPANO_PACKAGES=${ADDITIONAL_KOPANO_PACKAGES:-""}
set -eu # unset variables are errors & non-zero return values exit the whole script
if [ ! -e /kopano/$SERVICE_TO_START.py ]
@@ -8,6 +10,13 @@ then
exit 1
fi
[ ! -z "$ADDITIONAL_KOPANO_PACKAGES" ] && apt update
[ ! -z "$ADDITIONAL_KOPANO_PACKAGES" ] && for installpkg in "$ADDITIONAL_KOPANO_PACKAGES"; do
if [ $(dpkg-query -W -f='${Status}' $installpkg 2>/dev/null | grep -c "ok installed") -eq 0 ]; then
apt --assume-yes install $installpkg;
fi
done
mkdir -p /kopano/data/attachments /tmp/$SERVICE_TO_START /var/run/kopano
echo "Configure core service '$SERVICE_TO_START'" | ts
@@ -17,9 +26,6 @@ echo "Set ownership" | ts
chown -R kopano:kopano /run /tmp
chown kopano:kopano /kopano/data/ /kopano/data/attachments
echo "Clean old pid files and sockets" | ts
rm -f /var/run/kopano/*
# allow helper commands given by "docker-compose run"
if [ $# -gt 0 ]
then
@@ -29,28 +35,52 @@ fi
# start regular service
case "$SERVICE_TO_START" in
server)
exec /usr/sbin/kopano-server -F
;;
dagent)
exec /usr/sbin/kopano-dagent -l
;;
gateway)
exec /usr/sbin/kopano-gateway -F
;;
ical)
exec /usr/sbin/kopano-ical -F
;;
monitor)
exec /usr/sbin/kopano-monitor -F
;;
search)
exec /usr/bin/python /usr/sbin/kopano-search -F
;;
spooler)
exec /usr/sbin/kopano-spooler -F
;;
*)
echo "Failed to start: Unknown service name: '$SERVICE_TO_START'" | ts
exit 1
server)
exec dockerize \
-wait file://$KCCONF_SERVER_SERVER_SSL_CA_FILE \
-wait file://$KCCONF_SERVER_SERVER_SSL_KEY_FILE \
-wait tcp://db:3306 \
-timeout 360s \
/usr/sbin/kopano-server -F
;;
dagent)
exec dockerize \
-wait file://var/run/kopano/server.sock \
-timeout 360s \
/usr/sbin/kopano-dagent -l
;;
gateway)
exec dockerize \
-wait tcp://kserver:236 \
-timeout 360s \
/usr/sbin/kopano-gateway -F
;;
ical)
exec dockerize \
-wait tcp://kserver:236 \
-timeout 360s \
/usr/sbin/kopano-ical -F
;;
monitor)
exec dockerize \
-wait file://var/run/kopano/server.sock \
-timeout 360s \
/usr/sbin/kopano-monitor -F
;;
search)
exec dockerize \
-wait file://var/run/kopano/server.sock \
-timeout 360s \
/usr/bin/python /usr/sbin/kopano-search -F
;;
spooler)
exec dockerize \
-wait file://var/run/kopano/server.sock \
-wait tcp://mail:25 \
-timeout 1080s \
/usr/sbin/kopano-spooler -F
;;
*)
echo "Failed to start: Unknown service name: '$SERVICE_TO_START'" | ts
exit 1
esac