Repository: Mailu/Mailu

Issue:
Build webmails on php:fpm-alpine
Mailu's webmails are both built on debian/apache/php.

AFAIK all other mailu components are based on alpine, and we already have an nginx frontend.

IMHO it would make sense to rebase webmails on php:fpm-alpine and use the same nginx frontend for the static parts of the webmails.

If we want independent webmail containers (which is also nice), we should at least build the images with alpine/nginx/php-fpm built-in.


Discussion:
Hi There,

The `Mailu`-Project is currently in a bit of a bind! We are short on man-power, and we need to judge if it is possible for us to put in some work on this issue.

To help with that, we are currently trying to find out which issues are actively keeping users from using `Mailu`, which issues have someone who want to work on them — and which issues may be less important. These a less important ones could be discarded for the time being, until the project is in a more stable and regular state once again.

In order for us to better assess this, it would be helpful if you could put a **reaction on this post** (use the :smiley: icon to the top-right).
- 👍️ if you **need this** to be able to use Mailu. Ideally, you’d also be able to test this on your installation, and provide feedback …
- 🎉 if you find it a **nice bonus**, but no deal-breaker
- 🚀 if you want to **work on it yourself**!
We want to keep this **voting open for 2 weeks** from now, so please help out!
This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.

Using fpm and serving the static files via the existing would require sharing the files between both containers either via volumes (and subsequently some upgrade logic) or by putting all webmail files also in the nginx image.

I think your second proposal (completely independent containers) makes more sense, which is probably why it's currently built that way.

For using alpine we'd need to switch the base image, as docker.io/php doesn't provide tags with both alpine base and an integrated web server as far as I can see.

I don't really see a benefit in switching to alpine just for the sake of it, considering we'd need different base images and thus would have to switch away from the official Docker image for php.
Hi There,

we see this issue had only little attention 😟. As much as it pains us: In order to get the current issues a bit more manageable for us, we decided to close it. 👋👋

We hope that no one feels offended by doing so. Should the issue get really pressing in the future, please feel free to re-open it.

Thank you for your patience and understanding, 🙇
- Your Mailu Team
I'd like to re-open this.

Here the image of the webmail is over 600MiB, fresh start with no user it's 70MiB of RAM... we can do better.
One good reason to switch is to limit the number of technologies (and configuration syntaxes) one has to be familiar with. If front is nginx, whatever is behind should either have very little configuration (FPM) or be the same (another nginx instance)
There are a couple of possibilities:
- Use php:fpm-alpine and use the same nginx frontend (front image) for the static parts of the webmails.
- Use php:fpm-alpine and also use this image for serving static files

For roundcube we could chose to base our image on the official roundcube php-fpm-alpine image. 
https://github.com/roundcube/roundcubemail-docker
It is already has the functionality to set via env variable what plugins you want to run. A much requested feature for mailu roundcube. 

For rainloop I could not find any official image. But there is a  dockerfile on the rainloop repo we could use as a basis.
https://github.com/RainLoop/rainloop-webmail/tree/master/.docker/php 


Resolving patch:
diff --git a/webmails/roundcube/start.py b/webmails/roundcube/start.py
--- a/webmails/roundcube/start.py
+++ b/webmails/roundcube/start.py
@@ -1,12 +1,13 @@
-#!/usr/bin/python3
+#!/usr/bin/env python3
 
 import os
 import logging
 import sys
-from socrate import conf
 import subprocess
 import hmac
 
+from socrate import conf
+
 env = os.environ
 
 logging.basicConfig(stream=sys.stderr, level=env.get("LOG_LEVEL", "WARNING"))
@@ -51,7 +52,7 @@
 
 # roundcube plugins
 # (using "dict" because it is ordered and "set" is not)
-plugins = dict((p, None) for p in env.get("ROUNDCUBE_PLUGINS", "").replace(" ", "").split(",") if p and os.path.isdir(os.path.join("/var/www/html/plugins", p)))
+plugins = dict((p, None) for p in env.get("ROUNDCUBE_PLUGINS", "").replace(" ", "").split(",") if p and os.path.isdir(os.path.join("/var/www/webmail/plugins", p)))
 if plugins:
     plugins["mailu"] = None
 else:
