From 6d3a90c7db8e00e1f85c5676cdc7c68bf0d0ab51 Mon Sep 17 00:00:00 2001 From: Josh Santos Date: Sun, 31 Mar 2024 21:02:18 -0400 Subject: [PATCH] Migrate to pg_isready --- 15.0/entrypoint.sh | 28 ++++++++++++++++++---------- 15.0/wait-for-psql.py | 36 ------------------------------------ 16.0/entrypoint.sh | 28 ++++++++++++++++++---------- 16.0/wait-for-psql.py | 36 ------------------------------------ 17.0/entrypoint.sh | 28 ++++++++++++++++++---------- 17.0/wait-for-psql.py | 36 ------------------------------------ 6 files changed, 54 insertions(+), 138 deletions(-) delete mode 100755 15.0/wait-for-psql.py delete mode 100755 16.0/wait-for-psql.py delete mode 100755 17.0/wait-for-psql.py diff --git a/15.0/entrypoint.sh b/15.0/entrypoint.sh index 73973c5..91e41a1 100755 --- a/15.0/entrypoint.sh +++ b/15.0/entrypoint.sh @@ -14,22 +14,30 @@ fi : ${USER:=${DB_ENV_POSTGRES_USER:=${POSTGRES_USER:='odoo'}}} : ${PASSWORD:=${DB_ENV_POSTGRES_PASSWORD:=${POSTGRES_PASSWORD:='odoo'}}} +ODOO_ARGS=() DB_ARGS=() + function check_config() { param="$1" value="$2" + pg_flag="$3" + if grep -q -E "^\s*\b${param}\b\s*=" "$ODOO_RC" ; then value=$(grep -E "^\s*\b${param}\b\s*=" "$ODOO_RC" |cut -d " " -f3|sed 's/["\n\r]//g') fi; - DB_ARGS+=("--${param}") + + ODOO_ARGS+=("--${param}") + ODOO_ARGS+=("${value}") + + DB_ARGS+=("${pg_flag}") DB_ARGS+=("${value}") } -check_config "db_name" "$NAME" -check_config "db_host" "$HOST" -check_config "db_port" "$PORT" -check_config "db_user" "$USER" -check_config "db_password" "$PASSWORD" +check_config "db_name" "$NAME" "-d" +check_config "db_host" "$HOST" "-h" +check_config "db_port" "$PORT" "-p" +check_config "db_user" "$USER" "-U" +# check_config "db_password" "$PASSWORD" case "$1" in -- | odoo) @@ -37,13 +45,13 @@ case "$1" in if [[ "$1" == "scaffold" ]] ; then exec odoo "$@" else - wait-for-psql.py ${DB_ARGS[@]} --timeout=30 - exec odoo "$@" "${DB_ARGS[@]}" + pg_isready ${DB_ARGS[@]} --timeout=30 + exec odoo "$@" "${ODOO_ARGS[@]}" fi ;; -*) - wait-for-psql.py ${DB_ARGS[@]} --timeout=30 - exec odoo "$@" "${DB_ARGS[@]}" + pg_isready ${DB_ARGS[@]} --timeout=30 + exec odoo "$@" "${ODOO_ARGS[@]}" ;; *) exec "$@" diff --git a/15.0/wait-for-psql.py b/15.0/wait-for-psql.py deleted file mode 100755 index f8dbbd6..0000000 --- a/15.0/wait-for-psql.py +++ /dev/null @@ -1,36 +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_name', required=True) - arg_parser.add_argument('--db_password', required=True) - arg_parser.add_argument('--timeout', type=int, default=5) - - args = arg_parser.parse_args() - - conn = None - start_time = time.time() - error = '' - - 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=args.db_name) - error = '' - conn.close() - break - except psycopg2.OperationalError as e: - error = e - - time.sleep(1) - - if error: - print("Database connection failure: %s" % error, file=sys.stderr) - sys.exit(1) diff --git a/16.0/entrypoint.sh b/16.0/entrypoint.sh index 73973c5..91e41a1 100755 --- a/16.0/entrypoint.sh +++ b/16.0/entrypoint.sh @@ -14,22 +14,30 @@ fi : ${USER:=${DB_ENV_POSTGRES_USER:=${POSTGRES_USER:='odoo'}}} : ${PASSWORD:=${DB_ENV_POSTGRES_PASSWORD:=${POSTGRES_PASSWORD:='odoo'}}} +ODOO_ARGS=() DB_ARGS=() + function check_config() { param="$1" value="$2" + pg_flag="$3" + if grep -q -E "^\s*\b${param}\b\s*=" "$ODOO_RC" ; then value=$(grep -E "^\s*\b${param}\b\s*=" "$ODOO_RC" |cut -d " " -f3|sed 's/["\n\r]//g') fi; - DB_ARGS+=("--${param}") + + ODOO_ARGS+=("--${param}") + ODOO_ARGS+=("${value}") + + DB_ARGS+=("${pg_flag}") DB_ARGS+=("${value}") } -check_config "db_name" "$NAME" -check_config "db_host" "$HOST" -check_config "db_port" "$PORT" -check_config "db_user" "$USER" -check_config "db_password" "$PASSWORD" +check_config "db_name" "$NAME" "-d" +check_config "db_host" "$HOST" "-h" +check_config "db_port" "$PORT" "-p" +check_config "db_user" "$USER" "-U" +# check_config "db_password" "$PASSWORD" case "$1" in -- | odoo) @@ -37,13 +45,13 @@ case "$1" in if [[ "$1" == "scaffold" ]] ; then exec odoo "$@" else - wait-for-psql.py ${DB_ARGS[@]} --timeout=30 - exec odoo "$@" "${DB_ARGS[@]}" + pg_isready ${DB_ARGS[@]} --timeout=30 + exec odoo "$@" "${ODOO_ARGS[@]}" fi ;; -*) - wait-for-psql.py ${DB_ARGS[@]} --timeout=30 - exec odoo "$@" "${DB_ARGS[@]}" + pg_isready ${DB_ARGS[@]} --timeout=30 + exec odoo "$@" "${ODOO_ARGS[@]}" ;; *) exec "$@" diff --git a/16.0/wait-for-psql.py b/16.0/wait-for-psql.py deleted file mode 100755 index f8dbbd6..0000000 --- a/16.0/wait-for-psql.py +++ /dev/null @@ -1,36 +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_name', required=True) - arg_parser.add_argument('--db_password', required=True) - arg_parser.add_argument('--timeout', type=int, default=5) - - args = arg_parser.parse_args() - - conn = None - start_time = time.time() - error = '' - - 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=args.db_name) - error = '' - conn.close() - break - except psycopg2.OperationalError as e: - error = e - - time.sleep(1) - - if error: - print("Database connection failure: %s" % error, file=sys.stderr) - sys.exit(1) diff --git a/17.0/entrypoint.sh b/17.0/entrypoint.sh index 73973c5..91e41a1 100755 --- a/17.0/entrypoint.sh +++ b/17.0/entrypoint.sh @@ -14,22 +14,30 @@ fi : ${USER:=${DB_ENV_POSTGRES_USER:=${POSTGRES_USER:='odoo'}}} : ${PASSWORD:=${DB_ENV_POSTGRES_PASSWORD:=${POSTGRES_PASSWORD:='odoo'}}} +ODOO_ARGS=() DB_ARGS=() + function check_config() { param="$1" value="$2" + pg_flag="$3" + if grep -q -E "^\s*\b${param}\b\s*=" "$ODOO_RC" ; then value=$(grep -E "^\s*\b${param}\b\s*=" "$ODOO_RC" |cut -d " " -f3|sed 's/["\n\r]//g') fi; - DB_ARGS+=("--${param}") + + ODOO_ARGS+=("--${param}") + ODOO_ARGS+=("${value}") + + DB_ARGS+=("${pg_flag}") DB_ARGS+=("${value}") } -check_config "db_name" "$NAME" -check_config "db_host" "$HOST" -check_config "db_port" "$PORT" -check_config "db_user" "$USER" -check_config "db_password" "$PASSWORD" +check_config "db_name" "$NAME" "-d" +check_config "db_host" "$HOST" "-h" +check_config "db_port" "$PORT" "-p" +check_config "db_user" "$USER" "-U" +# check_config "db_password" "$PASSWORD" case "$1" in -- | odoo) @@ -37,13 +45,13 @@ case "$1" in if [[ "$1" == "scaffold" ]] ; then exec odoo "$@" else - wait-for-psql.py ${DB_ARGS[@]} --timeout=30 - exec odoo "$@" "${DB_ARGS[@]}" + pg_isready ${DB_ARGS[@]} --timeout=30 + exec odoo "$@" "${ODOO_ARGS[@]}" fi ;; -*) - wait-for-psql.py ${DB_ARGS[@]} --timeout=30 - exec odoo "$@" "${DB_ARGS[@]}" + pg_isready ${DB_ARGS[@]} --timeout=30 + exec odoo "$@" "${ODOO_ARGS[@]}" ;; *) exec "$@" diff --git a/17.0/wait-for-psql.py b/17.0/wait-for-psql.py deleted file mode 100755 index f8dbbd6..0000000 --- a/17.0/wait-for-psql.py +++ /dev/null @@ -1,36 +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_name', required=True) - arg_parser.add_argument('--db_password', required=True) - arg_parser.add_argument('--timeout', type=int, default=5) - - args = arg_parser.parse_args() - - conn = None - start_time = time.time() - error = '' - - 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=args.db_name) - error = '' - conn.close() - break - except psycopg2.OperationalError as e: - error = e - - time.sleep(1) - - if error: - print("Database connection failure: %s" % error, file=sys.stderr) - sys.exit(1)