--- /dev/null
+FROM kdvn/ubuntu
+
+RUN mkdir -p /mnt/extra-addons /mnt/oefilestore /opt/oe7 /opt/workspace
+
+#RUN wget -qO- http://10.10.0.1/openerp_7.0.latest.tar.gz | tar xz -C /opt/oe7/ --owner=openerp --strip 1
+RUN wget -qO- http://nightly.odoo.com/7.0/nightly/src/openerp_7.0.latest.tar.gz | tar xz -C /opt/oe7/ --strip 1
+
+RUN adduser -u 1000 --system --group --home /home/openerp --shell /bin/bash openerp
+
+RUN echo "openerp ALL = NOPASSWD : /usr/bin/tee , /bin/sed , /usr/bin/apt-get , /usr/bin/aptitude , /usr/sbin/usermod " | tee -a /etc/sudoers
+
+RUN mkdir -p /home/openerp
+
+ENV OPENERP_SERVER /etc/openerp/openerp-server.conf
+
+VOLUME ["/mnt/oefilestore", "/mnt/extra-addons"]
+
+RUN chown -R openerp /mnt/extra-addons /mnt/oefilestore /opt/oe7 /home/openerp
+RUN chown -R :9900 /home/openerp
+EXPOSE 8069
+
+# Copy entrypoint script and Odoo configuration file
+COPY ./entrypoint.sh /
+COPY ./openerp-server.conf /etc/openerp/
+USER openerp
+WORKDIR /opt/workspace
+
+ENV PATH "$PATH:/opt/oe7"
+ENTRYPOINT ["/entrypoint.sh"]
+CMD ["/opt/oe7/openerp-server"]
--- /dev/null
+#!/bin/bash
+
+USER_ID=${LOCAL_USER_ID:-9001}
+sudo usermod -u $USER_ID openerp
+
+set -e
+
+# set the postgres database host, port, user and password according to the environment
+# and pass them as arguments to the odoo process if not present in the config file
+: ${HOST:=${DB_PORT_5432_TCP_ADDR:='db'}}
+: ${PORT:=${DB_PORT_5432_TCP_PORT:=5432}}
+: ${USER:=${DB_ENV_POSTGRES_USER:=${POSTGRES_USER:='odoo'}}}
+: ${PASSWORD:=${DB_ENV_POSTGRES_PASSWORD:=${POSTGRES_PASSWORD:='odoo'}}}
+
+DB_ARGS=()
+function check_config() {
+ param="$1"
+ value="$2"
+ if ! grep -q -E "^\s*\b${param}\b\s*=" "$OPENERP_SERVER" ; then
+ DB_ARGS+=("--${param}")
+ DB_ARGS+=("${value}")
+ fi;
+}
+check_config "db_host" "$HOST"
+check_config "db_port" "$PORT"
+check_config "db_user" "$USER"
+check_config "db_password" "$PASSWORD"
+
+case "$1" in
+ -- | openerp-server)
+ shift
+ if [[ "$1" == "scaffold" ]] ; then
+ exec openerp-server "$@"
+ else
+ exec openerp-server "$@" "${DB_ARGS[@]}"
+ fi
+ ;;
+ -*)
+ exec openerp-server "$@" "${DB_ARGS[@]}"
+ ;;
+ *)
+ exec "$@"
+esac
+
+exit 1
--- /dev/null
+#!/bin/bash
+#Empty check not input parameter and actions
+EMPTY=0
+if [ $# -eq 0 ]; then
+ EMPTY=1
+fi
+lastParamenter=${!#}
+#inputParameter=$@
+#Compare string with list string
+containsAction(){
+ local e
+ for e in "${@:2}"; do [[ "${e,,}" == "${1,,}" ]] && return 1; done
+ return 0
+}
+descriptionFunction(){
+ echo -e "\t./pgtools paramneters Action"
+ echo -e "\t* ACTIONS:"
+ echo -e "\tlist: List all database in Postgre Server"
+ echo -e "\tdbsize: Show size of Database"
+ echo -e "\tcreate: Create new database (required DBNAME (-d) in paramneters)"
+ echo -e "\tbackup: Backup a database (required DBNAME (-d) in paramneters)"
+ echo -e "\trestore: Restore a database (required DBNAME (-d) in paramneters)"
+ echo -e "\tdrop: Drop a database (required DBNAME (-d) in paramneters)"
+ echo -e "\t* PARAMETERS:"
+ echo -e "\t-C= or --container= :Name of container. This parameter is required"
+ echo -e "\t-D= or --dbname= :Name of Database. This parameter is required using with Create, Restore, Drop and Backup database"
+ echo -e "\t-F= or --file= :Name of file using for Backup, Restore"
+}
+
+RestoreDB(){
+ if [ -f $FILE ]; then
+ FULLPATH=$(cd $(dirname "$FILE") && pwd -P)/$(basename "$FILE")
+ docker exec -it $CONTAINER mkdir -p oetemp
+ docker cp $FULLPATH $CONTAINER:/oetemp
+ FILENAME=$(basename $FULLPATH)
+ echo "Please wait a few minutes"
+ docker exec -it $CONTAINER su -c "pg_restore -F t -d $DBNAME /oetemp/$FILENAME" postgres
+ docker exec -it $CONTAINER rm /oetemp -rf
+ else
+ echo "File not found"
+ fi
+ }
+BackupDB(){
+ echo "Please wait a few minutes"
+ docker exec -it $CONTAINER mkdir oetemp
+ docker exec -it $CONTAINER su -c "pg_dump -F t -f /oetemp/$FILE $DBNAME" postgres
+ docker cp $CONTAINER:/oetemp/$FILE .
+ docker exec -it $CONTAINER rm /oetemp -rf
+ }
+
+LISTACTIONS=("list" "restore" "backup" "dbsize" "create" "drop")
+containsAction "$lastParamenter" "${LISTACTIONS[@]}"
+if [[ $EMPTY == 1 || "$?" == 0 ]]; then
+ descriptionFunction
+ echo "* Please check parameter and Action *"
+ exit 1
+else
+ # whatever you want to do when arr doesn't contain value
+ for i in "$@"
+ do
+ case $i in
+ -C=*|--container=*)
+ CONTAINER="${i#*=}"
+ shift # past argument=value
+ ;;
+ -F=*|--file=*)
+ FILE="${i#*=}"
+ shift # past argument=value
+ ;;
+ -D=*|--dbname=*)
+ DBNAME="${i#*=}"
+ shift # past argument=value
+ ;;
+ *)
+ # unknown option
+ ;;
+ esac
+ done
+ #Check Container
+ if [[ -z $CONTAINER ]]; then
+ descriptionFunction
+ echo "* Incomplete container parameter *"
+ exit 1
+ fi
+ #List Action
+ if [[ "${lastParamenter,,}" == "list" ]]; then
+ docker exec -it $CONTAINER su -c "psql --list" postgres
+ exit 1
+ fi
+
+ #DBSize Action
+ if [[ "${lastParamenter,,}" == "dbsize" ]]; then
+ #Not Input
+ if [[ -z $DBNAME ]]; then
+ docker exec -it $CONTAINER su -c 'psql -c "select t1.datname AS db_name, pg_size_pretty(pg_database_size(t1.datname)) as db_size from pg_database t1 order by pg_database_size(t1.datname) desc;"' postgres
+ exit 1
+ else
+ docker exec -it $CONTAINER su -c 'psql -c "select t1.datname AS db_name, pg_size_pretty(pg_database_size(t1.datname)) as db_size from pg_database t1 where t1.datname ilike '\'$DBNAME\'';"' postgres
+ exit 1
+ fi
+ fi
+
+ #Check DBNAME
+ if [[ -z $DBNAME ]]; then
+ descriptionFunction
+ echo "* Please check DBNAME parameter *"
+ exit 1
+ fi
+
+ #Create Action
+ if [[ "${lastParamenter,,}" == "create" ]]; then
+ docker exec -it $CONTAINER su -c "psql -c 'CREATE DATABASE \"$DBNAME\" encoding='\'utf8\'';'" postgres
+ #Kha la phuc tap Export DBNAME='$DBNAME' (truyen ten databse vao container environment)
+ docker exec -it $CONTAINER su -c 'export DBNAME='$DBNAME' && psql -c "ALTER DATABASE \"$DBNAME\" OWNER TO $POSTGRES_USER;"' postgres
+ if [[ $FILE ]]; then
+ RestoreDB
+ fi
+ exit 1
+ fi
+
+ #Restore Action
+ if [[ "${lastParamenter,,}" == "restore" ]]; then
+ if [[ $FILE ]]; then
+ RestoreDB
+ fi
+ exit 1
+ fi
+
+ #Backup Action
+ if [[ "${lastParamenter,,}" == "backup" ]]; then
+ BackupDB
+ exit 1
+ fi
+
+ #Drop Action
+ if [[ "${lastParamenter,,}" == "drop" ]]; then
+ docker exec -it $CONTAINER su -c "dropdb \"$DBNAME\";" postgres
+ exit 1
+ fi
+fi
\ No newline at end of file