diff --git a/README.md b/README.md index 005f908..a229058 100644 --- a/README.md +++ b/README.md @@ -6,8 +6,9 @@ Docker image for Dolibarr with auto installer on first boot. * 15.0.3-php7.4 15.0.3 15 * 16.0.5-php8.1 16.0.5 16 -* 17.0.3-php8.1 17.0.3 17 -* 18.0.2-php8.1 18.0.2 18 latest +* 17.0.4-php8.1 17.0.4 17 +* 18.0.5-php8.1 18.0.5 18 +* 19.0.2-php8.2 19.0.2 19 latest * develop **End of support for PHP < 7.4** @@ -102,6 +103,9 @@ When setup this way, to upgrade version the use of the web interface is mandator | **DOLI_ADMIN_LOGIN** | *admin* | Admin's login create on the first boot | **DOLI_ADMIN_PASSWORD** | *admin* | Admin'password | **DOLI_URL_ROOT** | *http://localhost* | Url root of the Dolibarr installation +| **DOLI_ENABLE_MODULES** | | Comma-separated list of modules to be activated at install. modUser will always be activated. (Ex: `Societe,Facture,Stock`) +| **DOLI_COMPANY_NAME** | | Set the company name of Dolibarr at container init +| **DOLI_COMPANY_COUNTRYCODE** | | Set the company and Dolibarr country at container init. Need 2-letter codes like "FR", "GB", "US",... | **PHP_INI_DATE_TIMEZONE** | *UTC* | Default timezone on PHP | **PHP_INI_MEMORY_LIMIT** | *256M* | PHP Memory limit | **PHP_INI_UPLOAD_MAX_FILESIZE** | *2M* | PHP Maximum allowed size for uploaded files @@ -135,3 +139,40 @@ Environment variables that are compatible with docker secrets: * `DOLI_CRON_KEY` => `DOLI_CRON_KEY_FILE` * `DOLI_CRON_USER` => `DOLI_CRON_USER_FILE` * `DOLI_INSTANCE_UNIQUE_ID` => `DOLI_INSTANCE_UNIQUE_ID_FILE` + +## Add post-deployment scripts +It is possible to execute `*.sh`, `*.sql` and/or `*.php` custom file at the end of deployment by mounting a volume in `/var/www/scripts/docker-init.d` +``` +\docker-init.d +|- custom_script.sql +|- custom_script.php +|- custom_script.sh +``` + +Mount the volume with compose file : +```yaml +version: "3" + +services: + mariadb: + image: mariadb:latest + environment: + MYSQL_ROOT_PASSWORD: root + MYSQL_DATABASE: dolibarr + + web: + image: tuxgasy/dolibarr + environment: + DOLI_DB_HOST: mariadb + DOLI_DB_USER: root + DOLI_DB_PASSWORD: root + DOLI_DB_NAME: dolibarr + DOLI_URL_ROOT: 'http://0.0.0.0' + PHP_INI_DATE_TIMEZONE: 'Europe/Paris' + volumes : + - volume-scripts:/var/www/scripts/docker-init.d + ports: + - "80:80" + links: + - mariadb +``` diff --git a/README.template b/README.template index 20665e7..83b02f8 100644 --- a/README.template +++ b/README.template @@ -97,6 +97,9 @@ When setup this way, to upgrade version the use of the web interface is mandator | **DOLI_ADMIN_LOGIN** | *admin* | Admin's login create on the first boot | **DOLI_ADMIN_PASSWORD** | *admin* | Admin'password | **DOLI_URL_ROOT** | *http://localhost* | Url root of the Dolibarr installation +| **DOLI_ENABLE_MODULES** | | Comma-separated list of modules to be activated at install. modUser will always be activated. (Ex: `Societe,Facture,Stock`) +| **DOLI_COMPANY_NAME** | | Set the company name of Dolibarr at container init +| **DOLI_COMPANY_COUNTRYCODE** | | Set the company and Dolibarr country at container init. Need 2-letter codes like "FR", "GB", "US",... | **PHP_INI_DATE_TIMEZONE** | *UTC* | Default timezone on PHP | **PHP_INI_MEMORY_LIMIT** | *256M* | PHP Memory limit | **PHP_INI_UPLOAD_MAX_FILESIZE** | *2M* | PHP Maximum allowed size for uploaded files @@ -130,3 +133,40 @@ Environment variables that are compatible with docker secrets: * `DOLI_CRON_KEY` => `DOLI_CRON_KEY_FILE` * `DOLI_CRON_USER` => `DOLI_CRON_USER_FILE` * `DOLI_INSTANCE_UNIQUE_ID` => `DOLI_INSTANCE_UNIQUE_ID_FILE` + +## Add post-deployment scripts +It is possible to execute `*.sh`, `*.sql` and/or `*.php` custom file at the end of deployment by mounting a volume in `/var/www/scripts/docker-init.d` +``` +\docker-init.d +|- custom_script.sql +|- custom_script.php +|- custom_script.sh +``` + +Mount the volume with compose file : +```yaml +version: "3" + +services: + mariadb: + image: mariadb:latest + environment: + MYSQL_ROOT_PASSWORD: root + MYSQL_DATABASE: dolibarr + + web: + image: tuxgasy/dolibarr + environment: + DOLI_DB_HOST: mariadb + DOLI_DB_USER: root + DOLI_DB_PASSWORD: root + DOLI_DB_NAME: dolibarr + DOLI_URL_ROOT: 'http://0.0.0.0' + PHP_INI_DATE_TIMEZONE: 'Europe/Paris' + volumes : + - volume-scripts:/var/www/scripts/docker-init.d + ports: + - "80:80" + links: + - mariadb +``` diff --git a/docker-init.php b/docker-init.php index dc0dea8..1fe71a3 100644 --- a/docker-init.php +++ b/docker-init.php @@ -1,6 +1,46 @@ #!/usr/bin/env php init(); +require_once DOL_DOCUMENT_ROOT.'/core/lib/admin.lib.php'; + +printf("Activating module User... "); +activateModule('modUser'); +printf("OK\n"); + +if (!empty(getenv('DOLI_COMPANY_COUNTRYCODE'))) { + require_once DOL_DOCUMENT_ROOT.'/core/lib/company.lib.php'; + require_once DOL_DOCUMENT_ROOT.'/core/class/ccountry.class.php'; + $countryCode = getenv('DOLI_COMPANY_COUNTRYCODE'); + $country = new Ccountry($db); + $res = $country->fetch(0,$countryCode); + if ($res > 0 ) { + $s = $country->id.':'.$country->code.':'.$country->label; + dolibarr_set_const($db, "MAIN_INFO_SOCIETE_COUNTRY", $s, 'chaine', 0, '', $conf->entity); + printf('Configuring for country : '.$s."\n"); + activateModulesRequiredByCountry($country->code); + } else { + printf('Unable to find country '.$countryCode."\n"); + } +} + +if (!empty(getenv('DOLI_COMPANY_NAME'))) { + $compname = getenv('DOLI_COMPANY_NAME'); + dolibarr_set_const($db, "MAIN_INFO_SOCIETE_NOM", $compname, 'chaine', 0, '', $conf->entity); +} + +if (!empty(getenv('DOLI_ENABLE_MODULES'))) { + $mods = explode(',', getenv('DOLI_ENABLE_MODULES')); + foreach ($mods as $mod) { + printf("Activating module ".$mod." ..."); + try { + $res = activateModule('mod' . $mod); + if ($res < 0) { + print(" FAILED. Unable to load module. Be sure to check the case\n"); + } else { + printf(" OK\n"); + } + } catch (Throwable $t) { + print(" FAILED. Unable to load module. Be sure to check the case\n"); + } + } +} diff --git a/docker-run.sh b/docker-run.sh index 69e3e3d..9196c13 100755 --- a/docker-run.sh +++ b/docker-run.sh @@ -171,6 +171,29 @@ function initializeDatabase() echo "Enable user module ..." php /var/www/scripts/docker-init.php + + if [ -d /var/www/scripts/docker-init.d ] ; then + for file in /var/www/scripts/docker-init.d/*; do + [ ! -f $file ] && continue + + # If extension is not in PHP SQL SH, we loop + isExec=$(echo "PHP SQL SH" | grep -wio ${file##*.}) + [ -z "$isExec" ] && continue + + echo "Importing custom ${isExec} from `basename ${file}` ..." + if [ "$isExec" == "SQL" ] ; then + sed -i 's/--.*//g;' ${file} + mysql -u ${DOLI_DB_USER} -p${DOLI_DB_PASSWORD} -h ${DOLI_DB_HOST} -P ${DOLI_DB_HOST_PORT} ${DOLI_DB_NAME} < ${file} > /dev/null 2>&1 + elif [ "$isExec" == "PHP" ] ; then + php $file + elif [ "$isExec" == "SH" ] ; then + /bin/bash $file + fi + done + fi + + # Update ownership after initialisation of modules + chown -R www-data:www-data /var/www/documents } function migrateDatabase() diff --git a/images/15.0.3-php7.4/docker-init.php b/images/15.0.3-php7.4/docker-init.php index dc0dea8..1fe71a3 100644 --- a/images/15.0.3-php7.4/docker-init.php +++ b/images/15.0.3-php7.4/docker-init.php @@ -1,6 +1,46 @@ #!/usr/bin/env php init(); +require_once DOL_DOCUMENT_ROOT.'/core/lib/admin.lib.php'; + +printf("Activating module User... "); +activateModule('modUser'); +printf("OK\n"); + +if (!empty(getenv('DOLI_COMPANY_COUNTRYCODE'))) { + require_once DOL_DOCUMENT_ROOT.'/core/lib/company.lib.php'; + require_once DOL_DOCUMENT_ROOT.'/core/class/ccountry.class.php'; + $countryCode = getenv('DOLI_COMPANY_COUNTRYCODE'); + $country = new Ccountry($db); + $res = $country->fetch(0,$countryCode); + if ($res > 0 ) { + $s = $country->id.':'.$country->code.':'.$country->label; + dolibarr_set_const($db, "MAIN_INFO_SOCIETE_COUNTRY", $s, 'chaine', 0, '', $conf->entity); + printf('Configuring for country : '.$s."\n"); + activateModulesRequiredByCountry($country->code); + } else { + printf('Unable to find country '.$countryCode."\n"); + } +} + +if (!empty(getenv('DOLI_COMPANY_NAME'))) { + $compname = getenv('DOLI_COMPANY_NAME'); + dolibarr_set_const($db, "MAIN_INFO_SOCIETE_NOM", $compname, 'chaine', 0, '', $conf->entity); +} + +if (!empty(getenv('DOLI_ENABLE_MODULES'))) { + $mods = explode(',', getenv('DOLI_ENABLE_MODULES')); + foreach ($mods as $mod) { + printf("Activating module ".$mod." ..."); + try { + $res = activateModule('mod' . $mod); + if ($res < 0) { + print(" FAILED. Unable to load module. Be sure to check the case\n"); + } else { + printf(" OK\n"); + } + } catch (Throwable $t) { + print(" FAILED. Unable to load module. Be sure to check the case\n"); + } + } +} diff --git a/images/15.0.3-php7.4/docker-run.sh b/images/15.0.3-php7.4/docker-run.sh index 69e3e3d..9196c13 100755 --- a/images/15.0.3-php7.4/docker-run.sh +++ b/images/15.0.3-php7.4/docker-run.sh @@ -171,6 +171,29 @@ function initializeDatabase() echo "Enable user module ..." php /var/www/scripts/docker-init.php + + if [ -d /var/www/scripts/docker-init.d ] ; then + for file in /var/www/scripts/docker-init.d/*; do + [ ! -f $file ] && continue + + # If extension is not in PHP SQL SH, we loop + isExec=$(echo "PHP SQL SH" | grep -wio ${file##*.}) + [ -z "$isExec" ] && continue + + echo "Importing custom ${isExec} from `basename ${file}` ..." + if [ "$isExec" == "SQL" ] ; then + sed -i 's/--.*//g;' ${file} + mysql -u ${DOLI_DB_USER} -p${DOLI_DB_PASSWORD} -h ${DOLI_DB_HOST} -P ${DOLI_DB_HOST_PORT} ${DOLI_DB_NAME} < ${file} > /dev/null 2>&1 + elif [ "$isExec" == "PHP" ] ; then + php $file + elif [ "$isExec" == "SH" ] ; then + /bin/bash $file + fi + done + fi + + # Update ownership after initialisation of modules + chown -R www-data:www-data /var/www/documents } function migrateDatabase() diff --git a/images/16.0.5-php8.1/docker-init.php b/images/16.0.5-php8.1/docker-init.php index dc0dea8..1fe71a3 100644 --- a/images/16.0.5-php8.1/docker-init.php +++ b/images/16.0.5-php8.1/docker-init.php @@ -1,6 +1,46 @@ #!/usr/bin/env php init(); +require_once DOL_DOCUMENT_ROOT.'/core/lib/admin.lib.php'; + +printf("Activating module User... "); +activateModule('modUser'); +printf("OK\n"); + +if (!empty(getenv('DOLI_COMPANY_COUNTRYCODE'))) { + require_once DOL_DOCUMENT_ROOT.'/core/lib/company.lib.php'; + require_once DOL_DOCUMENT_ROOT.'/core/class/ccountry.class.php'; + $countryCode = getenv('DOLI_COMPANY_COUNTRYCODE'); + $country = new Ccountry($db); + $res = $country->fetch(0,$countryCode); + if ($res > 0 ) { + $s = $country->id.':'.$country->code.':'.$country->label; + dolibarr_set_const($db, "MAIN_INFO_SOCIETE_COUNTRY", $s, 'chaine', 0, '', $conf->entity); + printf('Configuring for country : '.$s."\n"); + activateModulesRequiredByCountry($country->code); + } else { + printf('Unable to find country '.$countryCode."\n"); + } +} + +if (!empty(getenv('DOLI_COMPANY_NAME'))) { + $compname = getenv('DOLI_COMPANY_NAME'); + dolibarr_set_const($db, "MAIN_INFO_SOCIETE_NOM", $compname, 'chaine', 0, '', $conf->entity); +} + +if (!empty(getenv('DOLI_ENABLE_MODULES'))) { + $mods = explode(',', getenv('DOLI_ENABLE_MODULES')); + foreach ($mods as $mod) { + printf("Activating module ".$mod." ..."); + try { + $res = activateModule('mod' . $mod); + if ($res < 0) { + print(" FAILED. Unable to load module. Be sure to check the case\n"); + } else { + printf(" OK\n"); + } + } catch (Throwable $t) { + print(" FAILED. Unable to load module. Be sure to check the case\n"); + } + } +} diff --git a/images/16.0.5-php8.1/docker-run.sh b/images/16.0.5-php8.1/docker-run.sh index 69e3e3d..9196c13 100755 --- a/images/16.0.5-php8.1/docker-run.sh +++ b/images/16.0.5-php8.1/docker-run.sh @@ -171,6 +171,29 @@ function initializeDatabase() echo "Enable user module ..." php /var/www/scripts/docker-init.php + + if [ -d /var/www/scripts/docker-init.d ] ; then + for file in /var/www/scripts/docker-init.d/*; do + [ ! -f $file ] && continue + + # If extension is not in PHP SQL SH, we loop + isExec=$(echo "PHP SQL SH" | grep -wio ${file##*.}) + [ -z "$isExec" ] && continue + + echo "Importing custom ${isExec} from `basename ${file}` ..." + if [ "$isExec" == "SQL" ] ; then + sed -i 's/--.*//g;' ${file} + mysql -u ${DOLI_DB_USER} -p${DOLI_DB_PASSWORD} -h ${DOLI_DB_HOST} -P ${DOLI_DB_HOST_PORT} ${DOLI_DB_NAME} < ${file} > /dev/null 2>&1 + elif [ "$isExec" == "PHP" ] ; then + php $file + elif [ "$isExec" == "SH" ] ; then + /bin/bash $file + fi + done + fi + + # Update ownership after initialisation of modules + chown -R www-data:www-data /var/www/documents } function migrateDatabase() diff --git a/images/17.0.3-php8.1/docker-init.php b/images/17.0.3-php8.1/docker-init.php deleted file mode 100644 index dc0dea8..0000000 --- a/images/17.0.3-php8.1/docker-init.php +++ /dev/null @@ -1,6 +0,0 @@ -#!/usr/bin/env php -init(); diff --git a/images/17.0.3-php8.1/Dockerfile b/images/17.0.4-php8.1/Dockerfile similarity index 99% rename from images/17.0.3-php8.1/Dockerfile rename to images/17.0.4-php8.1/Dockerfile index ba6563e..425db8e 100644 --- a/images/17.0.3-php8.1/Dockerfile +++ b/images/17.0.4-php8.1/Dockerfile @@ -4,7 +4,7 @@ FROM ${ARCH}php:8.1-apache-buster LABEL maintainer="Garcia MICHEL " -ENV DOLI_VERSION 17.0.3 +ENV DOLI_VERSION 17.0.4 ENV DOLI_INSTALL_AUTO 1 ENV DOLI_PROD 1 diff --git a/images/17.0.4-php8.1/docker-init.php b/images/17.0.4-php8.1/docker-init.php new file mode 100644 index 0000000..1fe71a3 --- /dev/null +++ b/images/17.0.4-php8.1/docker-init.php @@ -0,0 +1,46 @@ +#!/usr/bin/env php +fetch(0,$countryCode); + if ($res > 0 ) { + $s = $country->id.':'.$country->code.':'.$country->label; + dolibarr_set_const($db, "MAIN_INFO_SOCIETE_COUNTRY", $s, 'chaine', 0, '', $conf->entity); + printf('Configuring for country : '.$s."\n"); + activateModulesRequiredByCountry($country->code); + } else { + printf('Unable to find country '.$countryCode."\n"); + } +} + +if (!empty(getenv('DOLI_COMPANY_NAME'))) { + $compname = getenv('DOLI_COMPANY_NAME'); + dolibarr_set_const($db, "MAIN_INFO_SOCIETE_NOM", $compname, 'chaine', 0, '', $conf->entity); +} + +if (!empty(getenv('DOLI_ENABLE_MODULES'))) { + $mods = explode(',', getenv('DOLI_ENABLE_MODULES')); + foreach ($mods as $mod) { + printf("Activating module ".$mod." ..."); + try { + $res = activateModule('mod' . $mod); + if ($res < 0) { + print(" FAILED. Unable to load module. Be sure to check the case\n"); + } else { + printf(" OK\n"); + } + } catch (Throwable $t) { + print(" FAILED. Unable to load module. Be sure to check the case\n"); + } + } +} diff --git a/images/18.0.2-php8.1/docker-run.sh b/images/17.0.4-php8.1/docker-run.sh similarity index 93% rename from images/18.0.2-php8.1/docker-run.sh rename to images/17.0.4-php8.1/docker-run.sh index 69e3e3d..9196c13 100755 --- a/images/18.0.2-php8.1/docker-run.sh +++ b/images/17.0.4-php8.1/docker-run.sh @@ -171,6 +171,29 @@ function initializeDatabase() echo "Enable user module ..." php /var/www/scripts/docker-init.php + + if [ -d /var/www/scripts/docker-init.d ] ; then + for file in /var/www/scripts/docker-init.d/*; do + [ ! -f $file ] && continue + + # If extension is not in PHP SQL SH, we loop + isExec=$(echo "PHP SQL SH" | grep -wio ${file##*.}) + [ -z "$isExec" ] && continue + + echo "Importing custom ${isExec} from `basename ${file}` ..." + if [ "$isExec" == "SQL" ] ; then + sed -i 's/--.*//g;' ${file} + mysql -u ${DOLI_DB_USER} -p${DOLI_DB_PASSWORD} -h ${DOLI_DB_HOST} -P ${DOLI_DB_HOST_PORT} ${DOLI_DB_NAME} < ${file} > /dev/null 2>&1 + elif [ "$isExec" == "PHP" ] ; then + php $file + elif [ "$isExec" == "SH" ] ; then + /bin/bash $file + fi + done + fi + + # Update ownership after initialisation of modules + chown -R www-data:www-data /var/www/documents } function migrateDatabase() diff --git a/images/18.0.2-php8.1/docker-init.php b/images/18.0.2-php8.1/docker-init.php deleted file mode 100644 index dc0dea8..0000000 --- a/images/18.0.2-php8.1/docker-init.php +++ /dev/null @@ -1,6 +0,0 @@ -#!/usr/bin/env php -init(); diff --git a/images/18.0.2-php8.1/Dockerfile b/images/18.0.5-php8.1/Dockerfile similarity index 99% rename from images/18.0.2-php8.1/Dockerfile rename to images/18.0.5-php8.1/Dockerfile index dbab309..d6480a3 100644 --- a/images/18.0.2-php8.1/Dockerfile +++ b/images/18.0.5-php8.1/Dockerfile @@ -4,7 +4,7 @@ FROM ${ARCH}php:8.1-apache-buster LABEL maintainer="Garcia MICHEL " -ENV DOLI_VERSION 18.0.2 +ENV DOLI_VERSION 18.0.5 ENV DOLI_INSTALL_AUTO 1 ENV DOLI_PROD 1 diff --git a/images/18.0.5-php8.1/docker-init.php b/images/18.0.5-php8.1/docker-init.php new file mode 100644 index 0000000..1fe71a3 --- /dev/null +++ b/images/18.0.5-php8.1/docker-init.php @@ -0,0 +1,46 @@ +#!/usr/bin/env php +fetch(0,$countryCode); + if ($res > 0 ) { + $s = $country->id.':'.$country->code.':'.$country->label; + dolibarr_set_const($db, "MAIN_INFO_SOCIETE_COUNTRY", $s, 'chaine', 0, '', $conf->entity); + printf('Configuring for country : '.$s."\n"); + activateModulesRequiredByCountry($country->code); + } else { + printf('Unable to find country '.$countryCode."\n"); + } +} + +if (!empty(getenv('DOLI_COMPANY_NAME'))) { + $compname = getenv('DOLI_COMPANY_NAME'); + dolibarr_set_const($db, "MAIN_INFO_SOCIETE_NOM", $compname, 'chaine', 0, '', $conf->entity); +} + +if (!empty(getenv('DOLI_ENABLE_MODULES'))) { + $mods = explode(',', getenv('DOLI_ENABLE_MODULES')); + foreach ($mods as $mod) { + printf("Activating module ".$mod." ..."); + try { + $res = activateModule('mod' . $mod); + if ($res < 0) { + print(" FAILED. Unable to load module. Be sure to check the case\n"); + } else { + printf(" OK\n"); + } + } catch (Throwable $t) { + print(" FAILED. Unable to load module. Be sure to check the case\n"); + } + } +} diff --git a/images/17.0.3-php8.1/docker-run.sh b/images/18.0.5-php8.1/docker-run.sh similarity index 93% rename from images/17.0.3-php8.1/docker-run.sh rename to images/18.0.5-php8.1/docker-run.sh index 69e3e3d..9196c13 100755 --- a/images/17.0.3-php8.1/docker-run.sh +++ b/images/18.0.5-php8.1/docker-run.sh @@ -171,6 +171,29 @@ function initializeDatabase() echo "Enable user module ..." php /var/www/scripts/docker-init.php + + if [ -d /var/www/scripts/docker-init.d ] ; then + for file in /var/www/scripts/docker-init.d/*; do + [ ! -f $file ] && continue + + # If extension is not in PHP SQL SH, we loop + isExec=$(echo "PHP SQL SH" | grep -wio ${file##*.}) + [ -z "$isExec" ] && continue + + echo "Importing custom ${isExec} from `basename ${file}` ..." + if [ "$isExec" == "SQL" ] ; then + sed -i 's/--.*//g;' ${file} + mysql -u ${DOLI_DB_USER} -p${DOLI_DB_PASSWORD} -h ${DOLI_DB_HOST} -P ${DOLI_DB_HOST_PORT} ${DOLI_DB_NAME} < ${file} > /dev/null 2>&1 + elif [ "$isExec" == "PHP" ] ; then + php $file + elif [ "$isExec" == "SH" ] ; then + /bin/bash $file + fi + done + fi + + # Update ownership after initialisation of modules + chown -R www-data:www-data /var/www/documents } function migrateDatabase() diff --git a/images/19.0.2-php8.2/Dockerfile b/images/19.0.2-php8.2/Dockerfile new file mode 100644 index 0000000..2351c94 --- /dev/null +++ b/images/19.0.2-php8.2/Dockerfile @@ -0,0 +1,94 @@ +ARG ARCH= + +FROM ${ARCH}php:8.2-apache-buster + +LABEL maintainer="Garcia MICHEL " + +ENV DOLI_VERSION 19.0.2 +ENV DOLI_INSTALL_AUTO 1 +ENV DOLI_PROD 1 + +ENV DOLI_DB_TYPE mysqli +ENV DOLI_DB_HOST mysql +ENV DOLI_DB_HOST_PORT 3306 +ENV DOLI_DB_NAME dolidb + +ENV DOLI_URL_ROOT 'http://localhost' +ENV DOLI_NOCSRFCHECK 0 + +ENV DOLI_AUTH dolibarr +ENV DOLI_LDAP_HOST 127.0.0.1 +ENV DOLI_LDAP_PORT 389 +ENV DOLI_LDAP_VERSION 3 +ENV DOLI_LDAP_SERVER_TYPE openldap +ENV DOLI_LDAP_LOGIN_ATTRIBUTE uid +ENV DOLI_LDAP_DN 'ou=users,dc=my-domain,dc=com' +ENV DOLI_LDAP_FILTER '' +ENV DOLI_LDAP_BIND_DN '' +ENV DOLI_LDAP_BIND_PASS '' +ENV DOLI_LDAP_DEBUG false + +ENV DOLI_CRON 0 + +ENV WWW_USER_ID 33 +ENV WWW_GROUP_ID 33 + +ENV PHP_INI_DATE_TIMEZONE 'UTC' +ENV PHP_INI_MEMORY_LIMIT 256M +ENV PHP_INI_UPLOAD_MAX_FILESIZE 2M +ENV PHP_INI_POST_MAX_SIZE 8M +ENV PHP_INI_ALLOW_URL_FOPEN 0 + +RUN sed -i \ + -e 's/^\(ServerSignature On\)$/#\1/g' \ + -e 's/^#\(ServerSignature Off\)$/\1/g' \ + -e 's/^\(ServerTokens\) OS$/\1 Prod/g' \ + /etc/apache2/conf-available/security.conf + +RUN apt-get update -y \ + && apt-get dist-upgrade -y \ + && apt-get install -y --no-install-recommends \ + libc-client-dev \ + libfreetype6-dev \ + libjpeg62-turbo-dev \ + libkrb5-dev \ + libldap2-dev \ + libpng-dev \ + libpq-dev \ + libxml2-dev \ + libzip-dev \ + default-mysql-client \ + postgresql-client \ + cron \ + && apt-get autoremove -y \ + && docker-php-ext-configure gd --with-freetype --with-jpeg \ + && docker-php-ext-install -j$(nproc) calendar intl mysqli pdo_mysql gd soap zip \ + && docker-php-ext-configure pgsql -with-pgsql \ + && docker-php-ext-install pdo_pgsql pgsql \ + && docker-php-ext-configure ldap --with-libdir=lib/$(gcc -dumpmachine)/ \ + && docker-php-ext-install -j$(nproc) ldap \ + && docker-php-ext-configure imap --with-kerberos --with-imap-ssl \ + && docker-php-ext-install imap \ + && mv ${PHP_INI_DIR}/php.ini-production ${PHP_INI_DIR}/php.ini \ + && rm -rf /var/lib/apt/lists/* + +# Get Dolibarr +RUN curl -fLSs https://github.com/Dolibarr/dolibarr/archive/${DOLI_VERSION}.tar.gz |\ + tar -C /tmp -xz && \ + cp -r /tmp/dolibarr-${DOLI_VERSION}/htdocs/* /var/www/html/ && \ + ln -s /var/www/html /var/www/htdocs && \ + cp -r /tmp/dolibarr-${DOLI_VERSION}/scripts /var/www/ && \ + rm -rf /tmp/* && \ + mkdir -p /var/www/documents && \ + mkdir -p /var/www/html/custom && \ + chown -R www-data:www-data /var/www + +EXPOSE 80 +VOLUME /var/www/documents +VOLUME /var/www/html/custom + +COPY docker-init.php /var/www/scripts/ +COPY docker-run.sh /usr/local/bin/ +ENTRYPOINT ["docker-run.sh"] + +CMD ["apache2-foreground"] diff --git a/images/19.0.2-php8.2/docker-init.php b/images/19.0.2-php8.2/docker-init.php new file mode 100644 index 0000000..1fe71a3 --- /dev/null +++ b/images/19.0.2-php8.2/docker-init.php @@ -0,0 +1,46 @@ +#!/usr/bin/env php +fetch(0,$countryCode); + if ($res > 0 ) { + $s = $country->id.':'.$country->code.':'.$country->label; + dolibarr_set_const($db, "MAIN_INFO_SOCIETE_COUNTRY", $s, 'chaine', 0, '', $conf->entity); + printf('Configuring for country : '.$s."\n"); + activateModulesRequiredByCountry($country->code); + } else { + printf('Unable to find country '.$countryCode."\n"); + } +} + +if (!empty(getenv('DOLI_COMPANY_NAME'))) { + $compname = getenv('DOLI_COMPANY_NAME'); + dolibarr_set_const($db, "MAIN_INFO_SOCIETE_NOM", $compname, 'chaine', 0, '', $conf->entity); +} + +if (!empty(getenv('DOLI_ENABLE_MODULES'))) { + $mods = explode(',', getenv('DOLI_ENABLE_MODULES')); + foreach ($mods as $mod) { + printf("Activating module ".$mod." ..."); + try { + $res = activateModule('mod' . $mod); + if ($res < 0) { + print(" FAILED. Unable to load module. Be sure to check the case\n"); + } else { + printf(" OK\n"); + } + } catch (Throwable $t) { + print(" FAILED. Unable to load module. Be sure to check the case\n"); + } + } +} diff --git a/images/19.0.2-php8.2/docker-run.sh b/images/19.0.2-php8.2/docker-run.sh new file mode 100755 index 0000000..9196c13 --- /dev/null +++ b/images/19.0.2-php8.2/docker-run.sh @@ -0,0 +1,284 @@ +#!/bin/bash + +# usage: get_env_value VAR [DEFAULT] +# ie: get_env_value 'XYZ_DB_PASSWORD' 'example' +# (will allow for "$XYZ_DB_PASSWORD_FILE" to fill in the value of +# "$XYZ_DB_PASSWORD" from a file, especially for Docker's secrets feature) +function get_env_value() { + local varName="${1}" + local fileVarName="${varName}_FILE" + local defaultValue="${2:-}" + + if [ "${!varName:-}" ] && [ "${!fileVarName:-}" ]; then + echo >&2 "error: both ${varName} and ${fileVarName} are set (but are exclusive)" + exit 1 + fi + + local value="${defaultValue}" + if [ "${!varName:-}" ]; then + value="${!varName}" + elif [ "${!fileVarName:-}" ]; then + value="$(< "${!fileVarName}")" + fi + + echo ${value} + exit 0 +} + +function initDolibarr() +{ + local CURRENT_UID=$(id -u www-data) + local CURRENT_GID=$(id -g www-data) + usermod -u ${WWW_USER_ID} www-data + groupmod -g ${WWW_GROUP_ID} www-data + + if [[ ! -d /var/www/documents ]]; then + echo "[INIT] => create volume directory /var/www/documents ..." + mkdir -p /var/www/documents + fi + + echo "[INIT] => update PHP Config ..." + cat > ${PHP_INI_DIR}/conf.d/dolibarr-php.ini << EOF +date.timezone = ${PHP_INI_DATE_TIMEZONE} +sendmail_path = /usr/sbin/sendmail -t -i +memory_limit = ${PHP_INI_MEMORY_LIMIT} +upload_max_filesize = ${PHP_INI_UPLOAD_MAX_FILESIZE} +post_max_size = ${PHP_INI_POST_MAX_SIZE} +allow_url_fopen = ${PHP_INI_ALLOW_URL_FOPEN} +session.use_strict_mode = 1 +disable_functions = pcntl_alarm,pcntl_fork,pcntl_waitpid,pcntl_wait,pcntl_wifexited,pcntl_wifstopped,pcntl_wifsignaled,pcntl_wifcontinued,pcntl_wexitstatus,pcntl_wtermsig,pcntl_wstopsig,pcntl_signal,pcntl_signal_get_handler,pcntl_signal_dispatch,pcntl_get_last_error,pcntl_strerror,pcntl_sigprocmask,pcntl_sigwaitinfo,pcntl_sigtimedwait,pcntl_exec,pcntl_getpriority,pcntl_setpriority,pcntl_async_signals,passthru,shell_exec,system,proc_open,popen +EOF + +if [[ ! -f /var/www/html/conf/conf.php ]]; then + echo "[INIT] => update Dolibarr Config ..." + cat > /var/www/html/conf/conf.php << EOF + update Dolibarr Config with instance unique id ..." + echo "\$dolibarr_main_instance_unique_id='${DOLI_INSTANCE_UNIQUE_ID}';" >> /var/www/html/conf/conf.php + fi + if [[ ${DOLI_AUTH} =~ .*ldap.* ]]; then + echo "[INIT] => update Dolibarr Config with LDAP entries ..." + cat >> /var/www/html/conf/conf.php << EOF +\$dolibarr_main_auth_ldap_host='${DOLI_LDAP_HOST}'; +\$dolibarr_main_auth_ldap_port='${DOLI_LDAP_PORT}'; +\$dolibarr_main_auth_ldap_version='${DOLI_LDAP_VERSION}'; +\$dolibarr_main_auth_ldap_servertype='${DOLI_LDAP_SERVER_TYPE}'; +\$dolibarr_main_auth_ldap_login_attribute='${DOLI_LDAP_LOGIN_ATTRIBUTE}'; +\$dolibarr_main_auth_ldap_dn='${DOLI_LDAP_DN}'; +\$dolibarr_main_auth_ldap_filter='${DOLI_LDAP_FILTER}'; +\$dolibarr_main_auth_ldap_admin_login='${DOLI_LDAP_BIND_DN}'; +\$dolibarr_main_auth_ldap_admin_pass='${DOLI_LDAP_BIND_PASS}'; +\$dolibarr_main_auth_ldap_debug='${DOLI_LDAP_DEBUG}'; +EOF + fi + fi + + echo "[INIT] => update ownership for file in Dolibarr Config ..." + chown www-data:www-data /var/www/html/conf/conf.php + if [[ ${DOLI_DB_TYPE} == "pgsql" && ! -f /var/www/documents/install.lock ]]; then + chmod 600 /var/www/html/conf/conf.php + else + chmod 400 /var/www/html/conf/conf.php + fi + + if [[ ${CURRENT_UID} -ne ${WWW_USER_ID} || ${CURRENT_GID} -ne ${WWW_GROUP_ID} ]]; then + # Refresh file ownership cause it has changed + echo "[INIT] => As UID / GID have changed from default, update ownership for files in /var/ww ..." + chown -R www-data:www-data /var/www + else + # Reducing load on init : change ownership only for volumes declared in docker + echo "[INIT] => update ownership for files in /var/www/documents ..." + chown -R www-data:www-data /var/www/documents + fi +} + +function waitForDataBase() +{ + r=1 + + while [[ ${r} -ne 0 ]]; do + mysql -u ${DOLI_DB_USER} --protocol tcp -p${DOLI_DB_PASSWORD} -h ${DOLI_DB_HOST} -P ${DOLI_DB_HOST_PORT} --connect-timeout=5 -e "status" > /dev/null 2>&1 + r=$? + if [[ ${r} -ne 0 ]]; then + echo "Waiting that SQL database is up ..." + sleep 2 + fi + done +} + +function lockInstallation() +{ + touch /var/www/documents/install.lock + chown www-data:www-data /var/www/documents/install.lock + chmod 400 /var/www/documents/install.lock +} + +function initializeDatabase() +{ + for fileSQL in /var/www/html/install/mysql/tables/*.sql; do + if [[ ${fileSQL} != *.key.sql ]]; then + echo "Importing table from `basename ${fileSQL}` ..." + sed -i 's/--.*//g;' ${fileSQL} # remove all comment + mysql -u ${DOLI_DB_USER} -p${DOLI_DB_PASSWORD} -h ${DOLI_DB_HOST} -P ${DOLI_DB_HOST_PORT} ${DOLI_DB_NAME} < ${fileSQL} + fi + done + + for fileSQL in /var/www/html/install/mysql/tables/*.key.sql; do + echo "Importing table key from `basename ${fileSQL}` ..." + sed -i 's/--.*//g;' ${fileSQL} + mysql -u ${DOLI_DB_USER} -p${DOLI_DB_PASSWORD} -h ${DOLI_DB_HOST} -P ${DOLI_DB_HOST_PORT} ${DOLI_DB_NAME} < ${fileSQL} > /dev/null 2>&1 + done + + for fileSQL in /var/www/html/install/mysql/functions/*.sql; do + echo "Importing `basename ${fileSQL}` ..." + sed -i 's/--.*//g;' ${fileSQL} + mysql -u ${DOLI_DB_USER} -p${DOLI_DB_PASSWORD} -h ${DOLI_DB_HOST} -P ${DOLI_DB_HOST_PORT} ${DOLI_DB_NAME} < ${fileSQL} > /dev/null 2>&1 + done + + for fileSQL in /var/www/html/install/mysql/data/*.sql; do + echo "Importing data from `basename ${fileSQL}` ..." + sed -i 's/--.*//g;' ${fileSQL} + mysql -u ${DOLI_DB_USER} -p${DOLI_DB_PASSWORD} -h ${DOLI_DB_HOST} -P ${DOLI_DB_HOST_PORT} ${DOLI_DB_NAME} < ${fileSQL} > /dev/null 2>&1 + done + + echo "Create SuperAdmin account ..." + pass_crypted=`echo -n ${DOLI_ADMIN_PASSWORD} | md5sum | awk '{print $1}'` + mysql -u ${DOLI_DB_USER} -p${DOLI_DB_PASSWORD} -h ${DOLI_DB_HOST} -P ${DOLI_DB_HOST_PORT} ${DOLI_DB_NAME} -e "INSERT INTO llx_user (entity, login, pass_crypted, lastname, admin, statut) VALUES (0, '${DOLI_ADMIN_LOGIN}', '${pass_crypted}', 'SuperAdmin', 1, 1);" > /dev/null 2>&1 + + echo "Set some default const ..." + mysql -u ${DOLI_DB_USER} -p${DOLI_DB_PASSWORD} -h ${DOLI_DB_HOST} -P ${DOLI_DB_HOST_PORT} ${DOLI_DB_NAME} -e "DELETE FROM llx_const WHERE name='MAIN_VERSION_LAST_INSTALL';" > /dev/null 2>&1 + mysql -u ${DOLI_DB_USER} -p${DOLI_DB_PASSWORD} -h ${DOLI_DB_HOST} -P ${DOLI_DB_HOST_PORT} ${DOLI_DB_NAME} -e "DELETE FROM llx_const WHERE name='MAIN_NOT_INSTALLED';" > /dev/null 2>&1 + mysql -u ${DOLI_DB_USER} -p${DOLI_DB_PASSWORD} -h ${DOLI_DB_HOST} -P ${DOLI_DB_HOST_PORT} ${DOLI_DB_NAME} -e "DELETE FROM llx_const WHERE name='MAIN_LANG_DEFAULT';" > /dev/null 2>&1 + mysql -u ${DOLI_DB_USER} -p${DOLI_DB_PASSWORD} -h ${DOLI_DB_HOST} -P ${DOLI_DB_HOST_PORT} ${DOLI_DB_NAME} -e "INSERT INTO llx_const(name,value,type,visible,note,entity) values('MAIN_VERSION_LAST_INSTALL', '${DOLI_VERSION}', 'chaine', 0, 'Dolibarr version when install', 0);" > /dev/null 2>&1 + mysql -u ${DOLI_DB_USER} -p${DOLI_DB_PASSWORD} -h ${DOLI_DB_HOST} -P ${DOLI_DB_HOST_PORT} ${DOLI_DB_NAME} -e "INSERT INTO llx_const(name,value,type,visible,note,entity) VALUES ('MAIN_LANG_DEFAULT', 'auto', 'chaine', 0, 'Default language', 1);" > /dev/null 2>&1 + mysql -u ${DOLI_DB_USER} -p${DOLI_DB_PASSWORD} -h ${DOLI_DB_HOST} -P ${DOLI_DB_HOST_PORT} ${DOLI_DB_NAME} -e "INSERT INTO llx_const(name,value,type,visible,note,entity) VALUES ('SYSTEMTOOLS_MYSQLDUMP', '/usr/bin/mysqldump', 'chaine', 0, '', 0);" > /dev/null 2>&1 + + echo "Enable user module ..." + php /var/www/scripts/docker-init.php + + if [ -d /var/www/scripts/docker-init.d ] ; then + for file in /var/www/scripts/docker-init.d/*; do + [ ! -f $file ] && continue + + # If extension is not in PHP SQL SH, we loop + isExec=$(echo "PHP SQL SH" | grep -wio ${file##*.}) + [ -z "$isExec" ] && continue + + echo "Importing custom ${isExec} from `basename ${file}` ..." + if [ "$isExec" == "SQL" ] ; then + sed -i 's/--.*//g;' ${file} + mysql -u ${DOLI_DB_USER} -p${DOLI_DB_PASSWORD} -h ${DOLI_DB_HOST} -P ${DOLI_DB_HOST_PORT} ${DOLI_DB_NAME} < ${file} > /dev/null 2>&1 + elif [ "$isExec" == "PHP" ] ; then + php $file + elif [ "$isExec" == "SH" ] ; then + /bin/bash $file + fi + done + fi + + # Update ownership after initialisation of modules + chown -R www-data:www-data /var/www/documents +} + +function migrateDatabase() +{ + TARGET_VERSION="$(echo ${DOLI_VERSION} | cut -d. -f1).$(echo ${DOLI_VERSION} | cut -d. -f2).0" + echo "Schema update is required ..." + echo "Dumping Database into /var/www/documents/dump.sql ..." + + mysqldump -u ${DOLI_DB_USER} -p${DOLI_DB_PASSWORD} -h ${DOLI_DB_HOST} -P ${DOLI_DB_HOST_PORT} ${DOLI_DB_NAME} > /var/www/documents/dump.sql + r=${?} + if [[ ${r} -ne 0 ]]; then + echo "Dump failed ... Aborting migration ..." + return ${r} + fi + echo "Dump done ... Starting Migration ..." + + echo "" > /var/www/documents/migration_error.html + pushd /var/www/htdocs/install > /dev/null + php upgrade.php ${INSTALLED_VERSION} ${TARGET_VERSION} >> /var/www/documents/migration_error.html 2>&1 && \ + php upgrade2.php ${INSTALLED_VERSION} ${TARGET_VERSION} >> /var/www/documents/migration_error.html 2>&1 && \ + php step5.php ${INSTALLED_VERSION} ${TARGET_VERSION} >> /var/www/documents/migration_error.html 2>&1 + r=$? + popd > /dev/null + + if [[ ${r} -ne 0 ]]; then + echo "Migration failed ... Restoring DB ... check file /var/www/documents/migration_error.html for more info on error ..." + mysql -u ${DOLI_DB_USER} -p${DOLI_DB_PASSWORD} -h ${DOLI_DB_HOST} -P ${DOLI_DB_HOST_PORT} ${DOLI_DB_NAME} < /var/www/documents/dump.sql + echo "DB Restored ..." + return ${r} + else + echo "Migration successful ... Enjoy !!" + fi + + return 0 +} + +function run() +{ + initDolibarr + echo "Current Version is : ${DOLI_VERSION}" + + if [[ ${DOLI_INSTALL_AUTO} -eq 1 && ${DOLI_CRON} -ne 1 && ! -f /var/www/documents/install.lock && ${DOLI_DB_TYPE} != "pgsql" ]]; then + waitForDataBase + + mysql -u ${DOLI_DB_USER} -p${DOLI_DB_PASSWORD} -h ${DOLI_DB_HOST} -P ${DOLI_DB_HOST_PORT} ${DOLI_DB_NAME} -e "SELECT Q.LAST_INSTALLED_VERSION FROM (SELECT INET_ATON(CONCAT(value, REPEAT('.0', 3 - CHAR_LENGTH(value) + CHAR_LENGTH(REPLACE(value, '.', ''))))) as VERSION_ATON, value as LAST_INSTALLED_VERSION FROM llx_const WHERE name IN ('MAIN_VERSION_LAST_INSTALL', 'MAIN_VERSION_LAST_UPGRADE') and entity=0) Q ORDER BY VERSION_ATON DESC LIMIT 1" > /tmp/lastinstall.result 2>&1 + r=$? + if [[ ${r} -ne 0 ]]; then + initializeDatabase + else + INSTALLED_VERSION=`grep -v LAST_INSTALLED_VERSION /tmp/lastinstall.result` + echo "Last installed Version is : ${INSTALLED_VERSION}" + if [[ "$(echo ${INSTALLED_VERSION} | cut -d. -f1)" -lt "$(echo ${DOLI_VERSION} | cut -d. -f1)" ]]; then + migrateDatabase + else + echo "Schema update is not required ... Enjoy !!" + fi + fi + + if [[ ${DOLI_VERSION} != "develop" ]]; then + lockInstallation + fi + fi +} + +DOLI_DB_USER=$(get_env_value 'DOLI_DB_USER' 'doli') +DOLI_DB_PASSWORD=$(get_env_value 'DOLI_DB_PASSWORD' 'doli_pass') +DOLI_ADMIN_LOGIN=$(get_env_value 'DOLI_ADMIN_LOGIN' 'admin') +DOLI_ADMIN_PASSWORD=$(get_env_value 'DOLI_ADMIN_PASSWORD' 'admin') +DOLI_CRON_KEY=$(get_env_value 'DOLI_CRON_KEY' '') +DOLI_CRON_USER=$(get_env_value 'DOLI_CRON_USER' '') +DOLI_INSTANCE_UNIQUE_ID=$(get_env_value 'DOLI_INSTANCE_UNIQUE_ID' '') + +run + +set -e + +if [[ ${DOLI_CRON} -eq 1 ]]; then + echo "PATH=\$PATH:/usr/local/bin" > /etc/cron.d/dolibarr + echo "*/5 * * * * root /bin/su www-data -s /bin/sh -c '/var/www/scripts/cron/cron_run_jobs.php ${DOLI_CRON_KEY} ${DOLI_CRON_USER}' > /proc/1/fd/1 2> /proc/1/fd/2" >> /etc/cron.d/dolibarr + cron -f + exit 0 +fi + +if [ "${1#-}" != "$1" ]; then + set -- apache2-foreground "$@" +fi + +exec "$@" diff --git a/images/develop/Dockerfile b/images/develop/Dockerfile index 4d54df5..51c7e91 100644 --- a/images/develop/Dockerfile +++ b/images/develop/Dockerfile @@ -1,6 +1,6 @@ ARG ARCH= -FROM ${ARCH}php:8.1-apache-buster +FROM ${ARCH}php:8.2-apache-buster LABEL maintainer="Garcia MICHEL " diff --git a/images/develop/docker-init.php b/images/develop/docker-init.php index dc0dea8..1fe71a3 100644 --- a/images/develop/docker-init.php +++ b/images/develop/docker-init.php @@ -1,6 +1,46 @@ #!/usr/bin/env php init(); +require_once DOL_DOCUMENT_ROOT.'/core/lib/admin.lib.php'; + +printf("Activating module User... "); +activateModule('modUser'); +printf("OK\n"); + +if (!empty(getenv('DOLI_COMPANY_COUNTRYCODE'))) { + require_once DOL_DOCUMENT_ROOT.'/core/lib/company.lib.php'; + require_once DOL_DOCUMENT_ROOT.'/core/class/ccountry.class.php'; + $countryCode = getenv('DOLI_COMPANY_COUNTRYCODE'); + $country = new Ccountry($db); + $res = $country->fetch(0,$countryCode); + if ($res > 0 ) { + $s = $country->id.':'.$country->code.':'.$country->label; + dolibarr_set_const($db, "MAIN_INFO_SOCIETE_COUNTRY", $s, 'chaine', 0, '', $conf->entity); + printf('Configuring for country : '.$s."\n"); + activateModulesRequiredByCountry($country->code); + } else { + printf('Unable to find country '.$countryCode."\n"); + } +} + +if (!empty(getenv('DOLI_COMPANY_NAME'))) { + $compname = getenv('DOLI_COMPANY_NAME'); + dolibarr_set_const($db, "MAIN_INFO_SOCIETE_NOM", $compname, 'chaine', 0, '', $conf->entity); +} + +if (!empty(getenv('DOLI_ENABLE_MODULES'))) { + $mods = explode(',', getenv('DOLI_ENABLE_MODULES')); + foreach ($mods as $mod) { + printf("Activating module ".$mod." ..."); + try { + $res = activateModule('mod' . $mod); + if ($res < 0) { + print(" FAILED. Unable to load module. Be sure to check the case\n"); + } else { + printf(" OK\n"); + } + } catch (Throwable $t) { + print(" FAILED. Unable to load module. Be sure to check the case\n"); + } + } +} diff --git a/images/develop/docker-run.sh b/images/develop/docker-run.sh index 69e3e3d..9196c13 100755 --- a/images/develop/docker-run.sh +++ b/images/develop/docker-run.sh @@ -171,6 +171,29 @@ function initializeDatabase() echo "Enable user module ..." php /var/www/scripts/docker-init.php + + if [ -d /var/www/scripts/docker-init.d ] ; then + for file in /var/www/scripts/docker-init.d/*; do + [ ! -f $file ] && continue + + # If extension is not in PHP SQL SH, we loop + isExec=$(echo "PHP SQL SH" | grep -wio ${file##*.}) + [ -z "$isExec" ] && continue + + echo "Importing custom ${isExec} from `basename ${file}` ..." + if [ "$isExec" == "SQL" ] ; then + sed -i 's/--.*//g;' ${file} + mysql -u ${DOLI_DB_USER} -p${DOLI_DB_PASSWORD} -h ${DOLI_DB_HOST} -P ${DOLI_DB_HOST_PORT} ${DOLI_DB_NAME} < ${file} > /dev/null 2>&1 + elif [ "$isExec" == "PHP" ] ; then + php $file + elif [ "$isExec" == "SH" ] ; then + /bin/bash $file + fi + done + fi + + # Update ownership after initialisation of modules + chown -R www-data:www-data /var/www/documents } function migrateDatabase() diff --git a/update.sh b/update.sh index 8eebec3..6018b17 100755 --- a/update.sh +++ b/update.sh @@ -27,7 +27,9 @@ for dolibarrVersion in "${DOLIBARR_VERSIONS[@]}"; do # Mapping version according https://wiki.dolibarr.org/index.php/Versions # Regarding PHP Supported version : https://www.php.net/supported-versions.php - if [ "${dolibarrVersion}" = "develop" ] || [ "${dolibarrMajor}" -ge "16" ]; then + if [ "${dolibarrVersion}" = "develop" ] || [ "${dolibarrMajor}" -ge "19" ]; then + php_base_images=( "8.2-apache-buster" ) + elif [ "${dolibarrMajor}" -ge "16" ]; then php_base_images=( "8.1-apache-buster" ) else php_base_images=( "7.4-apache-buster" ) @@ -58,8 +60,8 @@ for dolibarrVersion in "${DOLIBARR_VERSIONS[@]}"; do sed 's/%DOLI_VERSION%/'"${dolibarrVersion}"'/;' \ > "${dir}/Dockerfile" - cp "${BASE_DIR}/docker-init.php" "${dir}/docker-init.php" - cp "${BASE_DIR}/docker-run.sh" "${dir}/docker-run.sh" + cp -a "${BASE_DIR}/docker-init.php" "${dir}/docker-init.php" + cp -a "${BASE_DIR}/docker-run.sh" "${dir}/docker-run.sh" if [ "${DOCKER_BUILD}" = "1" ]; then if [ "${DOCKER_PUSH}" = "1" ]; then diff --git a/versions.sh b/versions.sh index 4dc93d7..d21a328 100644 --- a/versions.sh +++ b/versions.sh @@ -2,5 +2,5 @@ set -e -DOLIBARR_VERSIONS=( "15.0.3" "16.0.5" "17.0.3" "18.0.2" "develop" ) -DOLIBARR_LATEST_TAG="18.0.2" +DOLIBARR_VERSIONS=("15.0.3" "16.0.5" "17.0.4" "18.0.5" "19.0.2" "develop") +DOLIBARR_LATEST_TAG="19.0.2"