9.9 KiB
		
	
	
	
	
	
	
	
			
		
		
	
	Setup
- Clone the repository:
 
git clone git@github.com:yhaelopez/odoocker.git
- Copy the 
.env.exampleanddocker-compose.override.local.yml 
cp .env.example .env && cp docker-compose.override.local.yml docker-compose.override.yml
- Manually add entry to your 
hostsfile as below 
echo '127.0.0.1 erp.icomsa.test' | sudo tee -a /etc/hosts
echo '127.0.0.1 pgadmin.icomsa.test' | sudo tee -a /etc/hosts
- For Windows, go to 
C:\Windows\System32\drivers\etc\, and add this line: 
127.0.0.1 erp.icomsa.test
127.0.0.1 pgadmin.icomsa.test
In order to understand how each environment works, take a look at odoo/entrypoint.sh.
Default Master Password: odoo
Fresh Environment
This environment will have no database created.
The env.example is ready for this stage, no modifications are needed on .env.
- Make sure 
APP_ENV=fresh. - Run
 
docker-compose up -d --build && docker-compose logs -f odoo
- Navigate to the 
DOMAINin your browser. - Create Database form will be displayed.
 - Create Fresh DB.
 - Stop the Odoo container:
 
docker-compose stop odoo
- Set 
Localenvironment. 
Restore Environment
This environment will have no database created and it's ready to make an import on the production database.
- Set 
APP_ENV=restore. - Run:
 
docker-compose up -d --build && docker-compose logs -f odoo
- Navigate to the 
DOMAINin your browser & Restore the production database - Stop the Odoo container:
 
docker-compose stop odoo
- Set 
Localenvironment. 
If you are in a production server:
- Run 
Stagingenvironment. - Stop the Odoo container:
 
docker-compose stop odoo
- Run the 
Productionenvironment. 
Full Environment
This environment will initialize a database with DB_NAME and install the INSTALLED_MODULES.
This allows us to have a fresh production database replica.
- Make sure 
APP_ENV=full. - Make sure 
DB_NAME=odooor whatever name you want. - Run
 
docker-compose up -d --build && docker-compose logs -f odoo
- Navigate to the 
DOMAINin your browser. - Log in using the default credentials
 
Email: admin
Password: admin
- Stop the Odoo container:
 
docker-compose stop odoo
- Set 
Localenvironment. 
Local Environment
This environment will help us install / update the specific modules we are working on.
It's recommended to use this environment after Fresh, Full or Restore environments are run.
- Make sure 
APP_ENV=local. - Make sure 
DB_NAMEis set. - Set 
UPDATE=module1,module2,module3. - Run:
 
docker-compose up -d --build && docker-compose logs -f odoo
- Navigate to the 
DOMAINin your browser. - Start coding!
 - Any change you make to your packages, run:
 
docker-compose restart odoo && docker-compose logs -f odoo
- If you need to change a .env variable, run:
 
docker-compose up -d --build && docker-compose logs -f odoo
Debug Environment
This environment will bring up Odoo with debugpy library.
It's recommended to use this environment after Fresh, Full or Restore environments are run.
It works the same exact way as Local, since it respects any change in .env file.
- Make sure 
APP_ENV=debug. - Make sure 
DB_NAMEis set. - Set 
UPDATE=module1,module2,module3. - Run:
 
docker-compose up -d --build && docker-compose logs -f odoo
- Navigate to the 
DOMAINin your browser. - Mark breakpoints through the code.
 - Start VSCode Debugger
 - Start debugging!
 - Continue coding as if you were in 
Local 
Testing Environment
This environment will help us test the modules we are developing to ensure a safe deployment.
A test_* database is automagically created, addons to test get installed, test are filtered and run by their tags.
Odoo will stop after running the tests.
- Set 
APP_ENV=testing. - Set 
ADDONS_TO_TEST=addon_1,addon_2. - Set 
TEST_TAGS=test_tag_1,test_tag_2to fitler tests. - Run:
 
docker-compose down && docker-compose up -d --build && docker-compose logs -f odoo
Staging Environment
This environment performs a full update on all installed modules to test if they all can be upgraded at once.
This also allows to install new packages through INIT
- Set 
APP_ENV=staging - Set 
DB_NAMEto the desired one. - Set 
INITif there are any. - Run
 
git pull && docker-compose down && docker-compose pull && docker-compose build --no-cache && docker-compose up -d && docker-compose logs -f odoo
- Check Odoo continues to work as expected.
 - Change environment immediatly after finish testing.
 
Do not bring down & up again unless you want to perform a whole update again.
Production Environment
This environment has a preset of settings to work in production. Some .env variables won't work because are overwritten in the odoo command.
Let's imagine we are migrating a database from another server.
- Set 
APP_ENV=production - Set prod 
DB_NAME. - Set prod 
DB_PASSWORD. - Set prod 
ADMIN_PASSWD. - Set prod 
DOMAIN(make sure DNS are pointing to your instance). - Run 
Restoreenvironment - Run 
Stagingenvironment. - Repace the 
docker-compose.override.ymlwithdocker-compose.override.production.yml. This will bring Let's Encrypt (Nginx-Proxy/Acme-Companion) container 
cp docker-compose.override.production.yml docker-compose.override.yml
- Rebuild the containers
 
docker-compose down && docker-compose up -d --build && docker-compose logs odoo
Pro(d) Tips
The following tips will enhance your developing and production experience.
Define the following aliases:
alias odoo='cd odoo-icomsa'
alias hard-deploy='git pull && docker-compose down && docker-compose pull && docker-compose build --no-cache && docker-compose up -d && docker-compose logs -f odoo'
alias deploy='git pull && docker-compose down && docker-compose pull && docker-compose build && docker-compose up -d && docker-compose logs -f --tail 2000 odoo'
alias soft-deploy='git pull && docker-compose down && docker-compose up -d --build && docker-compose logs -f --tail 2000 odoo'
alias logs='docker-compose logs -f --tail 2000 odoo'
NEVER run
docker-compose down **-v**
...without having a tested backed up database
Have in mind that dropping volumes will destroy DB data, Odoo Conf & Filestore, Let's Encrypt certificates, and more!
Also, if you do this process several times in a short period of time, you may reach Let's Encrypt certificates limits and won't be able to generate new ones after several hours.
Colorize your branches
Add the following to ~/.bashrc
# Color git branches
function parse_git_branch () {
  git branch 2> /dev/null | sed -e '/^[^*]/d' -e 's/* \(.*\)/(\1)/'
}
if [ "$color_prompt" = yes ]; then
    #PS1='${debian_chroot:+($debian_chroot)}\[\033[01;32m\]\u@\h\[\033[00m\]:\[\033[01;34m\]\w\[\033[00m\]\$ '
    # Color git branches
    PS1="${debian_chroot:+($debian_chroot)}\[\033[01;32m\]\u@\h\[\033[00m\]:\[\033[01;34m\]\w \[\033[01;31m\]\$(parse_git_branch)\[\033[00m\]\$ "
else
    PS1='${debian_chroot:+($debian_chroot)}\u@\h:\w\$ '
fi
unset color_prompt force_color_prompt
Creating new Odoo Addons
- Log into the odoo container
 
docker-compose exec -u root odoo
- Navigate to custom addons folder inside the container
 
cd /usr/lib/python3/dist-packages/odoo/custom-addons
- Create new addons running:
 
odoo scaffold <addon_name>
- The new addon will be available in the 
odoo/custom_addonsfolder in this project. 
Using Odoo Shell
- Log into the odoo container
 
docker-compose exec odoo bash
- Start Odoo shell running:
 
odoo shell --http-port=8071
DB Connection
- Any other Postgres Database Manager con connect to the DB using 
.envcredentials. 
PgAdmin Container
- This project comes with a PgAdmin container which is loaded only in 
docker-compose.override.pgadmin.yml. In order to manage DB we provide a pgAdmin container. In order to bring this up, simply run: 
docker-compose -f docker-compose.yml -f docker-compose.override.yml -f docker-compose.pgadmin.yml up -d --build
And to turn down
docker-compose -f docker-compose.yml -f docker-compose.override.yml -f docker-compose.pgadmin.yml down
If your instance has pgAdmin, make sure you adapt this to your aliases.
Deployment Process
Note: the deployment process is easier & faster with aliases.
- Backup the production Databases from 
/web/database/manager. - Run
 
sudo apt update && sudo apt upgrade -y
- If packages are kept, install them
 
sudo apt install <kept packages>
- Restart the server
 
sudo reboot
- Make sure there are no more upgrades or possible kept packages
 
sudo apt update && sudo apt upgrade -y
- Go to the project folder in /home/ubuntu or (~)
 
cd ~/odoo-icomsa
or with alias:
odoo
- Pull the latest 
mainbranch changes. 
git pull origin main
- Set 
Stagingenvironment - Set 
APP_ENV=production - Take down the containers, pull the latest images from docker hub, and rebuild the containers.
 
docker-compose down && docker-compose up -d --build && docker-compose logs -f odoo