diff --git a/11.0/Dockerfile b/11.0/Dockerfile index 361c76a..6f84e46 100644 --- a/11.0/Dockerfile +++ b/11.0/Dockerfile @@ -13,7 +13,6 @@ RUN set -x; \ && apt-get install -y --no-install-recommends \ ca-certificates \ curl \ - wait-for-it \ dirmngr \ fonts-noto-cjk \ gnupg \ @@ -76,6 +75,8 @@ EXPOSE 8069 8071 # Set the default config file ENV ODOO_RC /etc/odoo/odoo.conf +COPY wait-for-psql.py /usr/local/bin/wait-for-psql.py + # Set default user when running the container USER odoo diff --git a/11.0/entrypoint.sh b/11.0/entrypoint.sh index b6401f7..5638e6d 100755 --- a/11.0/entrypoint.sh +++ b/11.0/entrypoint.sh @@ -23,19 +23,18 @@ check_config "db_port" "$PORT" check_config "db_user" "$USER" check_config "db_password" "$PASSWORD" -# Wait for the database to be up -wait-for-it $HOST:$PORT --timeout=60 -- sleep 5s - case "$1" in -- | odoo) shift if [[ "$1" == "scaffold" ]] ; then exec odoo "$@" else + wait-for-psql.py ${DB_ARGS[@]} --timeout=30 exec odoo "$@" "${DB_ARGS[@]}" fi ;; -*) + wait-for-psql.py ${DB_ARGS[@]} --timeout=30 exec odoo "$@" "${DB_ARGS[@]}" ;; *) diff --git a/11.0/wait-for-psql.py b/11.0/wait-for-psql.py new file mode 100755 index 0000000..a55f440 --- /dev/null +++ b/11.0/wait-for-psql.py @@ -0,0 +1,32 @@ +#!/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) diff --git a/12.0/Dockerfile b/12.0/Dockerfile index cfa69a6..a93334a 100644 --- a/12.0/Dockerfile +++ b/12.0/Dockerfile @@ -13,7 +13,6 @@ RUN set -x; \ && apt-get install -y --no-install-recommends \ ca-certificates \ curl \ - wait-for-it \ dirmngr \ fonts-noto-cjk \ gnupg \ @@ -90,6 +89,8 @@ EXPOSE 8069 8071 # Set the default config file ENV ODOO_RC /etc/odoo/odoo.conf +COPY wait-for-psql.py /usr/local/bin/wait-for-psql.py + # Set default user when running the container USER odoo diff --git a/12.0/entrypoint.sh b/12.0/entrypoint.sh index b6401f7..5638e6d 100755 --- a/12.0/entrypoint.sh +++ b/12.0/entrypoint.sh @@ -23,19 +23,18 @@ check_config "db_port" "$PORT" check_config "db_user" "$USER" check_config "db_password" "$PASSWORD" -# Wait for the database to be up -wait-for-it $HOST:$PORT --timeout=60 -- sleep 5s - case "$1" in -- | odoo) shift if [[ "$1" == "scaffold" ]] ; then exec odoo "$@" else + wait-for-psql.py ${DB_ARGS[@]} --timeout=30 exec odoo "$@" "${DB_ARGS[@]}" fi ;; -*) + wait-for-psql.py ${DB_ARGS[@]} --timeout=30 exec odoo "$@" "${DB_ARGS[@]}" ;; *) diff --git a/12.0/wait-for-psql.py b/12.0/wait-for-psql.py new file mode 100755 index 0000000..a55f440 --- /dev/null +++ b/12.0/wait-for-psql.py @@ -0,0 +1,32 @@ +#!/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) diff --git a/13.0/Dockerfile b/13.0/Dockerfile index 7a1b3ff..d20372e 100644 --- a/13.0/Dockerfile +++ b/13.0/Dockerfile @@ -10,7 +10,6 @@ RUN set -x; \ && apt-get install -y --no-install-recommends \ ca-certificates \ curl \ - wait-for-it \ dirmngr \ fonts-noto-cjk \ gnupg \ @@ -78,6 +77,8 @@ EXPOSE 8069 8071 # Set the default config file ENV ODOO_RC /etc/odoo/odoo.conf +COPY wait-for-psql.py /usr/local/bin/wait-for-psql.py + # Set default user when running the container USER odoo diff --git a/13.0/entrypoint.sh b/13.0/entrypoint.sh index b6401f7..5638e6d 100755 --- a/13.0/entrypoint.sh +++ b/13.0/entrypoint.sh @@ -23,19 +23,18 @@ check_config "db_port" "$PORT" check_config "db_user" "$USER" check_config "db_password" "$PASSWORD" -# Wait for the database to be up -wait-for-it $HOST:$PORT --timeout=60 -- sleep 5s - case "$1" in -- | odoo) shift if [[ "$1" == "scaffold" ]] ; then exec odoo "$@" else + wait-for-psql.py ${DB_ARGS[@]} --timeout=30 exec odoo "$@" "${DB_ARGS[@]}" fi ;; -*) + wait-for-psql.py ${DB_ARGS[@]} --timeout=30 exec odoo "$@" "${DB_ARGS[@]}" ;; *) diff --git a/13.0/wait-for-psql.py b/13.0/wait-for-psql.py new file mode 100755 index 0000000..a55f440 --- /dev/null +++ b/13.0/wait-for-psql.py @@ -0,0 +1,32 @@ +#!/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)