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

Commit

Permalink
FIX Custom scripts in volume docker-init.d
Browse files Browse the repository at this point in the history
  • Loading branch information
Vaadasch committed Apr 28, 2024
1 parent d5a6f24 commit 34658ed
Show file tree
Hide file tree
Showing 9 changed files with 127 additions and 110 deletions.
17 changes: 4 additions & 13 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -141,14 +141,12 @@ Environment variables that are compatible with docker secrets:
* `DOLI_INSTANCE_UNIQUE_ID` => `DOLI_INSTANCE_UNIQUE_ID_FILE`

## Add post-deployment scripts
It is possible to execute `*.sql` and `*.php` custom file at the end of deployment by mounting a volume with the following structure :
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
|-\sql
| |- custom_script.sql
|
|-\php
| |- custom_script.php
|- custom_script.sql
|- custom_script.php
|- custom_script.sh
```
Mount the volume with compose file :
Expand Down Expand Up @@ -178,10 +176,3 @@ services:
links:
- mariadb
```

or more specifically
```
volumes :
- volume-scripts-sql:/var/www/scripts/docker-init.d/sql
- volume-scripts-php:/var/www/scripts/docker-init.d/php
```
17 changes: 4 additions & 13 deletions README.template
Original file line number Diff line number Diff line change
Expand Up @@ -135,14 +135,12 @@ Environment variables that are compatible with docker secrets:
* `DOLI_INSTANCE_UNIQUE_ID` => `DOLI_INSTANCE_UNIQUE_ID_FILE`

## Add post-deployment scripts
It is possible to execute `*.sql` and `*.php` custom file at the end of deployment by mounting a volume with the following structure :
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
|-\sql
| |- custom_script.sql
|
|-\php
| |- custom_script.php
|- custom_script.sql
|- custom_script.php
|- custom_script.sh
```

Mount the volume with compose file :
Expand Down Expand Up @@ -172,10 +170,3 @@ services:
links:
- mariadb
```

or more specifically
```
volumes :
- volume-scripts-sql:/var/www/scripts/docker-init.d/sql
- volume-scripts-php:/var/www/scripts/docker-init.d/php
```
29 changes: 17 additions & 12 deletions docker-run.sh
Original file line number Diff line number Diff line change
Expand Up @@ -172,18 +172,23 @@ function initializeDatabase()
echo "Enable user module ..."
php /var/www/scripts/docker-init.php

if [ -d /var/www/scripts/docker-init.d/sql ] ; then
for fileSQL in /var/www/scripts/docker-init.d/sql/*.sql; do
[ ! -f $fileSQL ] && continue ;
echo "Importing custom SQL 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 filePHP in /var/www/scripts/docker-init.d/php/*.php; do
[ ! -f $filePHP ] && continue ;
echo "Executing custom PHP : `basename ${filePHP}` ..."
php $filePHP
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

Expand Down
29 changes: 17 additions & 12 deletions images/15.0.3-php7.4/docker-run.sh
Original file line number Diff line number Diff line change
Expand Up @@ -172,18 +172,23 @@ function initializeDatabase()
echo "Enable user module ..."
php /var/www/scripts/docker-init.php

if [ -d /var/www/scripts/docker-init.d/sql ] ; then
for fileSQL in /var/www/scripts/docker-init.d/sql/*.sql; do
[ ! -f $fileSQL ] && continue ;
echo "Importing custom SQL 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 filePHP in /var/www/scripts/docker-init.d/php/*.php; do
[ ! -f $filePHP ] && continue ;
echo "Executing custom PHP : `basename ${filePHP}` ..."
php $filePHP
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

Expand Down
29 changes: 17 additions & 12 deletions images/16.0.5-php8.1/docker-run.sh
Original file line number Diff line number Diff line change
Expand Up @@ -172,18 +172,23 @@ function initializeDatabase()
echo "Enable user module ..."
php /var/www/scripts/docker-init.php

if [ -d /var/www/scripts/docker-init.d/sql ] ; then
for fileSQL in /var/www/scripts/docker-init.d/sql/*.sql; do
[ ! -f $fileSQL ] && continue ;
echo "Importing custom SQL 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 filePHP in /var/www/scripts/docker-init.d/php/*.php; do
[ ! -f $filePHP ] && continue ;
echo "Executing custom PHP : `basename ${filePHP}` ..."
php $filePHP
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

Expand Down
29 changes: 17 additions & 12 deletions images/17.0.4-php8.1/docker-run.sh
Original file line number Diff line number Diff line change
Expand Up @@ -172,18 +172,23 @@ function initializeDatabase()
echo "Enable user module ..."
php /var/www/scripts/docker-init.php

if [ -d /var/www/scripts/docker-init.d/sql ] ; then
for fileSQL in /var/www/scripts/docker-init.d/sql/*.sql; do
[ ! -f $fileSQL ] && continue ;
echo "Importing custom SQL 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 filePHP in /var/www/scripts/docker-init.d/php/*.php; do
[ ! -f $filePHP ] && continue ;
echo "Executing custom PHP : `basename ${filePHP}` ..."
php $filePHP
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

Expand Down
29 changes: 17 additions & 12 deletions images/18.0.5-php8.1/docker-run.sh
Original file line number Diff line number Diff line change
Expand Up @@ -172,18 +172,23 @@ function initializeDatabase()
echo "Enable user module ..."
php /var/www/scripts/docker-init.php

if [ -d /var/www/scripts/docker-init.d/sql ] ; then
for fileSQL in /var/www/scripts/docker-init.d/sql/*.sql; do
[ ! -f $fileSQL ] && continue ;
echo "Importing custom SQL 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 filePHP in /var/www/scripts/docker-init.d/php/*.php; do
[ ! -f $filePHP ] && continue ;
echo "Executing custom PHP : `basename ${filePHP}` ..."
php $filePHP
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

Expand Down
29 changes: 17 additions & 12 deletions images/19.0.1-php8.2/docker-run.sh
Original file line number Diff line number Diff line change
Expand Up @@ -172,18 +172,23 @@ function initializeDatabase()
echo "Enable user module ..."
php /var/www/scripts/docker-init.php

if [ -d /var/www/scripts/docker-init.d/sql ] ; then
for fileSQL in /var/www/scripts/docker-init.d/sql/*.sql; do
[ ! -f $fileSQL ] && continue ;
echo "Importing custom SQL 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 filePHP in /var/www/scripts/docker-init.d/php/*.php; do
[ ! -f $filePHP ] && continue ;
echo "Executing custom PHP : `basename ${filePHP}` ..."
php $filePHP
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

Expand Down
29 changes: 17 additions & 12 deletions images/develop/docker-run.sh
Original file line number Diff line number Diff line change
Expand Up @@ -172,18 +172,23 @@ function initializeDatabase()
echo "Enable user module ..."
php /var/www/scripts/docker-init.php

if [ -d /var/www/scripts/docker-init.d/sql ] ; then
for fileSQL in /var/www/scripts/docker-init.d/sql/*.sql; do
[ ! -f $fileSQL ] && continue ;
echo "Importing custom SQL 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 filePHP in /var/www/scripts/docker-init.d/php/*.php; do
[ ! -f $filePHP ] && continue ;
echo "Executing custom PHP : `basename ${filePHP}` ..."
php $filePHP
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

Expand Down

0 comments on commit 34658ed

Please sign in to comment.