Hi Folks,
What is the overall interest and the maintainers’ perspective on migrating MIAB to run in a containerized environment as a fully supported, if not the recommended way to deploy Mail-in-a-Box?
TL;DR It’s easy to run the current MIAB in a proof-of-concept containerized environment – let’s discuss the interest and issues involved in fully supporting a containerized MIAB.
Background
As part of preparing for the migration to v60.1, and following my first false start, I got MIAB running in a podman container, hoping it would make the migration simpler to test and rollback if necessary. Running MIAB in a rootless, systemd-aware podman-container was an easy proof-of-concept for containerized MIAB. However, it raised a number of design, migration, and long-term support issues, so I set the containerization idea aside as my second false start.
Eventually my traditional migration to a new Ubuntu 22.04 server was successful, but it took a bit of planning and obsessing. It is documented as the final couple of entries in the Discourse discussion for the v60 migration. Version 60 for Ubuntu 22.04 is released - #104 by hughsw
As a result of the containerization POC I learned a lot about MIAB internals, and I’ve made PRs for a few fixes and UI improvements to MIAB.
At this point I’m trying to figure out if a containerized MIAB could
- make the end-user’s installation and maintenance easier
- make the maintainers’ development and testing cycles easier
- avoid the frictions of the v60 upgrade to Ubuntu 22.04
- address the common theme of wanting to run other services alongside MIAB (search for Discourse entries with ‘docker’ or ‘container’).
Proof-of-concept 1
I have a package that builds and runs a new MIAB installation in a rootless container using podman. The image-building steps control the exact Ubuntu 22.04 environment that MIAB gets inside the container. It is refreshing to have complete control over the Ubuntu, unlike when installing on one of the varied Ubuntus one gets on different cloud providers or the (unsupported) situations where MIAB is shoehorned into older or non-exclusive Ubuntu environments. That is, containerization eliminates a whole class of at-present-uncontrollable environmental issues.
On the host side, for rootless use of podman, I had to tweak the sysctl config to allow unprivileged users to open low-numbered ports, so that the rootless podman could map the relevant ports into the container. This seemed preferable and more cgroups embracing than running podman as root. The command-line for running podman specifies the necessary port mappings and directory bindings so that MIAB can do its things.
On the MIAB side (running in the container), for the POC, I only had to make two un-intrusive one-line changes to MIAB’s setup code. By “un-intrusive” I mean that the changes would not affect the traditional hosted MIAB installation and usage. With those two one-line tweaks, containerized MIAB installation and maintenance is essentially identical to running the traditional (hosted) way. A minor difference is that you have to ssh to a high-numbered port that podman maps to the container’s port 22. After the curl-based setup steps, Email, DNS, certificates, web access, administration, backups, cli, etc all “just work”. I have done this using podman hosted on Ubuntu, Debian, and CentOS.
Proof-of-concept 2
I took the containerizing process a step further. I un-intrusively factored the setup script code, separating the logic into three semantics:
- generic installation of Ubuntu packages
- shared MIAB setup, i.e. MIAB-specific package configuration that does not depend on the contents of
/etc/mailinabox.conf
- deployment specific MIAB setup, i.e. package and MIAB configuration that does depend on the contents of
/etc/mailinabox.conf
The first two of these can be done when building the image, i.e. once, by the MIAB maintainer in the release build process. No end-user would have to wait for Ubuntu apt-get installations and their hiccups again, and maintainers would not have to field Issues stemming from the package installation problems, e.g. transient repository failures, botched upgrades, etc!
The third step, configuration that depends on the contents of /etc/mailinabox.conf
(mostly PRIMARY_HOSTNAME
), obviously has to be run by the end-user when setting up their deployment. Actually, it’s essentially the only thing an end-user has to do. It’s quicker and simpler compared the current MIAB installation process.
That’s where things stand with POC work, and the lessons of that effort informs the following list of discussion points.
Discussion points
There is the important question of clarifying and weighing the long-term gains and costs of moving MIAB to a containerized structure. Does it have significant benefits? And, to have a supportable, containerized MIAB package there are a number of high-level design and other technical issues to address.
Here’s my quick outline of the major technical matters to be sorted out:
- which containerization environment to support – I used podman for several reasons; Kubernetes, Docker, LXC/LXD, etc are other options
- how to manage the overall state of the MIAB deployment – at present this state is scattered in
- the
/home/user-data
tree (configuration, credentials, email, webmail databases) - the
/etc
tree (configuration managed by packages and by MIAB) - the
/var/lib
tree (configuration managed by packages and by MIAB) -
/root/.ssh/id_rsa_miab
(credentials)
- the
- which parts of this state should be stored where:
- in the container’s file system, or is the container ephemeral (meaning there is no expectation of or reliance on the persistence of the container)
- in the containerization’s file store, e.g. podman volumes
- in host file trees
- how to migrate an existing MIAB installation into the containerized environment
- how to do a fresh MIAB installation into the containerized environment
- how to structure MIAB’s ongoing migrations, both its internals and when Ubuntu packages need to be reconfigured
- supporting development and testing work for maintainers
- release process and a CI/CD framework
- documentation
- And, once the above are reasoned-out, how to structure the incremental changes needed to get to the containerized goal without breaking things and with minimal friction
AFAICT none of these has any show-stopper qualities, but I’m not a veteran of the MIAB maintenance experience, and some of the webmail/web-app support in MIAB has torturous migration logic
And obviously, there would have to be agreement among the maintainers that this is the right direction for MIAB to move.
So, please provide high-level input on the pros and cons of moving to a containerized MIAB, and please add to the list and discuss the lower-level, implementation issues outlined above.
Thanks,
-Hugh
[ Some of the points (and prose) above appears in my comments in this issue: Any official docker installation? · Issue #1934 · mail-in-a-box/mailinabox · GitHub ]