espocrm / espocrm-docker

Official Docker Image for EspoCRM
https://hub.docker.com/r/espocrm/espocrm
GNU Affero General Public License v3.0
56 stars 34 forks source link

Suggestions for handling config.php with Dockerized EspoCRM #9

Closed bliles closed 2 years ago

bliles commented 2 years ago

Could you provide feedback on best practices for managing data/config.php with a docker build of EspoCRM?

This file contains configuration that needs to be persisted across a cluster of web nodes, for example, tabList and smtp settings, therefore I would like to track the file in our git repo and include it in our build of the app, but doing this with the stock docker image causes the Espo installation process to fail because the installer thinks that the app has already been installed if this file is present. Also config.php contains values like siteUrl that should not be baked into the image since it needs to be per environment.

bliles commented 2 years ago

This is what I've come up with so far as part of the container startup to build the proper config files for Espo.

<?php

$config = include("/path/to/templates/config.php");
$config['siteUrl'] = getenv('ESPOCRM_SITE_URL');
file_put_contents("/var/www/html/data/config.php", "<?php\nreturn " . var_export($config, true) . ";\n");

$configInternal = include("/path/to/templates/config-internal.php");
$configInternal['database']['host'] = getenv('ESPOCRM_DATABASE_HOST');
$configInternal['database']['dbname'] = getenv('ESPOCRM_DATABASE_NAME');
$configInternal['database']['user'] = getenv('ESPOCRM_DATABASE_USER');
$configInternal['database']['password'] = getenv('ESPOCRM_DATABASE_PASSWORD');
$configInternal['passwordSalt'] = getenv('ESPOCRM_PASSWORD_SALT');
$configInternal['cryptKey'] = getenv('ESPOCRM_CRYPT_KEY');
$configInternal['hashSecretKey'] = getenv('ESPOCRM_HASH_SECRET_KEY');

file_put_contents("/var/www/html/data/config-internal.php", "<?php\nreturn " . var_export($configInternal, true) . ";\n");
tmachyshyn commented 2 years ago

Hello,

You can define these parameters while creating the container. Please see https://hub.docker.com/r/espocrm/espocrm under Installation Environments section. Also, you can change any config option (string, integer, boolean) by using Config Environments. See https://hub.docker.com/r/espocrm/espocrm.

bliles commented 2 years ago

I found that using the method you mention resulted in Espo doing an install during container start. The install process generated new cryptKey, passwordSalt and hashSecretKey values. These values need to remain consistent between deploys to the same environment/multiple nodes in the same cluster.

tmachyshyn commented 2 years ago

In this case, you have to create a data/config.php file before starting the installation process in the way you described above.

mich3000 commented 2 years ago

In this case, you have to create a data/config.php file before starting the installation process in the way you described above.

Hello,

You can define these parameters while creating the container. Please see https://hub.docker.com/r/espocrm/espocrm under Installation Environments section. Also, you can change any config option (string, integer, boolean) by using Config Environments. See https://hub.docker.com/r/espocrm/espocrm.

Version 7 also uses config-internal.php. How can i set parameters in docker-compose for that file. Thanks

tmachyshyn commented 2 years ago

This is automatically defined on the EspoCRM side. All items in the systemItems will be added to the config-internal.php. If you need some extra parameters to be added to the config-internal.php, you have to add to config.php the code:

'systemItems' => [
    '__APPEND__',
    'YOUR_PARAMETER'
],