Skip to content

Commit

Permalink
[REF] Odoo 8.0-10.0: pass pg connection parameters as CLI arguments
Browse files Browse the repository at this point in the history
Do not assume that Odoo will handle correctly the PG* environment
variables, because it won't.

We also rename the PG* variables in order to avoid confusion since we do
not export them anymore.
  • Loading branch information
sle-odoo committed Nov 3, 2016
1 parent 9621c46 commit a3d207f
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 24 deletions.
17 changes: 9 additions & 8 deletions 10.0/entrypoint.sh
Original file line number Diff line number Diff line change
Expand Up @@ -2,20 +2,21 @@

set -e

# set odoo database host, port, user and password
: ${PGHOST:=${DB_PORT_5432_TCP_ADDR:='db'}}
: ${PGPORT:=${DB_PORT_5432_TCP_PORT:=5432}}
: ${PGUSER:=${DB_ENV_POSTGRES_USER:=${POSTGRES_USER:='postgres'}}}
: ${PGPASSWORD:=${DB_ENV_POSTGRES_PASSWORD:=$POSTGRES_PASSWORD}}
export PGHOST PGPORT PGUSER PGPASSWORD
# set the postgres database host, port, user and password
: ${HOST:=${DB_PORT_5432_TCP_ADDR:='db'}}
: ${PORT:=${DB_PORT_5432_TCP_PORT:=5432}}
: ${USER:=${DB_ENV_POSTGRES_USER:=${POSTGRES_USER:='postgres'}}}
: ${PASSWORD:=${DB_ENV_POSTGRES_PASSWORD:=$POSTGRES_PASSWORD}}
# pass them as arguments to the odoo process
DB_ARGS=("--db_user" $USER "--db_password" $PASSWORD "--db_host" $HOST "--db_port" $PORT)

case "$1" in
--)
shift
exec odoo "$@"
exec odoo "${DB_ARGS[@]}" "$@"
;;
-*)
exec odoo "$@"
exec odoo "${DB_ARGS[@]}" "$@"
;;
*)
exec "$@"
Expand Down
17 changes: 9 additions & 8 deletions 8.0/entrypoint.sh
Original file line number Diff line number Diff line change
Expand Up @@ -2,20 +2,21 @@

set -e

# set odoo database host, port, user and password
: ${PGHOST:=${DB_PORT_5432_TCP_ADDR:='db'}}
: ${PGPORT:=${DB_PORT_5432_TCP_PORT:=5432}}
: ${PGUSER:=${DB_ENV_POSTGRES_USER:=${POSTGRES_USER:='postgres'}}}
: ${PGPASSWORD:=${DB_ENV_POSTGRES_PASSWORD:=$POSTGRES_PASSWORD}}
export PGHOST PGPORT PGUSER PGPASSWORD
# set the postgres database host, port, user and password
: ${HOST:=${DB_PORT_5432_TCP_ADDR:='db'}}
: ${PORT:=${DB_PORT_5432_TCP_PORT:=5432}}
: ${USER:=${DB_ENV_POSTGRES_USER:=${POSTGRES_USER:='postgres'}}}
: ${PASSWORD:=${DB_ENV_POSTGRES_PASSWORD:=$POSTGRES_PASSWORD}}
# pass them as arguments to the odoo process
DB_ARGS=("--db_user" $USER "--db_password" $PASSWORD "--db_host" $HOST "--db_port" $PORT)

case "$1" in
--)
shift
exec openerp-server "$@"
exec openerp-server "${DB_ARGS[@]}" "$@"
;;
-*)
exec openerp-server "$@"
exec openerp-server "${DB_ARGS[@]}" "$@"
;;
*)
exec "$@"
Expand Down
17 changes: 9 additions & 8 deletions 9.0/entrypoint.sh
Original file line number Diff line number Diff line change
Expand Up @@ -2,20 +2,21 @@

set -e

# set odoo database host, port, user and password
: ${PGHOST:=${DB_PORT_5432_TCP_ADDR:='db'}}
: ${PGPORT:=${DB_PORT_5432_TCP_PORT:=5432}}
: ${PGUSER:=${DB_ENV_POSTGRES_USER:=${POSTGRES_USER:='postgres'}}}
: ${PGPASSWORD:=${DB_ENV_POSTGRES_PASSWORD:=$POSTGRES_PASSWORD}}
export PGHOST PGPORT PGUSER PGPASSWORD
# set the postgres database host, port, user and password
: ${HOST:=${DB_PORT_5432_TCP_ADDR:='db'}}
: ${PORT:=${DB_PORT_5432_TCP_PORT:=5432}}
: ${USER:=${DB_ENV_POSTGRES_USER:=${POSTGRES_USER:='postgres'}}}
: ${PASSWORD:=${DB_ENV_POSTGRES_PASSWORD:=$POSTGRES_PASSWORD}}
# pass them as arguments to the odoo process
DB_ARGS=("--db_user" $USER "--db_password" $PASSWORD "--db_host" $HOST "--db_port" $PORT)

case "$1" in
--)
shift
exec openerp-server "$@"
exec openerp-server "${DB_ARGS[@]}" "$@"
;;
-*)
exec openerp-server "$@"
exec openerp-server "${DB_ARGS[@]}" "$@"
;;
*)
exec "$@"
Expand Down

2 comments on commit a3d207f

@philhug
Copy link

@philhug philhug commented on a3d207f Dec 9, 2016

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

using the variable PORT and USER is not a very good idea.
USER is set to the current user and PORT is set to the listening port by some orchestration tools (e.g. dokku).

@sle-odoo
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

USER is not set to the current user in a debian stretch container. I guess it doesn't go through login.

~ @ odoos-MBP [odoo] $ docker run -i -t debian:stretch /bin/bash
root@6446168be7ae:/# env
HOSTNAME=6446168be7ae
PWD=/
HOME=/root
no_proxy=*.local, 169.254/16
TERM=xterm
SHLVL=1
PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin
_=/usr/bin/env

Please sign in to comment.