Creating Your Odoo Dev Environment
Spinning up an Odoo development environment can be an excercise in frustration. The Odoo docs don't give much, and everyone has their own opinions online. Searching github will give a page of results, of various qualities. Below is my notes - what I've found important in developing Odoo over the last ~8 years
Dockerize!
Put everything in docker. This makes it trivial to re-install, restore the database, avoids dependency issues, etc. Docker Compose is best to avoid the requirement to remember some strange docker run commands.
Keep it Lean!
Use the standard Odoo base image - don't build anything unless you have to.
## boilerplate docker-compose.yml file for my odoo builds
services:
db:
image: postgres:14 ## or your version
volumes:
- ./data-db/:/var/lib/postgresql/data/pgdata
- ./dumps/:/tmp/dumps
environment:
- POSTGRES_USER=odoo
- POSTGRES_PASSWORD=odoo
- POSTGRES_DB=odoo
- PGDATA=/var/lib/postgresql/data/pgdata
command: ["postgres", "-c", "log_statement=all"]
odoo:
image: odoo:17 ## or your version
depends_on:
- db
ports:
- "8069:8069/tcp"
- "8071:8071/tcp"
volumes:
- ./data-dir:/var/lib/odoo
- ./addons:/opt/odoo/custom/addons # custom addons
- ./odoo17-source:/opt/odoo/odoo17-source # base odoo code
- ./config:/etc/config
- ./scripts:/scripts
environment:
- ODOO_RC=etc/config/odoo.conf
- ODOO_DB_PASS=odoo
- ODOO_DB_USER=odoo
- POSTGRES_DB_HOST=db
- POSTGRES_DB_PORT=5432
- DB_NAME=odoo
entrypoint: ['tail', '-f','/dev/null']
Notes:
Using the above assumes a working knowledge of docker-compose, odoo, and postgres. Some of the key things that I have found helpful are:
- Don't start the Odoo process on container startup! - Contrary to how docker is meant to work, it's easier to bring it up with 'tail -f /dev/null'. The container will start & do nothing - this means you can have a script outside of the odoo container, to start/stop the Odoo process. This allows a much, much faster feedback loop, thank restarting the container every time you need to make a change. I like to do 'docker compose up -d' - and then stop thinking about docker.
- Database in Docker! - Configging Odoo to find your database on your host can be a PITA. It may be on any one of different IP addresses, or 'host.docker.internal'. Having it in the container means that you can always rely on Odoo finding it through 'db'.
- Load in the source! - Having the odoo base code in your repo and mounted in the container makes it super easy to grep, debug, troubleshoot, etc. If you're feeling risque, you can even edit the base code!. Although this is not usually recommended, it's handy for quickly debugging things. And occassionally, we've all hacked some of the source, haven't we....
Useful Scripts
Running the Odoo process: I have a script in the root dir called 'run.sh'. It does what it says on the tin.
#! /bin/bash
helpmessage="
Info: use --upgrade [module1,module2] to upgrade modules]
Info: use --shell to access shell
Info: use --script to run a script in the Odoo env
Info: run without any args to start odoo web server (default behaviour)
"
APP=odoo
if [ "$#" -gt 0 ]; then
first_arg="$1"
case "$first_arg" in
"--upgrade")
shift ## pop the arg off
### uses --upgrade to upgrade certain modules
docker compose exec -it $APP /scripts/entrypoint.sh --no-xmlrpc --stop-after-init -u "$@"
;;
"--shell")
docker compose exec -it $APP /scripts/odoo-shell.sh
;;
"--script")
docker compose exec -it -T $APP sh -c "/scripts/odoo-shell.sh - " < $2
;;
"-h")
echo "$helpmessage"
;;
*)
echo "$helpmessage"
;;
esac
else
docker compose exec -it $APP /scripts/entrypoint.sh "$@"
fi
Running './run.sh' will start up the Odoo process. Running with '--upgrade' X will upgrade module X. Running with --script 'scriptx.py' will allow you to pipe a python script into the shell (this is useful for tasks where you want to directly run ORM code) The script will need to be in a directory that is mounted inside the Odoo container. This could be better written, but I'm not much of a bashman.
Other scripts
Scripts used above
entrypoint.sh -- the main entrypoint that ./run.sh will run
#!/bin/bash
# entrypoint.sh
/opt/odoo/odoo10-source/odoo-bin "$@" --dev=reload
odoo-shell.sh -- used to fire up a shell. Later versions of odoo don't use --no-xmlrpc, they use --no-http instead
#!/bin/bash
/opt/odoo/odoo10-source/odoo-bin shell --no-xmlrpc
Other thoughts
If you're running multiple / many instances of Odoo, it can help to put your Odoo database on a remote host / VPS / etc. The db can be quite heavy, especially for larger instances, so having it remote will make things a bit easier.
This is not a production-ready setup - wait for my Odoo in Production post!