Files
odoocker/README.md
2023-08-25 02:08:56 -05:00

9.9 KiB

Setup

  1. Clone the repository:
git clone git@github.com:yhaelopez/odoocker.git
  1. Copy the .env.example and docker-compose.override.local.yml
cp .env.example .env && cp docker-compose.override.local.yml docker-compose.override.yml
  1. Manually add entry to your hosts file 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.

  1. Make sure APP_ENV=fresh.
  2. Run
docker-compose up -d --build && docker-compose logs -f odoo
  1. Navigate to the DOMAIN in your browser.
  2. Create Database form will be displayed.
  3. Create Fresh DB.
  4. Stop the Odoo container:
docker-compose stop odoo
  1. Set Local environment.

Restore Environment

This environment will have no database created and it's ready to make an import on the production database.

  1. Set APP_ENV=restore.
  2. Run:
docker-compose up -d --build && docker-compose logs -f odoo
  1. Navigate to the DOMAIN in your browser & Restore the production database
  2. Stop the Odoo container:
docker-compose stop odoo
  1. Set Local environment.

If you are in a production server:

  1. Run Staging environment.
  2. Stop the Odoo container:
docker-compose stop odoo
  1. Run the Production environment.

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.

  1. Make sure APP_ENV=full.
  2. Make sure DB_NAME=odoo or whatever name you want.
  3. Run
docker-compose up -d --build && docker-compose logs -f odoo
  1. Navigate to the DOMAIN in your browser.
  2. Log in using the default credentials
Email: admin
Password: admin
  1. Stop the Odoo container:
docker-compose stop odoo
  1. Set Local environment.

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.

  1. Make sure APP_ENV=local.
  2. Make sure DB_NAME is set.
  3. Set UPDATE=module1,module2,module3.
  4. Run:
docker-compose up -d --build && docker-compose logs -f odoo
  1. Navigate to the DOMAIN in your browser.
  2. Start coding!
  3. 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.

  1. Make sure APP_ENV=debug.
  2. Make sure DB_NAME is set.
  3. Set UPDATE=module1,module2,module3.
  4. Run:
docker-compose up -d --build && docker-compose logs -f odoo
  1. Navigate to the DOMAIN in your browser.
  2. Mark breakpoints through the code.
  3. Start VSCode Debugger
  4. Start debugging!
  5. 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.

  1. Set APP_ENV=testing.
  2. Set ADDONS_TO_TEST=addon_1,addon_2.
  3. Set TEST_TAGS=test_tag_1,test_tag_2 to fitler tests.
  4. 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

  1. Set APP_ENV=staging
  2. Set DB_NAME to the desired one.
  3. Set INIT if there are any.
  4. Run
git pull && docker-compose down && docker-compose pull && docker-compose build --no-cache && docker-compose up -d && docker-compose logs -f odoo
  1. Check Odoo continues to work as expected.
  2. 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.

  1. Set APP_ENV=production
  2. Set prod DB_NAME.
  3. Set prod DB_PASSWORD.
  4. Set prod ADMIN_PASSWD.
  5. Set prod DOMAIN (make sure DNS are pointing to your instance).
  6. Run Restore environment
  7. Run Staging environment.
  8. Repace the docker-compose.override.yml with docker-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
  1. 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

  1. Log into the odoo container
docker-compose exec -u root odoo
  1. Navigate to custom addons folder inside the container
cd /usr/lib/python3/dist-packages/odoo/custom-addons
  1. Create new addons running:
odoo scaffold <addon_name>
  • The new addon will be available in the odoo/custom_addons folder in this project.

Using Odoo Shell

  1. Log into the odoo container
docker-compose exec odoo bash
  1. Start Odoo shell running:
odoo shell --http-port=8071

DB Connection

  • Any other Postgres Database Manager con connect to the DB using .env credentials.

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.

  1. Backup the production Databases from /web/database/manager.
  2. Run
sudo apt update && sudo apt upgrade -y
  • If packages are kept, install them
sudo apt install <kept packages>
  1. Restart the server
sudo reboot
  • Make sure there are no more upgrades or possible kept packages
sudo apt update && sudo apt upgrade -y
  1. Go to the project folder in /home/ubuntu or (~)
cd ~/odoo-icomsa

or with alias:

odoo
  1. Pull the latest main branch changes.
git pull origin main
  1. Set Staging environment
  2. Set APP_ENV=production
  3. 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