From d86050d68adaa02a3ef07fa8a1df612f70f9efbf Mon Sep 17 00:00:00 2001 From: Janik von Rotz Date: Fri, 7 Mar 2025 09:05:53 +0100 Subject: [PATCH] feat(image): replace wit-for-psql with pg_isready --- image/Dockerfile | 2 -- image/entrypoint.sh | 6 +++--- image/wait-for-psql.py | 32 -------------------------------- 3 files changed, 3 insertions(+), 37 deletions(-) delete mode 100755 image/wait-for-psql.py diff --git a/image/Dockerfile b/image/Dockerfile index ea615cdb..1bcd9c22 100644 --- a/image/Dockerfile +++ b/image/Dockerfile @@ -136,8 +136,6 @@ EXPOSE 8069 8071 8072 # Set the default config file ENV ODOO_RC=/etc/odoo/odoo.conf -COPY ./image/wait-for-psql.py /usr/local/bin/ - # Set default user when running the container USER odoo diff --git a/image/entrypoint.sh b/image/entrypoint.sh index be7d3f70..d395ab43 100755 --- a/image/entrypoint.sh +++ b/image/entrypoint.sh @@ -60,7 +60,7 @@ check_config "db_user" "$PGUSER" check_config "db_password" "$PGPASSWORD" entrypoint-log "Waiting for database connection." -wait-for-psql.py ${DB_ARGS[@]} --timeout=30 +pg_isready -h "$PGHOST" -p "$PGPORT" setup-mail @@ -74,12 +74,12 @@ case "$1" in if [[ "$1" == "scaffold" ]] ; then exec odoo "$@" else - wait-for-psql.py ${DB_ARGS[@]} --timeout=30 + pg_isready -h "$PGHOST" -p "$PGPORT" exec odoo "$@" "${DB_ARGS[@]}" fi ;; -*) - wait-for-psql.py ${DB_ARGS[@]} --timeout=30 + pg_isready -h "$PGHOST" -p "$PGPORT" exec odoo "$@" "${DB_ARGS[@]}" ;; *) diff --git a/image/wait-for-psql.py b/image/wait-for-psql.py deleted file mode 100755 index a55f4409..00000000 --- a/image/wait-for-psql.py +++ /dev/null @@ -1,32 +0,0 @@ -#!/usr/bin/env python3 -import argparse -import psycopg2 -import sys -import time - - -if __name__ == '__main__': - arg_parser = argparse.ArgumentParser() - arg_parser.add_argument('--db_host', required=True) - arg_parser.add_argument('--db_port', required=True) - arg_parser.add_argument('--db_user', required=True) - arg_parser.add_argument('--db_password', required=True) - arg_parser.add_argument('--timeout', type=int, default=5) - - args = arg_parser.parse_args() - - start_time = time.time() - while (time.time() - start_time) < args.timeout: - try: - conn = psycopg2.connect(user=args.db_user, host=args.db_host, port=args.db_port, password=args.db_password, dbname='postgres') - error = '' - break - except psycopg2.OperationalError as e: - error = e - else: - conn.close() - time.sleep(1) - - if error: - print("Database connection failure: %s" % error, file=sys.stderr) - sys.exit(1)