Skip to content
This repository has been archived by the owner on Sep 15, 2024. It is now read-only.

Commit

Permalink
Add customs scripts via volume mount (#150)
Browse files Browse the repository at this point in the history
* docker-init.d

* Custom scripts in volume docker-init.d

* FIX Custom scripts in volume docker-init.d

---------

Co-authored-by: Vaadasch <[email protected]>
  • Loading branch information
Vaadasch and Vaadasch authored Apr 29, 2024
1 parent a36910e commit bf68e31
Show file tree
Hide file tree
Showing 16 changed files with 228 additions and 14 deletions.
37 changes: 37 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -139,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
```
37 changes: 37 additions & 0 deletions README.template
Original file line number Diff line number Diff line change
Expand Up @@ -133,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
```
4 changes: 2 additions & 2 deletions docker-init.php
Original file line number Diff line number Diff line change
Expand Up @@ -33,12 +33,12 @@
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);
printf('Configuring for country : '.$s."\n");
activateModulesRequiredByCountry($country->code);
$db->commit();
}
else {
printf('Unable to find country '.$countryCode);
printf('Unable to find country '.$countryCode."\n");
}
}

Expand Down
20 changes: 20 additions & 0 deletions docker-run.sh
Original file line number Diff line number Diff line change
Expand Up @@ -172,6 +172,26 @@ 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
}
Expand Down
4 changes: 2 additions & 2 deletions images/15.0.3-php7.4/docker-init.php
Original file line number Diff line number Diff line change
Expand Up @@ -33,12 +33,12 @@
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);
printf('Configuring for country : '.$s."\n");
activateModulesRequiredByCountry($country->code);
$db->commit();
}
else {
printf('Unable to find country '.$countryCode);
printf('Unable to find country '.$countryCode."\n");
}
}

Expand Down
20 changes: 20 additions & 0 deletions images/15.0.3-php7.4/docker-run.sh
Original file line number Diff line number Diff line change
Expand Up @@ -172,6 +172,26 @@ 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
}
Expand Down
4 changes: 2 additions & 2 deletions images/16.0.5-php8.1/docker-init.php
Original file line number Diff line number Diff line change
Expand Up @@ -33,12 +33,12 @@
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);
printf('Configuring for country : '.$s."\n");
activateModulesRequiredByCountry($country->code);
$db->commit();
}
else {
printf('Unable to find country '.$countryCode);
printf('Unable to find country '.$countryCode."\n");
}
}

Expand Down
20 changes: 20 additions & 0 deletions images/16.0.5-php8.1/docker-run.sh
Original file line number Diff line number Diff line change
Expand Up @@ -172,6 +172,26 @@ 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
}
Expand Down
4 changes: 2 additions & 2 deletions images/17.0.4-php8.1/docker-init.php
Original file line number Diff line number Diff line change
Expand Up @@ -33,12 +33,12 @@
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);
printf('Configuring for country : '.$s."\n");
activateModulesRequiredByCountry($country->code);
$db->commit();
}
else {
printf('Unable to find country '.$countryCode);
printf('Unable to find country '.$countryCode."\n");
}
}

Expand Down
20 changes: 20 additions & 0 deletions images/17.0.4-php8.1/docker-run.sh
Original file line number Diff line number Diff line change
Expand Up @@ -172,6 +172,26 @@ 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
}
Expand Down
4 changes: 2 additions & 2 deletions images/18.0.5-php8.1/docker-init.php
Original file line number Diff line number Diff line change
Expand Up @@ -33,12 +33,12 @@
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);
printf('Configuring for country : '.$s."\n");
activateModulesRequiredByCountry($country->code);
$db->commit();
}
else {
printf('Unable to find country '.$countryCode);
printf('Unable to find country '.$countryCode."\n");
}
}

Expand Down
20 changes: 20 additions & 0 deletions images/18.0.5-php8.1/docker-run.sh
Original file line number Diff line number Diff line change
Expand Up @@ -172,6 +172,26 @@ 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
}
Expand Down
4 changes: 2 additions & 2 deletions images/19.0.1-php8.2/docker-init.php
Original file line number Diff line number Diff line change
Expand Up @@ -33,12 +33,12 @@
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);
printf('Configuring for country : '.$s."\n");
activateModulesRequiredByCountry($country->code);
$db->commit();
}
else {
printf('Unable to find country '.$countryCode);
printf('Unable to find country '.$countryCode."\n");
}
}

Expand Down
20 changes: 20 additions & 0 deletions images/19.0.1-php8.2/docker-run.sh
Original file line number Diff line number Diff line change
Expand Up @@ -172,6 +172,26 @@ 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
}
Expand Down
4 changes: 2 additions & 2 deletions images/develop/docker-init.php
Original file line number Diff line number Diff line change
Expand Up @@ -33,12 +33,12 @@
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);
printf('Configuring for country : '.$s."\n");
activateModulesRequiredByCountry($country->code);
$db->commit();
}
else {
printf('Unable to find country '.$countryCode);
printf('Unable to find country '.$countryCode."\n");
}
}

Expand Down
20 changes: 20 additions & 0 deletions images/develop/docker-run.sh
Original file line number Diff line number Diff line change
Expand Up @@ -172,6 +172,26 @@ 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
}
Expand Down

0 comments on commit bf68e31

Please sign in to comment.