Skip to content

Commit

Permalink
Give a dedicated cachedb dir for volume mount
Browse files Browse the repository at this point in the history
In order to extract the DB dump from the image we want this folder to be standalone especially in the CI
  • Loading branch information
yvaucher committed Oct 15, 2024
1 parent 123a4e7 commit c683569
Show file tree
Hide file tree
Showing 2 changed files with 48 additions and 50 deletions.
46 changes: 23 additions & 23 deletions bin/runmigration
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@
set -e

wait_postgres.sh
CACHE_DIR=/.cachedb
CACHE_DIR=/tmp/cachedb

echo $CACHE_DIR

Expand All @@ -45,38 +45,38 @@ CACHED_DUMP="$CACHE_DIR/odoo_sample_$VERSION.dmp"

if [ "$LOAD_DB_CACHE" != "false" ]; then

# If we want to run the migration steps on top of a previous dump
# useful when odoo/VERSION was edited
if [ -n "$MIG_LOAD_VERSION_CEIL" ]; then
echo "New version - Searching for previous version dump ๐Ÿ”ญ"
if [ -d "$CACHE_DIR" ]; then
# Filter dumps of higher releases
export MAX_DUMP="$CACHE_DIR/odoo_sample_${MIG_LOAD_VERSION_CEIL}.dmp"
CACHED_DUMP=$(ls -v $CACHE_DIR/odoo_sample_*.dmp | awk '$0 < ENVIRON["MAX_DUMP"]' | tail -n1)
else
echo "No cached migration sample dump found"
fi
# If we want to run the migration steps on top of a previous dump
# useful when odoo/VERSION was edited
if [ -n "$MIG_LOAD_VERSION_CEIL" ]; then
echo "New version - Searching for previous version dump ๐Ÿ”ญ"
if [ -d "$CACHE_DIR" ]; then
# Filter dumps of higher releases
export MAX_DUMP="$CACHE_DIR/odoo_sample_${MIG_LOAD_VERSION_CEIL}.dmp"
CACHED_DUMP=$(ls -v $CACHE_DIR/odoo_sample_*.dmp | awk '$0 < ENVIRON["MAX_DUMP"]' | tail -n1)
else
echo "No cached migration sample dump found"
fi
fi
else
echo "Dump cache load disabled."
echo "Dump cache load disabled."
fi

if [ "$LOAD_DB_CACHE" != "false" -a -f "$CACHED_DUMP" ]; then
echo "๐Ÿ˜ ๐Ÿ˜ Database dump ${CACHED_DUMP} found ๐Ÿ˜ ๐Ÿ˜"
echo "Restore Database dump from cache ๐Ÿ“ฆโฎ• ๐Ÿ˜"
createdb -O $DB_USER $DB_NAME
psql -q -o /dev/null -f "$CACHED_DUMP"
echo "Do migration on top of restored dump"
echo "๐Ÿ˜ ๐Ÿ˜ Database dump ${CACHED_DUMP} found ๐Ÿ˜ ๐Ÿ˜"
echo "Restore Database dump from cache ๐Ÿ“ฆโฎ• ๐Ÿ˜"
createdb -O $DB_USER $DB_NAME
psql -q -o /dev/null -f "$CACHED_DUMP"
echo "Do migration on top of restored dump"
else
echo "Do migration from scratch ๐Ÿข ๐Ÿข ๐Ÿข"
echo "Do migration from scratch ๐Ÿข ๐Ÿข ๐Ÿข"
fi

gosu odoo migrate

# Create a dump if none exist for the current VERSION
if [ "$CREATE_DB_CACHE" == "true" -a ! -f "$CACHED_DUMP" ]; then
echo "Save DB to cache $CACHED_DUMP ๐Ÿ˜โฎ• ๐Ÿ“ฆ"
mkdir -p "$CACHE_DIR"
pg_dump -Fp -O -f "$CACHED_DUMP"
ls -l $CACHED_DUMP
echo "Save DB to cache $CACHED_DUMP ๐Ÿ˜โฎ• ๐Ÿ“ฆ"
mkdir -p "$CACHE_DIR"
pg_dump -Fp -O -f "$CACHED_DUMP"
ls -l $CACHED_DUMP
fi
52 changes: 25 additions & 27 deletions bin/runtests
Original file line number Diff line number Diff line change
Expand Up @@ -31,17 +31,16 @@ set -e
wait_postgres.sh
LOCAL_SRC_DIR=/odoo/local-src
case "$ODOO_VERSION" in
"7.0") ODOO_BIN_PATH=/odoo/src/openerp-server ;;
"8.0"|"9.0") ODOO_BIN_PATH=/odoo/src/odoo.py ;;
*) ODOO_BIN_PATH=/odoo/src/odoo-bin ;;
"7.0") ODOO_BIN_PATH=/odoo/src/openerp-server ;;
"8.0" | "9.0") ODOO_BIN_PATH=/odoo/src/odoo.py ;;
*) ODOO_BIN_PATH=/odoo/src/odoo-bin ;;
esac
CACHE_DIR=/.cachedb
CACHE_DIR=/tmp/cachedb

if [ -z $1 ]
then
LOCAL_ADDONS=$(find ${LOCAL_SRC_DIR}/* -maxdepth 0 -type d -and -not -name server_environment_files -printf "%f\n"\
| awk -vORS=, '{print $1}'\
| sed 's/,$/\n/')
if [ -z $1 ]; then
LOCAL_ADDONS=$(find ${LOCAL_SRC_DIR}/* -maxdepth 0 -type d -and -not -name server_environment_files -printf "%f\n" |
awk -vORS=, '{print $1}' |
sed 's/,$/\n/')
else
LOCAL_ADDONS=$1
fi
Expand All @@ -50,34 +49,33 @@ DEPS_ADDONS=$(list_dependencies.py "$LOCAL_ADDONS")

DB_NAME_TEST=${DB_NAME}_test


echo "Create database"
createdb -O $DB_USER ${DB_NAME_TEST}

if [[ ! -z "$SUBS_MD5" ]]; then
CACHED_DUMP="$CACHE_DIR/odoo_test_$SUBS_MD5.dmp"
CACHED_DUMP="$CACHE_DIR/odoo_test_$SUBS_MD5.dmp"
fi

echo "Submodule addons MD5 is: $SUBS_MD5"

if [ "$LOAD_DB_CACHE" != "false" -a -f "$CACHED_DUMP" ]; then
echo "๐Ÿ˜ ๐Ÿ˜ Database dump ${CACHED_DUMP} found ๐Ÿ˜ ๐Ÿ˜"
echo "Restore Database dump from cache matching MD5 ๐Ÿ“ฆโฎ• ๐Ÿ˜"
psql -q -o /dev/null -d $DB_NAME_TEST -f "$CACHED_DUMP"
psql -d $DB_NAME_TEST -P pager=off -c "SELECT name as installed_module FROM ir_module_module WHERE state = 'installed' ORDER BY name"
echo "๐Ÿ˜ ๐Ÿ˜ Database dump ${CACHED_DUMP} found ๐Ÿ˜ ๐Ÿ˜"
echo "Restore Database dump from cache matching MD5 ๐Ÿ“ฆโฎ• ๐Ÿ˜"
psql -q -o /dev/null -d $DB_NAME_TEST -f "$CACHED_DUMP"
psql -d $DB_NAME_TEST -P pager=off -c "SELECT name as installed_module FROM ir_module_module WHERE state = 'installed' ORDER BY name"
else
if [ "$LOAD_DB_CACHE" == "false" ]; then
echo "Dump cache load disabled."
else
echo "No cached dump found matching MD5 ๐Ÿข ๐Ÿข ๐Ÿข"
fi
echo "๐Ÿ”จ๐Ÿ”จ Install official/OCA modules ๐Ÿ”จ๐Ÿ”จ"
gosu odoo odoo --stop-after-init --workers=0 --database $DB_NAME_TEST --log-level=warn --without-demo="" --db-filter=$DB_NAME_TEST -i ${DEPS_ADDONS}
if [ "$CREATE_DB_CACHE" == "true" -a ! -z "$CACHED_DUMP" ]; then
echo "Generate dump $CACHED_DUMP into cache ๐Ÿ˜โฎ• ๐Ÿ“ฆ"
mkdir -p "$CACHE_DIR"
pg_dump -Fp -d $DB_NAME_TEST -O -f "$CACHED_DUMP"
fi
if [ "$LOAD_DB_CACHE" == "false" ]; then
echo "Dump cache load disabled."
else
echo "No cached dump found matching MD5 ๐Ÿข ๐Ÿข ๐Ÿข"
fi
echo "๐Ÿ”จ๐Ÿ”จ Install official/OCA modules ๐Ÿ”จ๐Ÿ”จ"
gosu odoo odoo --stop-after-init --workers=0 --database $DB_NAME_TEST --log-level=warn --without-demo="" --db-filter=$DB_NAME_TEST -i ${DEPS_ADDONS}
if [ "$CREATE_DB_CACHE" == "true" -a ! -z "$CACHED_DUMP" ]; then
echo "Generate dump $CACHED_DUMP into cache ๐Ÿ˜โฎ• ๐Ÿ“ฆ"
mkdir -p "$CACHE_DIR"
pg_dump -Fp -d $DB_NAME_TEST -O -f "$CACHED_DUMP"
fi
fi
echo "๐Ÿ”ง๐Ÿ”ง Install local-src modules ๐Ÿ”ง๐Ÿ”ง"
gosu odoo odoo --stop-after-init --workers=0 --database $DB_NAME_TEST --log-level=warn --without-demo="" --db-filter=$DB_NAME_TEST -i ${LOCAL_ADDONS}
Expand Down

0 comments on commit c683569

Please sign in to comment.