diff --git a/compose.yml.template b/compose.yml.template index b9abff86..116d7690 100644 --- a/compose.yml.template +++ b/compose.yml.template @@ -67,7 +67,8 @@ services: TEST_ADDONS_DIR: ${TEST_ADDONS_DIR} TEST_INCLUDE: ${TEST_INCLUDE} TEST_EXCLUDE: ${TEST_EXCLUDE} - AUTO_UPDATE_TRANSLATIONS: ${AUTO_UPDATE_TRANSLATIONS} + AUTO_UPDATE_TRANSLATIONS: "${AUTO_UPDATE_TRANSLATIONS}" + AUTO_UPDATE_MODULES_LIST: "${AUTO_UPDATE_MODULES_LIST}" command: odoo --dev=all ports: - "${ODOO_PORT}:8069" diff --git a/images/odoo/README.md b/images/odoo/README.md index be8ee6b1..a48fb811 100644 --- a/images/odoo/README.md +++ b/images/odoo/README.md @@ -139,6 +139,7 @@ services: TEST_INCLUDE: partner_firstname TEST_EXCLUDE: partner_fax AUTO_UPDATE_TRANSLATIONS: True + AUTO_UPDATE_MODULES_LIST: True ports: - "127.0.0.1:8069:8069" volumes: @@ -233,6 +234,12 @@ There is also the possiblity to update all modules: docker compose exec odoo update-modules ``` +Or update the modules list (refresh the list of available modules from the addons path): + +```bash +docker compose exec odoo update-modules-list +``` + For each installed module Odoo computes and stores a checksum in the database. The update modules script compares the checksum and updates all modules that have changed. Updating module translations is simple: @@ -406,6 +413,7 @@ The container uses [click-odoo-contrib](https://github.com/acsone/click-odoo-con * `AUTO_UPDATE_MODULES` If enabled modules will updated when the container is started. Default is `False`. * `AUTO_UPDATE_TRANSLATIONS` If enabled translatiosn will be updated when the container starts. Default is `False`. +* `AUTO_UPDATE_MODULES_LIST` If enabled, the modules list will be updated when the container starts. Default is `False`. Both options require `ODOO_DATABASE` and `ODOO_ADDONS_PATH`. diff --git a/images/odoo/bin/check-database-initialized b/images/odoo/bin/check-database-initialized new file mode 100755 index 00000000..7b20c8d1 --- /dev/null +++ b/images/odoo/bin/check-database-initialized @@ -0,0 +1,18 @@ +#!/bin/bash + +if [ -n "$ODOO_DATABASE" ]; then + echo "Check if database $ODOO_DATABASE is initialized." + DATABASE_INITIALIZED=$(exec psql "postgres://$PGUSER:$PGPASSWORD@$PGHOST:$PGPORT/$ODOO_DATABASE" -tAc "SELECT COUNT(*) FROM information_schema.tables WHERE table_name = 'ir_module_module'") + echo "Database initialization check result: $DATABASE_INITIALIZED" + + if [ "$DATABASE_INITIALIZED" = "1" ]; then + echo "Database $ODOO_DATABASE is initialized." + exit 0 + else + echo "Database $ODOO_DATABASE is not initialized." + exit 1 + fi +else + echo "ODOO_DATABASE environment variable not set." + exit 1 +fi diff --git a/images/odoo/bin/init-db b/images/odoo/bin/init-db index 5707c8d7..a70ed38c 100755 --- a/images/odoo/bin/init-db +++ b/images/odoo/bin/init-db @@ -2,16 +2,15 @@ if [ -n "$ODOO_DATABASE" ]; then - echo "Starting database initialization for $ODOO_DATABASE" + echo "Starting database initialization for $ODOO_DATABASE." echo "Database connection: $PGUSER@$PGHOST:$PGPORT" - # Wait for database to be ready echo "Waiting for database connection..." until psql "postgres://$PGUSER:$PGPASSWORD@$PGHOST:$PGPORT/postgres" -c '\q' 2>/dev/null; do echo "Database not ready, waiting 2 seconds..." sleep 2 done - echo "Database connection established" + echo "Database connection established." echo "Check if database $ODOO_DATABASE exists..." DATABASE_EXISTS=$(exec psql "postgres://$PGUSER:$PGPASSWORD@$PGHOST:$PGPORT/postgres" -tAc "SELECT COUNT(*) FROM pg_database WHERE datname = '$ODOO_DATABASE'") @@ -19,18 +18,14 @@ if [ -n "$ODOO_DATABASE" ]; then # If it does not exist, create it if [ "$DATABASE_EXISTS" = "0" ]; then - echo "Create database $ODOO_DATABASE." + echo "Create database $ODOO_DATABASE..." (exec psql "postgres://$PGUSER:$PGPASSWORD@$PGHOST:$PGPORT/postgres" -tAc "CREATE DATABASE \"$ODOO_DATABASE\";") || true - echo "Database creation completed" + echo "Database creation completed." else - echo "Database $ODOO_DATABASE already exists" + echo "Database $ODOO_DATABASE already exists." fi - echo "Check if database $ODOO_DATABASE is initialized" - DATABASE_INITIALIZED=$(exec psql "postgres://$PGUSER:$PGPASSWORD@$PGHOST:$PGPORT/$ODOO_DATABASE" -tAc "SELECT COUNT(*) FROM information_schema.tables WHERE table_name = 'ir_module_module'") - echo "Database initialization check result: $DATABASE_INITIALIZED" - - if [ "$DATABASE_INITIALIZED" = "0" ]; then + if ! check-database-initialized; then echo "Database not initialized, starting initialization process" ODOO_INIT_DEMO_DATA=${ODOO_INIT_DEMO_DATA:=False} ODOO_INIT_LOGIN=${ODOO_INIT_LOGIN:="admin"} @@ -46,7 +41,7 @@ if [ -n "$ODOO_DATABASE" ]; then echo "Initialize database $ODOO_DATABASE with modules: $ODOO_INIT_ADDONS." (exec odoo "${DB_ARGS[@]}" --database "$ODOO_DATABASE" --init "$ODOO_INIT_ADDONS" --config "$ODOO_RC" --stop-after-init --no-http --load-language "$ODOO_INIT_LANG" $ODOO_INIT_PARAM) || true - echo "Odoo initialization command completed" + echo "Odoo initialization command completed." if [ "$ODOO_INIT_LOGIN" != "admin" ] || [ "$ODOO_INIT_PASSWORD" != "admin" ]; then echo "Updating admin user credentials to login: $ODOO_INIT_LOGIN" @@ -57,21 +52,14 @@ admin_user.write({ 'password': '$ODOO_INIT_PASSWORD' }) env.cr.commit() -print('Admin credentials updated successfully') +print('Admin credentials updated successfully.') EOF ) || true - echo "Admin credentials update completed" + echo "Admin credentials update completed." fi - else - echo "Database $ODOO_DATABASE is already initialized (DATABASE_INITIALIZED=$DATABASE_INITIALIZED)" fi - # Recheck database initialization status - echo "Rechecking database initialization status..." - DATABASE_INITIALIZED=$(exec psql "postgres://$PGUSER:$PGPASSWORD@$PGHOST:$PGPORT/$ODOO_DATABASE" -tAc "SELECT COUNT(*) FROM information_schema.tables WHERE table_name = 'ir_module_module'") - echo "Final database initialization status: $DATABASE_INITIALIZED" - - if [ "$DATABASE_INITIALIZED" = "1" ]; then + if check-database-initialized; then echo "Setting up mail server configuration..." export ODOO_MAIL_SMTP_PORT=${ODOO_MAIL_SMTP_PORT:="587"} export ODOO_MAIL_SMTP_ENCRYPTION=${ODOO_MAIL_SMTP_ENCRYPTION:="starttls"} @@ -79,14 +67,14 @@ EOF export ODOO_MAIL_IMAP_PORT=${ODOO_MAIL_IMAP_PORT:="993"} export ODOO_MAIL_IMAP_SSL=${ODOO_MAIL_IMAP_SSL:="True"} - echo "Setup mail server configuration for database $ODOO_DATABASE" + echo "Setup mail server configuration for database $ODOO_DATABASE." (odoo shell "${DB_ARGS[@]}" --database "$ODOO_DATABASE" --config "$ODOO_RC" --stop-after-init --no-http < /usr/local/bin/setup-mail) || true - echo "Mail server configuration completed" + echo "Mail server configuration completed." else - echo "WARNING: Database initialization may have failed. DATABASE_INITIALIZED=$DATABASE_INITIALIZED" + echo "WARNING: Database initialization may have failed." fi echo "Database initialization process completed for $ODOO_DATABASE" else - echo "ODOO_DATABASE environment variable not set, skipping database initialization" + echo "ODOO_DATABASE environment variable not set, skipping database initialization." fi diff --git a/images/odoo/bin/init-module b/images/odoo/bin/init-module index aba62f7e..7e138a28 100755 --- a/images/odoo/bin/init-module +++ b/images/odoo/bin/init-module @@ -1,10 +1,7 @@ #!/bin/bash if [ -n "$ODOO_DATABASE" ]; then - echo "Check if database $ODOO_DATABASE is initialized" - DATABASE_INITIALIZED=$(exec psql "postgres://$PGUSER:$PGPASSWORD@$PGHOST:$PGPORT/$ODOO_DATABASE" -tAc "SELECT COUNT(*) FROM information_schema.tables WHERE table_name = 'ir_module_module'") - - if [ "$DATABASE_INITIALIZED" = "1" ]; then + if check-database-initialized; then ODOO_INIT_LANG="${ODOO_INIT_LANG:="en_US"}" echo "Initialize module $1 on database $ODOO_DATABASE." diff --git a/images/odoo/bin/update-module b/images/odoo/bin/update-module index 34bf9ec1..f00aabea 100755 --- a/images/odoo/bin/update-module +++ b/images/odoo/bin/update-module @@ -1,10 +1,7 @@ #!/bin/bash if [ -n "$ODOO_DATABASE" ]; then - echo "Check if database $ODOO_DATABASE is initialized" - DATABASE_INITIALIZED=$(exec psql "postgres://$PGUSER:$PGPASSWORD@$PGHOST:$PGPORT/$ODOO_DATABASE" -tAc "SELECT COUNT(*) FROM information_schema.tables WHERE table_name = 'ir_module_module'") - - if [ "$DATABASE_INITIALIZED" = "1" ]; then + if check-database-initialized; then ODOO_INIT_LANG="${ODOO_INIT_LANG:="en_US"}" echo "Update module $1 on database $ODOO_DATABASE." diff --git a/images/odoo/bin/update-modules-list b/images/odoo/bin/update-modules-list new file mode 100755 index 00000000..53bc91d2 --- /dev/null +++ b/images/odoo/bin/update-modules-list @@ -0,0 +1,19 @@ +#!/bin/bash + +if [ -n "$ODOO_DATABASE" ]; then + if check-database-initialized; then + echo "Update modules list on database $ODOO_DATABASE." + # Execute Odoo shell command to call base.module.update:update_module() + (exec odoo shell "${DB_ARGS[@]}" --database "$ODOO_DATABASE" --config "$ODOO_RC" --stop-after-init --no-http << EOF +updater = env['base.module.update'] +updater.update_module() +env.cr.commit() +print('Module list updated successfully.') +EOF +) || true + else + echo "Database $ODOO_DATABASE is not initialized, skipping modules list update." + fi +else + echo "ODOO_DATABASE environment variable not set, skipping modules list update." +fi diff --git a/images/odoo/bin/update-translations b/images/odoo/bin/update-translations index 53ce0e6f..a84b980c 100755 --- a/images/odoo/bin/update-translations +++ b/images/odoo/bin/update-translations @@ -3,12 +3,14 @@ source set-addons-path if [ -n "$ODOO_DATABASE" ]; then - echo "Updating translations for all active languages and installed modules." - (exec odoo shell --database "$ODOO_DATABASE" --config "$ODOO_RC" << EOF + if check-database-initialized; then + echo "Updating translations for all active languages and installed modules." + (exec odoo shell --database "$ODOO_DATABASE" --config "$ODOO_RC" << EOF for lang in env['res.lang'].search([]): env['ir.module.module'].search([('state', '=', 'installed')])._update_translations(lang.code, overwrite=True) env.cr.commit() print('Translations updated successfully') EOF ) || true + fi fi diff --git a/images/odoo/bin/wait-for-pg b/images/odoo/bin/wait-for-pg index db038a89..be954f6f 100755 --- a/images/odoo/bin/wait-for-pg +++ b/images/odoo/bin/wait-for-pg @@ -1,6 +1,5 @@ #!/bin/bash - MAX_ATTEMPTS=30 SLEEP_SECONDS=5 ATTEMPTS=0 diff --git a/images/odoo/entrypoint.sh b/images/odoo/entrypoint.sh index 7dc5caed..20b66dbe 100755 --- a/images/odoo/entrypoint.sh +++ b/images/odoo/entrypoint.sh @@ -53,6 +53,11 @@ if [ "$AUTO_UPDATE_MODULES" = "True" ]; then update-modules fi +AUTO_UPDATE_MODULES_LIST="${AUTO_UPDATE_MODULES_LIST:=False}" +if [ "$AUTO_UPDATE_MODULES_LIST" = "True" ]; then + update-modules-list +fi + AUTO_UPDATE_TRANSLATIONS="${AUTO_UPDATE_TRANSLATIONS:=False}" if [ "$AUTO_UPDATE_TRANSLATIONS" = "True" ]; then update-translations diff --git a/images/odoo/requirements.txt b/images/odoo/requirements.txt index d06e0b74..faaf713a 100644 --- a/images/odoo/requirements.txt +++ b/images/odoo/requirements.txt @@ -15,10 +15,13 @@ watchdog # python3-watchdog rlPyCairo # python3-renderpm lxml # python3-lxml -# Built-in +# Performance +memray + +# OCA Tools manifestoo click-odoo-contrib -memray +git-aggregator # Upgrade git+https://github.com/OCA/openupgradelib.git@master diff --git a/requirements.txt b/requirements.txt index f1b5ea56..be85ee20 100644 --- a/requirements.txt +++ b/requirements.txt @@ -32,5 +32,5 @@ manifestoo oca-port odoo-module-migrator click-odoo-contrib -git+https://github.com/acsone/git-aggregator@master +git-aggregator git+https://github.com/OCA/maintainer-tools diff --git a/task b/task index 7110778d..7f1c8a07 100755 --- a/task +++ b/task @@ -625,7 +625,7 @@ function build() { # Set container tag and platform based on Dockerfile PLATFORM="linux/amd64" if [ "$1" = "images/odoo" ]; then - PLATFORM="linux/amd64,linux/arm64" + # PLATFORM="linux/amd64,linux/arm64" MANIFEST_FILE="images/odoo/Dockerfile" CONTAINER_TAG="odoo:$ODOO_REVISION" LATEST_TAG="odoo:$ODOO_VERSION" @@ -1324,6 +1324,7 @@ function test-project() { export MODULE_AUTO_INSTALL_DISABLED=odoo_test_xmlrunner export AUTO_UPDATE_MODULES=True export AUTO_UPDATE_TRANSLATIONS=True + export AUTO_UPDATE_MODULES_LIST=True export MAIL_DEFAULT_FROM="test" export BROWSER_OPEN=false export TEST_ADDONS_DIR=/mnt/oca/partner-contact