PHPFixing
  • Privacy Policy
  • TOS
  • Ask Question
  • Contact Us
  • Home
  • PHP
  • Programming
  • SQL Injection
  • Web3.0
Showing posts with label default. Show all posts
Showing posts with label default. Show all posts

Tuesday, October 18, 2022

[FIXED] How to customise docker-compose containing the odoo app and postgresql with non default database name, user name and password?

 October 18, 2022     default, docker, docker-compose, odoo, postgresql     No comments   

Issue

I have an application (odoo, but my question may be for any app, I don't know) and a database with database default name, user and password. All is launched with docker-compose. With these default values, it works great (I have copy/pasted only what is relevant):

  db:
    image: postgres:14
    user: root
    environment:
      - POSTGRES_PASSWORD=odoo
      - POSTGRES_USER=odoo
      - POSTGRES_DB=postgres
  volumes:
      - ./postgresql:/var/lib/postgresql/data
  web:
    image: odoo:15
    user: root
    depends_on:
      - db
    environment:
      - HOST=db
      - USER=odoo
      - PASSWORD=odoo
  volumes:
      - ./etc:/etc/odoo
      - ./odoo-data:/var/lib/odoo

There is also a config file etc/odoo.conf which needs to be updated and I did (here the default values):

db_name = postgres
db_user = odoo
db_password = odoo

If for example I set the password to 123, the user name to my and the database name to mydb, remove the containers and suppress ./postgresql to restart clean, I get the following error from the database host:

odoo-db-1   | 2022-09-18 15:08:17.420 UTC [908] FATAL:  password authentication failed for user "my"
odoo-db-1   | 2022-09-18 15:08:17.420 UTC [908] DETAIL:  Role "my" does not exist.

Of course, I have updated both the docker-compose and odoo.conf files with my values.

What could I miss? My investigations at this point have failed.

Here is my docker-compose file:

version: '2'
services:
  db:
    image: postgres:14
    user: root
    environment:
      - POSTGRES_DB_FILE=/run/secrets/postgresql_db
      - POSTGRES_USER_FILE=/run/secrets/postgresql_user
      - POSTGRES_PASSWORD_FILE=/run/secrets/postgresql_password
    restart: always             # run as a service
    volumes:
        - ./postgresql:/var/lib/postgresql/data
    secrets:
      - postgresql_user
      - postgresql_password
      - postgresql_db

  web:
    image: odoo:15
    user: root
    depends_on:
      - db
    ports:
      - "10013:8069"
      - "20013:8072" # live chat
    tty: true
    command: --
    environment:
      - HOST=db
      - USER_FILE=/run/secrets/postgresql_user
      - PASSWORD_FILE=/run/secrets/postgresql_password
    volumes:
      - /etc/timezone:/etc/timezone:fr
      - /etc/localtime:/etc/localtime:fr
      - ./addons:/mnt/extra-addons
      - ./etc:/etc/odoo
      - ./odoo-data:/var/lib/odoo
    secrets:
      - postgresql_user
      - postgresql_password
    restart: always             # run as a service

secrets:
  postgresql_db:
    file: odoo_pg_db
  postgresql_user:
    file: odoo_pg_user
  postgresql_password:
    file: odoo_pg_pass

Here is my etc/odoo.conf:

[options]
addons_path = /mnt/extra-addons
data_dir = /etc/odoo
admin_passwd = "my_own_admin_password"
logfile = /etc/odoo/odoo-server.log
db_name = my_db
db_user = myself
db_password = "my_db_user_password"
dev_mode = reload

The entrypoint.sh:

#!/bin/bash

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'}}}

# install python packages
pip3 install pip --upgrade
pip3 install -r /etc/odoo/requirements.txt

# sed -i 's|raise werkzeug.exceptions.BadRequest(msg)|self.jsonrequest = {}|g' /usr/lib/python3/dist-packages/odoo/http.py

DB_ARGS=()
function check_config() {
    param="$1"
    value="$2"
    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}")
    DB_ARGS+=("${value}")
}
check_config "db_host" "$HOST"
check_config "db_port" "$PORT"
check_config "db_user" "$USER"
check_config "db_password" "$PASSWORD"

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[@]}"
        ;;
    *)
        exec "$@"
esac

exit 1

And:

cat odoo_pg_db
my_db
cat odoo_pg_user
myself
cat odoo_pg_pass
my_db_user_password

And my project folder tree:

.
├── addons
│   └── readme.md
├── docker-compose.yml
├── entrypoint.sh
├── etc
│   ├── addons
│   │   └── 15.0
│   ├── odoo.conf
│   ├── odoo.conf.meld
│   ├── odoo-server.log
│   ├── requirements.txt
│   └── sessions
├── odoo-data
├── odoo_pg_db
├── odoo_pg_pass
├── odoo_pg_user
├── postgresql [error opening dir]
├── README.md
├── run.sh
└── screenshots
    ├── odoo-13-apps-screenshot.png
    ├── odoo-13-sales-form.png
    ├── odoo-13-sales-screen.png
    └── odoo-13-welcome-screenshot.png

