Add support for setting database name in Docker env variables

This commit is contained in:
Dyingday 2023-07-08 14:11:07 +01:00
parent 672d5cda91
commit 7df7ab081e
2 changed files with 4 additions and 1 deletions

View File

@ -12,6 +12,7 @@ fi
: ${PORT:=${DB_PORT_5432_TCP_PORT:=5432}} : ${PORT:=${DB_PORT_5432_TCP_PORT:=5432}}
: ${USER:=${DB_ENV_POSTGRES_USER:=${POSTGRES_USER:='odoo'}}} : ${USER:=${DB_ENV_POSTGRES_USER:=${POSTGRES_USER:='odoo'}}}
: ${PASSWORD:=${DB_ENV_POSTGRES_PASSWORD:=${POSTGRES_PASSWORD:='odoo'}}} : ${PASSWORD:=${DB_ENV_POSTGRES_PASSWORD:=${POSTGRES_PASSWORD:='odoo'}}}
: ${DB_NAME:=${DB_ENV_POSTGRES_DB_NAME:=${POSTGRES_DB_NAME:='odoo'}}}
DB_ARGS=() DB_ARGS=()
function check_config() { function check_config() {
@ -27,6 +28,7 @@ check_config "db_host" "$HOST"
check_config "db_port" "$PORT" check_config "db_port" "$PORT"
check_config "db_user" "$USER" check_config "db_user" "$USER"
check_config "db_password" "$PASSWORD" check_config "db_password" "$PASSWORD"
check_config "db_name" "$DB_NAME"
case "$1" in case "$1" in
-- | odoo) -- | odoo)

View File

@ -11,6 +11,7 @@ if __name__ == '__main__':
arg_parser.add_argument('--db_port', required=True) arg_parser.add_argument('--db_port', required=True)
arg_parser.add_argument('--db_user', required=True) arg_parser.add_argument('--db_user', required=True)
arg_parser.add_argument('--db_password', required=True) arg_parser.add_argument('--db_password', required=True)
arg_parser.add_argument('--db_name', required=True)
arg_parser.add_argument('--timeout', type=int, default=5) arg_parser.add_argument('--timeout', type=int, default=5)
args = arg_parser.parse_args() args = arg_parser.parse_args()
@ -18,7 +19,7 @@ if __name__ == '__main__':
start_time = time.time() start_time = time.time()
while (time.time() - start_time) < args.timeout: while (time.time() - start_time) < args.timeout:
try: try:
conn = psycopg2.connect(user=args.db_user, host=args.db_host, port=args.db_port, password=args.db_password, dbname='postgres') conn = psycopg2.connect(user=args.db_user, host=args.db_host, port=args.db_port, password=args.db_password, dbname=args.db_name)
error = '' error = ''
break break
except psycopg2.OperationalError as e: except psycopg2.OperationalError as e: