This is a complete guide for how I lay out Odoo deploys, and projects, that is optimized for development and deploy using Git and Docker.
Note that whenever I give an example of an owner UID or GUID, they are when deploying or migrating to native Linux. When using the "native" MacOS Docker, the folders must be owned by the user that is invoking Docker.
The Project Directory
This directory forms the base of the site repository. This includes the `docker-compose.yml` file and several folders for data and source code.
Typically I name it after the company or feature that needs some testing like 'hibou' or 'abc-odoo'. All future directory structure will be relative to this one.
Data Persistence
/var/data/postgres/9.5/pgdata
Mount for storing the database files. As outlined on the official Postgres Docker image, this will be a non-standard filesystem directory pointed to by an environment variable, `PGDATA=/var/lib/postgres/data/pgdata`. When moving to a new version of Postgres, one simply needs to create a new numbered folder and migrate into it.
When deploying on Linux, this folder will end up being owned by the postgres user and group (999:999).
/var/data/odoo
Mount point for storing Odoo's sessions, file attachments and uploaded modules. This will be owned by the Odoo user (uid: 104).
Container Configuration
/var/conf/odoo
Mounted volume to store your Odoo configuration files. I recommend taking the basic file, making modifications to add-on folders and other deploy changes, then making a copy of it with a file extension of `.sample`. This way you can simply copy and rename this file in deploy specific scenarios (and passwords) without committing these to your Git repo.
/var/conf/nginx
Mounted volume for the nginx proxy. Basically take a generic `/etc/nginx` directory as the base. Modify the sites-enabled directory for deploy specific configuration and domain names.
Source Code
/src
Main mount point for customizations and additional packages. I usually mount this to `/opt/odoo`, so use that appropriately when modifying your Odoo configuration files.
/src/addons
First level add-ons. Generally I have Git submodules in `/src` and symlinks to individual modules in `/src/addons`. Since you can commit relative symlinks safely (at least on Linux and MacOS) this provides a very versatile way of maintaining a growing list of custom extensions.
/src/odoo
Not strictly required, but having a clone of the main source makes it easy to test changes and patches while giving you some code completion and search in any IDE.
Additionally, you can mount parts of this directory over internal Odoo docker image folders to make the Odoo server container run your branch of Odoo core.
/src/enterprise
Another optional Git submodule or folder to contain Odoo Enterprise packages.
Docker Compose
Here is a sample `docker-compose.yml` file that you can use to put this all together.
version: '2'
services:
db:
environment:
- POSTGRES_PASSWORD=odoo_db_pass
- POSTGRES_USER=odoo
- PGDATA=/var/lib/postgresql/data/pgdata
image: postgres:9.5
networks:
- backend
volumes:
- "./var/data/postgres/9.5/pgdata:/var/lib/postgresql/data/pgdata"
odoo:
depends_on:
- db
image: hibou/odoo:9.0
networks:
- backend
- frontend
volumes:
- "./var/conf/odoo:/etc/odoo"
- "./var/data/odoo:/var/lib/odoo"
- "./src/:/opt/odoo"
nginx:
depends_on:
- odoo
image: nginx:1.9
networks:
- frontend
volumes:
- "./var/conf/nginx/:/etc/nginx:ro"
networks:
backend:
frontend:
You might notice that there are no exposed ports, you should create a `docker-compose.override.yml.sample` file like above to expose ports and do any extra remapping or environment variables. Here is an example.
version: '2'
services:
db:
environment:
- POSTGRES_PASSWORD=some_better_pass_for_first_launch
ports:
- "127.0.0.1:5432:5432"
odoo:
volumes:
- "./src/odoo/openerp:/usr/local/lib/python2.7/site-packages/openerp"
nginx:
ports:
- "80:80"
- "443:443"
Future
This structure has served me well, both in terms of my own development and production site, as well as client sites and deployments. Eventually I will create a git repo with all of these ideas to be able to quickly fork and create new projects. Odoo Blueprint
Stay tuned...