indaclouds.fr

Some tips when I take time to write them down.

Part 3 - Build a docker image


In this post, we'll create a custom docker image of odoo that fits our need.

Create a Docker file to the root folder of your addon/repo:

$ cd ~/odoo-docker/addons/my_awesome_addon
$ touch Dockerfile

Copy these lines into the file:

FROM odoo:latest

USER root
RUN apt update && apt install -y --no-install-recommends git

WORKDIR /tmp/
COPY ./ /tmp/
RUN python setup.py install

USER odoo

First, we tell docker that our image is based on the latest from odoo. Then, as root user, we install git to be able to install python dependencies from pip with git.

Finally, we copy our addon into the image and install it in python environment, then get back to odoo user.

Now, we can build the image and run the container:

$ docker build -t odoo-my-awesome-addon:10 .
$ docker run -p 8069:8069 --name my-container --link db-docker:db odoo-my-awesome-addon:10 -d new_database -i my_awesome_addon

You can access odoo with the web interface. Select the right database, check that your addon is installed.

Once done, imagine that our addon depends of an OCA addon, for example partner_firstname of partner-contact repo.

Adding the dependency to partner_contact in the manifest makes it only really required when odoo is launched. To make it required at our module installation we need to update our setup.py and adding a requirement file for pip. (not sure why I can't use setuptools)

Add required depencies to setup.py:

import setuptools

setuptools.setup(
    setup_requires=['setuptools-odoo'],
    odoo_addon={
        'depends_override': {
            'partner_firstname': 'odoo10-addon-partner-firstname',
        },
    },
    dependency_links=[
        'https://wheelhouse.odoo-community.org/oca/'  # Not working for some reason..
    ]
)

And to be able to install it with pip, add the project a requirements.txt with this content:

-f https://wheelhouse.odoo-community.org/oca/

odoo10-addon-partner_firstname

Now you can install your addon with pip:

$ pip install -r requirements.txt -e . (equivalent to python setup.py develop)
$ pip install -r requirements.txt . (equivalent to python setup.py install)

Edit the Dockerfile to use the new command to install the addon. Rebuild the image and run the container. Check that your addon and partner_firstname are installed.

Think to save the changes:

$ git add --all
$ git commit -m "Allow creation of a custom docker image of odoo"
$ git push