iredmail / dockerized

Official dockerized iRedMail.
https://www.iredmail.org/
281 stars 71 forks source link

Need help: How to maintain default settings with Docker Hub? #9

Closed iredmail closed 4 years ago

iredmail commented 4 years ago

Dear all,

I need some help here.

Currently we use GitHub repo to manage all files used to build docker image, so it's easy to store many files, especially two config files:

We store MANY parameters with their default values in default_settings.conf, like paths to mailboxes, ssl cert/key files, clamav database, also parameters used to enable or disable some features:

#
# Enable/disable components
#
USE_IREDAPD=YES
USE_ANTISPAM=YES
USE_ROUNDCUBE=YES
USE_FAIL2BAN=YES

#
# Enable/disable features
#
FAIL2BAN_STORE_BANNED_IP_IN_DB=YES
POSTFIX_ENABLE_SRS=YES

Currently default_settings.conf is maintained by iRedMail Team, and iredmail.conf should be maintained by user to override settings defined in default_settings.conf.

If we offer docker image via the Docker Hub, user gets only one image, no default_settings.conf. It's not good to store all parameters in iredmail.conf and ask users to add new ones or remove deprecated ones if there's some update, and user may make mistakes (quite often).

So the question is: is there any easy way we can maintain the default settings, and let users just maintain customized ones?

iredmail commented 4 years ago

@lejmr @TitanFighter @oubayun

TitanFighter commented 4 years ago

Maybe I do not understand something, but I do not see any problems keeping everything you need (including default_settings.conf) inside your image (and update default_settings.conf and the rest things and release a new image every time you need). You can build (read as: add any files to your image) the way you wish and then upload the image you built to docker hub.

Here is the little instruction how to build and push an image to Docker Hub.

Additionally you can check, for example, implementation of PostgreSQL (docker hub + git), because they also use some default env values.

  1. They use ENTRYPOINT directive in Dockerfile
  2. I'm not good with bash but it seems they use a docker_setup_env and file_env functions to set default env values.
  3. So you can use your own docker-entrypoint.sh file with your default values (or even import default_settings.conf into docker-entrypoint.sh).
  4. In case when user needs to change any values, user can either:
    • add --env-file iredmail.conf, ie: docker run --env-file iredmail.conf
    • use -e, ie: docker run -e HOSTNAME=mail.xyz.com -e FIRST_MAIL_DOMAIN=xyz.com

which, as a result, override your default env values.

Does it help?

iredmail commented 4 years ago

Thanks for sharing. It’s a good idea, I will make it happen soon. :)

lejmr commented 4 years ago

Hi, I am sorry for late response.

I totally agree with using env variables through -e or --env-file parameters. I can't even express how annoying is to push a config file into a container if you dont want to go with default variables.

The default_settings.conf is a good idea, but that is going to be tricky to make sure the default values for such variables get overrode by -e/--env-file variables. Bear in mind that all variables pushed using -e/--env-file are visible among env variables (which get listed by env bash command). Therefore, the easiest way is to list all variables from default_settings.conf as ENV steps of Dockerfile (which can be done by pre-commit hook in git).

Other (maybe a side comment) is to container builds from CI. You can use jenkins/travis/what-ever-ci-as-a-service then you can automate some tricks as generation of the aforementioned ENV steps, etc. However, you won't get the label "Automatic build of iRedMail", e.g., https://hub.docker.com/r/lejmr/iredmail. Therefore, if you want to get this label on the docker hub then you must make sure the git repository works standalone hence you can just use command docker built -t name:tag . in order to build container locally. Sure you can have multiple projects of the one git repository and define when the Dockerfile is located thus you can generate multiple containers from one git repo (basically what you are shooting for right now)

iredmail commented 4 years ago

Dear all,

Thank you very much for sharing. Latest git version packs default_settings.conf to image directly.