From 9b10e938cf5fd46dcafe25ed1c16237a3ebe4156 Mon Sep 17 00:00:00 2001 From: Michael Wyraz Date: Tue, 19 Nov 2019 12:22:09 +0100 Subject: [PATCH 1/8] Make roundcube db configurable --- webmails/roundcube/config.inc.php | 2 +- webmails/roundcube/start.py | 23 +++++++++++++++++++++++ 2 files changed, 24 insertions(+), 1 deletion(-) diff --git a/webmails/roundcube/config.inc.php b/webmails/roundcube/config.inc.php index eff8ffa2..09a743d7 100644 --- a/webmails/roundcube/config.inc.php +++ b/webmails/roundcube/config.inc.php @@ -3,7 +3,7 @@ $config = array(); // Generals -$config['db_dsnw'] = 'sqlite:////data/roundcube.db'; +$config['db_dsnw'] = getenv('DB_DSNW');; $config['temp_dir'] = '/tmp/'; $config['des_key'] = getenv('SECRET_KEY'); $config['cipher_method'] = 'AES-256-CBC'; diff --git a/webmails/roundcube/start.py b/webmails/roundcube/start.py index 55832dd0..7851921a 100755 --- a/webmails/roundcube/start.py +++ b/webmails/roundcube/start.py @@ -9,6 +9,29 @@ log.basicConfig(stream=sys.stderr, level=os.environ.get("LOG_LEVEL", "WARNING")) os.environ["MAX_FILESIZE"] = str(int(int(os.environ.get("MESSAGE_SIZE_LIMIT"))*0.66/1048576)) +db_flavor=os.environ.get("ROUNDCUBE_DB_FLAVOR","sqlite") +if db_flavor=="sqlite": + os.environ["DB_DSNW"]="sqlite:////data/roundcube.db" +elif db_flavor=="mysql": + os.environ["DB_DSNW"]="mysql://%s:%s@%s/%s" % ( + os.environ.get("ROUNDCUBE_DB_USER","roundcube"), + os.environ.get("ROUNDCUBE_DB_PW"), + os.environ.get("ROUNDCUBE_DB_HOST","database"), + os.environ.get("ROUNDCUBE_DB_NAME","roundcube") + ) +elif db_flavor=="postgresql": + os.environ["DB_DSNW"]="pgsql://%s:%s@%s/%s" % ( + os.environ.get("ROUNDCUBE_DB_USER","roundcube"), + os.environ.get("ROUNDCUBE_DB_PW"), + os.environ.get("ROUNDCUBE_DB_HOST","database"), + os.environ.get("ROUNDCUBE_DB_NAME","roundcube") + ) +else: + print("Unknown ROUNDCUBE_DB_FLAVOR: %s",db_flavor) + exit(1) + + + conf.jinja("/php.ini", os.environ, "/usr/local/etc/php/conf.d/roundcube.ini") # Fix some permissions From 06926561e238b4a8d81c106e073b87dfb4563191 Mon Sep 17 00:00:00 2001 From: Michael Wyraz Date: Thu, 21 Nov 2019 13:32:45 +0100 Subject: [PATCH 2/8] Install php-mysql on roundcube container --- webmails/roundcube/Dockerfile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/webmails/roundcube/Dockerfile b/webmails/roundcube/Dockerfile index ad326767..53c043d9 100644 --- a/webmails/roundcube/Dockerfile +++ b/webmails/roundcube/Dockerfile @@ -21,7 +21,7 @@ ENV ROUNDCUBE_URL https://github.com/roundcube/roundcubemail/releases/download/1 RUN apt-get update && apt-get install -y \ zlib1g-dev libzip4 libzip-dev \ python3-jinja2 \ - && docker-php-ext-install zip \ + && docker-php-ext-install zip pdo_mysql \ && echo date.timezone=UTC > /usr/local/etc/php/conf.d/timezone.ini \ && rm -rf /var/www/html/ \ && cd /var/www \ From 982c93e3a2355ba211ee996e1d12cac09668a224 Mon Sep 17 00:00:00 2001 From: Michael Wyraz Date: Thu, 21 Nov 2019 13:46:38 +0100 Subject: [PATCH 3/8] Print roundcube error log to stdout --- webmails/roundcube/start.py | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/webmails/roundcube/start.py b/webmails/roundcube/start.py index 7851921a..f2c037cb 100755 --- a/webmails/roundcube/start.py +++ b/webmails/roundcube/start.py @@ -4,6 +4,7 @@ import os import logging as log import sys from socrate import conf +import subprocess log.basicConfig(stream=sys.stderr, level=os.environ.get("LOG_LEVEL", "WARNING")) @@ -35,8 +36,12 @@ else: conf.jinja("/php.ini", os.environ, "/usr/local/etc/php/conf.d/roundcube.ini") # Fix some permissions -os.system("mkdir -p /data/gpg") -os.system("chown -R www-data:www-data /data") +os.system("mkdir -p /data/gpg /var/www/html/logs") +os.system("touch /var/www/html/logs/errors") +os.system("chown -R www-data:www-data /data /var/www/html/logs") + +# Tail roundcube logs +subprocess.Popen(["tail","-f","-n","0","/var/www/html/logs/errors"]) # Run apache os.execv("/usr/local/bin/apache2-foreground", ["apache2-foreground"]) From 8242ca150ded72c5c06c9af91e751ed142a4543e Mon Sep 17 00:00:00 2001 From: Michael Wyraz Date: Thu, 21 Nov 2019 21:05:15 +0100 Subject: [PATCH 4/8] Create/update database on startup --- webmails/roundcube/start.py | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/webmails/roundcube/start.py b/webmails/roundcube/start.py index f2c037cb..e7dda509 100755 --- a/webmails/roundcube/start.py +++ b/webmails/roundcube/start.py @@ -40,6 +40,23 @@ os.system("mkdir -p /data/gpg /var/www/html/logs") os.system("touch /var/www/html/logs/errors") os.system("chown -R www-data:www-data /data /var/www/html/logs") +try: + print("Initializing database") + result=subprocess.check_output(["/var/www/html/bin/initdb.sh","--dir","/var/www/html/SQL"],stderr=subprocess.STDOUT) + print(result.decode()) +except subprocess.CalledProcessError as e: + if "already exists" in e.stdout.decode(): + print("Already initialzed") + else: + print(e.stdout.decode()) + quit(1) + +try: + print("Upgrading database") + subprocess.check_call(["/var/www/html/bin/update.sh","--version=?","-y"],stderr=subprocess.STDOUT) +except subprocess.CalledProcessError as e: + quit(1) + # Tail roundcube logs subprocess.Popen(["tail","-f","-n","0","/var/www/html/logs/errors"]) From 2cb42c31a6c6f5c4470bce4a034bc4bd50ed24dc Mon Sep 17 00:00:00 2001 From: Michael Wyraz Date: Thu, 21 Nov 2019 23:32:01 +0100 Subject: [PATCH 5/8] Add changelog --- towncrier/newsfragments/1268.feature | 1 + 1 file changed, 1 insertion(+) create mode 100644 towncrier/newsfragments/1268.feature diff --git a/towncrier/newsfragments/1268.feature b/towncrier/newsfragments/1268.feature new file mode 100644 index 00000000..e4cf9a5a --- /dev/null +++ b/towncrier/newsfragments/1268.feature @@ -0,0 +1 @@ +The roundcube container does support mysql now (no setup integration yet) From fe09cf57052ae8a21810897bff7b1c9a183ed9a9 Mon Sep 17 00:00:00 2001 From: Michael Wyraz Date: Thu, 12 Dec 2019 20:43:56 +0100 Subject: [PATCH 6/8] Default to DB_FLAVOR/DB_HOST if ROUNDCUBE_DB_FLAVOR/ROUNDCUBE_DB_HOST is not set --- webmails/roundcube/start.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/webmails/roundcube/start.py b/webmails/roundcube/start.py index e7dda509..ef913a2b 100755 --- a/webmails/roundcube/start.py +++ b/webmails/roundcube/start.py @@ -10,21 +10,21 @@ log.basicConfig(stream=sys.stderr, level=os.environ.get("LOG_LEVEL", "WARNING")) os.environ["MAX_FILESIZE"] = str(int(int(os.environ.get("MESSAGE_SIZE_LIMIT"))*0.66/1048576)) -db_flavor=os.environ.get("ROUNDCUBE_DB_FLAVOR","sqlite") +db_flavor=os.environ.get("ROUNDCUBE_DB_FLAVOR",os.environ.get("DB_FLAVOR","sqlite")) if db_flavor=="sqlite": os.environ["DB_DSNW"]="sqlite:////data/roundcube.db" elif db_flavor=="mysql": os.environ["DB_DSNW"]="mysql://%s:%s@%s/%s" % ( os.environ.get("ROUNDCUBE_DB_USER","roundcube"), os.environ.get("ROUNDCUBE_DB_PW"), - os.environ.get("ROUNDCUBE_DB_HOST","database"), + os.environ.get("ROUNDCUBE_DB_HOST",os.environ.get("DB_HOST","database")), os.environ.get("ROUNDCUBE_DB_NAME","roundcube") ) elif db_flavor=="postgresql": os.environ["DB_DSNW"]="pgsql://%s:%s@%s/%s" % ( os.environ.get("ROUNDCUBE_DB_USER","roundcube"), os.environ.get("ROUNDCUBE_DB_PW"), - os.environ.get("ROUNDCUBE_DB_HOST","database"), + os.environ.get("ROUNDCUBE_DB_HOST",os.environ.get("DB_HOST","database")), os.environ.get("ROUNDCUBE_DB_NAME","roundcube") ) else: From b4d81f833dc2172c7049cfe9f77319c7134b1297 Mon Sep 17 00:00:00 2001 From: micw Date: Fri, 6 Mar 2020 15:55:35 +0100 Subject: [PATCH 7/8] Add pdo_pgsql to Dockerfile --- webmails/roundcube/Dockerfile | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/webmails/roundcube/Dockerfile b/webmails/roundcube/Dockerfile index 53c043d9..a3ee3d40 100644 --- a/webmails/roundcube/Dockerfile +++ b/webmails/roundcube/Dockerfile @@ -19,9 +19,9 @@ RUN pip3 install socrate ENV ROUNDCUBE_URL https://github.com/roundcube/roundcubemail/releases/download/1.3.10/roundcubemail-1.3.10-complete.tar.gz RUN apt-get update && apt-get install -y \ - zlib1g-dev libzip4 libzip-dev \ + zlib1g-dev libzip4 libzip-dev postgresql-dev \ python3-jinja2 \ - && docker-php-ext-install zip pdo_mysql \ + && docker-php-ext-install zip pdo_mysql pdo_pgsql \ && echo date.timezone=UTC > /usr/local/etc/php/conf.d/timezone.ini \ && rm -rf /var/www/html/ \ && cd /var/www \ From e08f4ab7a92aacc360a9dcf4a435d51f9ca7801e Mon Sep 17 00:00:00 2001 From: micw Date: Sat, 7 Mar 2020 19:38:12 +0100 Subject: [PATCH 8/8] Fix wrong psql lib name --- webmails/roundcube/Dockerfile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/webmails/roundcube/Dockerfile b/webmails/roundcube/Dockerfile index a3ee3d40..55de8b93 100644 --- a/webmails/roundcube/Dockerfile +++ b/webmails/roundcube/Dockerfile @@ -19,7 +19,7 @@ RUN pip3 install socrate ENV ROUNDCUBE_URL https://github.com/roundcube/roundcubemail/releases/download/1.3.10/roundcubemail-1.3.10-complete.tar.gz RUN apt-get update && apt-get install -y \ - zlib1g-dev libzip4 libzip-dev postgresql-dev \ + zlib1g-dev libzip4 libzip-dev libpq-dev \ python3-jinja2 \ && docker-php-ext-install zip pdo_mysql pdo_pgsql \ && echo date.timezone=UTC > /usr/local/etc/php/conf.d/timezone.ini \