The odoo:15 dockerfile does not include hard written database name nor user regarding the database, only an app user set to odoo, but this is for the web app. It makes use of a config file with the default database name user and password like depicted above, but I provide the modified one with my values. The docker files makes use of ENV to refer to it: ENV ODOO_RC /etc/odoo/odoo.conf. Then it runs an entrypoint containing:

DB_ARGS=()
function check_config() {
    param="$1"
    value="$2"
    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}")
    DB_ARGS+=("${value}")
}
check_config "db_host" "$HOST"
check_config "db_port" "$PORT"
check_config "db_user" "$USER"
check_config "db_password" "$PASSWORD"

With these check_config, it gets my values from the config file.

The postgres:14 dockerfile contains only the superuser name postgres set with a useradd.

Note: of course, there is more to be done after this like replace root user, use Docker secrets, but that's another topic.


Solution

The postgresql folder contents were not suppressed with sudo rm -fr postgresql/* while the containers were deleted, since created with the odoo user. I have to do sudo chmod -R 777 postgresql before.

Now I can see in the docker console that the environment variables are correctly set. Other problems now, but this one is solved.



Answered By - lalebarde
Answer Checked By - David Marino (PHPFixing Volunteer)
Read More
  • Share This:  
  •  Facebook
  •  Twitter
  •  Stumble
  •  Digg

Saturday, July 9, 2022

[FIXED] What is the equivalent in F# of the C# default keyword?

 July 09, 2022     c#, c#-to-f#, default, f#, keyword     No comments   

Issue

I'm looking for the equivalent of C# default keyword, e.g:

public T GetNext()
{
    T temp = default(T);
            ...

Thanks


Solution

I found this in a blog: "What does this C# code look like in F#? (part one: expressions and statements)"

C# has an operator called "default" that returns the zero-initialization value of a given type:

default(int) 

It has limited utility; most commonly you may use default(T) in a generic. F# has a similar construct as a library function:

Unchecked.defaultof<int>


Answered By - blu
Answer Checked By - David Goodson (PHPFixing Volunteer)
Read More
  • Share This:  
  •  Facebook
  •  Twitter
  •  Stumble
  •  Digg

[FIXED] What does "default" mean after a class' function declaration?

 July 09, 2022     c++, c++11, declaration, default, keyword     No comments   

Issue

I've seen default used next to function declarations in a class. What does it do?

class C {
  C(const C&) = default;
  C(C&&) = default;
  C& operator=(const C&) & = default;
  C& operator=(C&&) & = default;
  virtual ~C() { }
};

Solution

It's a new C++11 feature.

It means that you want to use the compiler-generated version of that function, so you don't need to specify a body.

You can also use = delete to specify that you don't want the compiler to generate that function automatically.

With the introduction of move constructors and move assignment operators, the rules for when automatic versions of constructors, destructors and assignment operators are generated has become quite complex. Using = default and = delete makes things easier as you don't need to remember the rules: you just say what you want to happen.



Answered By - Peter Alexander
Answer Checked By - Marilyn (PHPFixing Volunteer)
Read More
  • Share This:  
  •  Facebook
  •  Twitter
  •  Stumble
  •  Digg

Thursday, April 21, 2022

[FIXED] How to replace default hikari cp to tomcat pool on spring boot 2.0

 April 21, 2022     connection, default, pool, spring-boot, tomcat     No comments   

Issue

I have migrated spring boot application to 2.0 and found out some problems with hikari connection pool. When I am fetching database data this results to hikari cp timeout ie. connection is not available. I don't know why when in the previous version this worked correctly.

Therefore I tried to use tomcat pool with this config in application.yml but it did not work (in correct YAML formatting).

spring.datasource.type=org.apache.tomcat.jdbc.pool.DataSource

My pom.xml has these dependencies related to DB things:

spring-boot-jpa
spring-boot-jdbc
jdbc7

How to exclude hikari and use tomcat connection pool?


Solution

I have found out the solution. This can be resolved in pom.xml by modifying like that:

<dependency>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-starter-jdbc</artifactId>
    <exclusions>
        <exclusion>
            <groupId>com.zaxxer</groupId>
            <artifactId>HikariCP</artifactId>
        </exclusion>
    </exclusions>
</dependency>

<dependency>
    <groupId>org.apache.tomcat</groupId>
    <artifactId>tomcat-jdbc</artifactId>
</dependency>

However the hikari problem was probably with default small size of connection pool. So this problem could be resolved also with this change but not verified by myself. Just note for others. Something like that:

spring.datasource.hikari.connection-timeout=60000
spring.datasource.hikari.maximum-pool-size=5


Answered By - Luke
Answer Checked By - Katrina (PHPFixing Volunteer)
Read More
  • Share This:  
  •  Facebook
  •  Twitter
  •  Stumble
  •  Digg
Older Posts Home
View mobile version

Total Pageviews

Featured Post

Why Learn PHP Programming

Why Learn PHP Programming A widely-used open source scripting language PHP is one of the most popular programming languages in the world. It...

Subscribe To

Posts
Atom
Posts
All Comments
Atom
All Comments

Copyright © PHPFixing