@@ -66,18 +67,15 @@
 context["SESSION_TIMEOUT_MINUTES"] = max(int(env.get("SESSION_TIMEOUT", "3600")) // 60, 1)
 
 # create config files
-conf.jinja("/php.ini", context, "/usr/local/etc/php/conf.d/roundcube.ini")
-conf.jinja("/config.inc.php", context, "/var/www/html/config/config.inc.php")
+conf.jinja("/conf/php.ini", context, "/etc/php81/php.ini")
+conf.jinja("/conf/config.inc.php", context, "/var/www/webmail/config/config.inc.php")
 
 # create dirs
 os.system("mkdir -p /data/gpg")
 
-# disable access log for VirtualHosts that don't define their own logfile
-os.system("a2disconf other-vhosts-access-log")
-
 print("Initializing database")
 try:
-    result = subprocess.check_output(["/var/www/html/bin/initdb.sh", "--dir", "/var/www/html/SQL"],
+    result = subprocess.check_output(["/var/www/webmail/bin/initdb.sh", "--dir", "/var/www/webmail/SQL"],
                                      stderr=subprocess.STDOUT)
     print(result.decode())
 except subprocess.CalledProcessError as exc:
@@ -90,22 +88,29 @@
 
 print("Upgrading database")
 try:
-    subprocess.check_call(["/var/www/html/bin/update.sh", "--version=?", "-y"], stderr=subprocess.STDOUT)
+    subprocess.check_call(["/var/www/webmail/bin/update.sh", "--version=?", "-y"], stderr=subprocess.STDOUT)
 except subprocess.CalledProcessError as exc:
     exit(4)
 else:
     print("Cleaning database")
     try:
-        subprocess.check_call(["/var/www/html/bin/cleandb.sh"], stderr=subprocess.STDOUT)
+        subprocess.check_call(["/var/www/webmail/bin/cleandb.sh"], stderr=subprocess.STDOUT)
     except subprocess.CalledProcessError as exc:
         exit(5)
 
 # setup permissions
-os.system("chown -R www-data:www-data /data")
+os.system("chown -R nginx:nginx /data")
+os.system("chmod -R a+rX /var/www/webmail/")
+
+# Configure nginx
+conf.jinja("/conf/nginx-roundcube.conf", context, "/etc/nginx/http.d/roundcube.conf")
+if os.path.exists("/var/run/nginx.pid"):
+    os.system("nginx -s reload")
 
 # clean env
 [env.pop(key, None) for key in env.keys() if key == "SECRET_KEY" or key.startswith("ROUNDCUBE_")]
 
-# run apache
-os.execve("/usr/local/bin/apache2-foreground", ["apache2-foreground"], env)
+# run nginx
+os.system("php-fpm81")
+os.execv("/usr/sbin/nginx", ["nginx", "-g", "daemon off;"])
 
diff --git a/webmails/snappymail/config.py b/webmails/snappymail/config.py
--- a/webmails/snappymail/config.py
+++ b/webmails/snappymail/config.py
@@ -1,8 +1,9 @@
-#!/usr/bin/python3
+#!/usr/bin/env python3
 
 import os
 import logging as log
 import sys
+
 from socrate import system, conf
 
 args = os.environ.copy()
diff --git a/webmails/snappymail/start.py b/webmails/snappymail/start.py
--- a/webmails/snappymail/start.py
+++ b/webmails/snappymail/start.py
@@ -1,10 +1,11 @@
-#!/usr/bin/python3
+#!/usr/bin/env python3
 
 import os
 import shutil
 import logging as log
 import sys
 import subprocess
+
 from socrate import system, conf
 
 log.basicConfig(stream=sys.stderr, level=os.environ.get("LOG_LEVEL", "WARNING"))
@@ -22,9 +23,9 @@
 
 conf.jinja("/defaults/default.ini", os.environ, "/data/_data_/_default_/domains/default.ini")
 conf.jinja("/defaults/application.ini", os.environ, "/data/_data_/_default_/configs/application.ini")
-conf.jinja("/defaults/php.ini", os.environ, "/etc/php7/php.ini")
+conf.jinja("/defaults/php.ini", os.environ, "/etc/php81/php.ini")
 # Start the fastcgi process manager now that config files have been adjusted
-os.system("php-fpm7")
+os.system("php-fpm81")
 
 os.system("chown -R nginx:nginx /data")
 os.system("chmod -R a+rX /var/www/webmail/")


Test patch:
diff --git a/tests/build.hcl b/tests/build.hcl
--- a/tests/build.hcl
+++ b/tests/build.hcl
@@ -174,12 +174,18 @@ target "smtp" {
 target "snappymail" {
   inherits = ["defaults"]
   context = "webmails/snappymail/"
+  contexts = {
+    base = "target:base"
+  }
   tags = tag("snappymail")
 }
 
 target "roundcube" {
   inherits = ["defaults"]
   context = "webmails/roundcube/"
+  contexts = {
+    base = "target:base"
+  }
   tags = tag("roundcube")
 }