Skip to content

Commit

Permalink
add support for pip install of odoo and addons
Browse files Browse the repository at this point in the history
  • Loading branch information
JordiBForgeFlow authored and sebalix committed Jan 23, 2018
1 parent 15d810c commit c1f8496
Show file tree
Hide file tree
Showing 31 changed files with 558 additions and 3 deletions.
14 changes: 14 additions & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,48 +7,62 @@ env:
# Odoo 8.0
- IMAGE="images:debian/jessie" ODOO_VERSION=8.0 ODOO_INSTALL_TYPE=standard ANSIBLE_VERSION="2.4,<2.5"
- IMAGE="images:debian/jessie" ODOO_VERSION=8.0 ODOO_INSTALL_TYPE=buildout ANSIBLE_VERSION="2.4,<2.5"
- IMAGE="images:debian/jessie" ODOO_VERSION=8.0 ODOO_INSTALL_TYPE=pip ANSIBLE_VERSION="2.4,<2.5"
# Odoo 9.0
- IMAGE="images:debian/jessie" ODOO_VERSION=9.0 ODOO_INSTALL_TYPE=standard ANSIBLE_VERSION="2.4,<2.5"
- IMAGE="images:debian/jessie" ODOO_VERSION=9.0 ODOO_INSTALL_TYPE=buildout ANSIBLE_VERSION="2.4,<2.5"
- IMAGE="images:debian/jessie" ODOO_VERSION=9.0 ODOO_INSTALL_TYPE=pip ANSIBLE_VERSION="2.4,<2.5"
# Odoo 10.0
- IMAGE="images:debian/jessie" ODOO_VERSION=10.0 ODOO_INSTALL_TYPE=standard ANSIBLE_VERSION="2.4,<2.5"
- IMAGE="images:debian/jessie" ODOO_VERSION=10.0 ODOO_INSTALL_TYPE=buildout ANSIBLE_VERSION="2.4,<2.5"
- IMAGE="images:debian/jessie" ODOO_VERSION=10.0 ODOO_INSTALL_TYPE=pip ANSIBLE_VERSION="2.4,<2.5"
# Debian 9 (stretch)
# Odoo 8.0
- IMAGE="images:debian/stretch" ODOO_VERSION=8.0 ODOO_INSTALL_TYPE=standard ANSIBLE_VERSION="2.4,<2.5"
- IMAGE="images:debian/stretch" ODOO_VERSION=8.0 ODOO_INSTALL_TYPE=buildout ANSIBLE_VERSION="2.4,<2.5"
- IMAGE="images:debian/stretch" ODOO_VERSION=8.0 ODOO_INSTALL_TYPE=pip ANSIBLE_VERSION="2.4,<2.5"
# Odoo 9.0
- IMAGE="images:debian/stretch" ODOO_VERSION=9.0 ODOO_INSTALL_TYPE=standard ANSIBLE_VERSION="2.4,<2.5"
- IMAGE="images:debian/stretch" ODOO_VERSION=9.0 ODOO_INSTALL_TYPE=buildout ANSIBLE_VERSION="2.4,<2.5"
- IMAGE="images:debian/stretch" ODOO_VERSION=9.0 ODOO_INSTALL_TYPE=pip ANSIBLE_VERSION="2.4,<2.5"
# Odoo 10.0
- IMAGE="images:debian/stretch" ODOO_VERSION=10.0 ODOO_INSTALL_TYPE=standard ANSIBLE_VERSION="2.4,<2.5"
- IMAGE="images:debian/stretch" ODOO_VERSION=10.0 ODOO_INSTALL_TYPE=buildout ANSIBLE_VERSION="2.4,<2.5"
- IMAGE="images:debian/stretch" ODOO_VERSION=10.0 ODOO_INSTALL_TYPE=pip ANSIBLE_VERSION="2.4,<2.5"
# Odoo 11.0
- IMAGE="images:debian/stretch" ODOO_VERSION=11.0 ODOO_INSTALL_TYPE=standard ANSIBLE_VERSION="2.4,<2.5"
- IMAGE="images:debian/stretch" ODOO_VERSION=11.0 ODOO_INSTALL_TYPE=buildout ANSIBLE_VERSION="2.4,<2.5"
- IMAGE="images:debian/stretch" ODOO_VERSION=11.0 ODOO_INSTALL_TYPE=pip ANSIBLE_VERSION="2.4,<2.5"
# Ubuntu 14.04 (trusty)
# Odoo 8.0
- IMAGE="ubuntu:trusty" ODOO_VERSION=8.0 ODOO_INSTALL_TYPE=standard ANSIBLE_VERSION="2.4,<2.5"
- IMAGE="ubuntu:trusty" ODOO_VERSION=8.0 ODOO_INSTALL_TYPE=buildout ANSIBLE_VERSION="2.4,<2.5"
- IMAGE="ubuntu:trusty" ODOO_VERSION=8.0 ODOO_INSTALL_TYPE=pip ANSIBLE_VERSION="2.4,<2.5"
# Odoo 9.0
- IMAGE="ubuntu:trusty" ODOO_VERSION=9.0 ODOO_INSTALL_TYPE=standard ANSIBLE_VERSION="2.4,<2.5"
- IMAGE="ubuntu:trusty" ODOO_VERSION=9.0 ODOO_INSTALL_TYPE=buildout ANSIBLE_VERSION="2.4,<2.5"
- IMAGE="ubuntu:trusty" ODOO_VERSION=9.0 ODOO_INSTALL_TYPE=pip ANSIBLE_VERSION="2.4,<2.5"
# Odoo 10.0
- IMAGE="ubuntu:trusty" ODOO_VERSION=10.0 ODOO_INSTALL_TYPE=standard ANSIBLE_VERSION="2.4,<2.5"
- IMAGE="ubuntu:trusty" ODOO_VERSION=10.0 ODOO_INSTALL_TYPE=buildout ANSIBLE_VERSION="2.4,<2.5"
- IMAGE="ubuntu:trusty" ODOO_VERSION=10.0 ODOO_INSTALL_TYPE=pip ANSIBLE_VERSION="2.4,<2.5"
# Ubuntu 16.04 (xenial)
# Odoo 8.0
- IMAGE="ubuntu:xenial" ODOO_VERSION=8.0 ODOO_INSTALL_TYPE=standard ANSIBLE_VERSION="2.4,<2.5"
- IMAGE="ubuntu:xenial" ODOO_VERSION=8.0 ODOO_INSTALL_TYPE=buildout ANSIBLE_VERSION="2.4,<2.5"
- IMAGE="ubuntu:xenial" ODOO_VERSION=8.0 ODOO_INSTALL_TYPE=pip ANSIBLE_VERSION="2.4,<2.5"
# Odoo 9.0
- IMAGE="ubuntu:xenial" ODOO_VERSION=9.0 ODOO_INSTALL_TYPE=standard ANSIBLE_VERSION="2.4,<2.5"
- IMAGE="ubuntu:xenial" ODOO_VERSION=9.0 ODOO_INSTALL_TYPE=buildout ANSIBLE_VERSION="2.4,<2.5"
- IMAGE="ubuntu:xenial" ODOO_VERSION=9.0 ODOO_INSTALL_TYPE=pip ANSIBLE_VERSION="2.4,<2.5"
# Odoo 10.0
- IMAGE="ubuntu:xenial" ODOO_VERSION=10.0 ODOO_INSTALL_TYPE=standard ANSIBLE_VERSION="2.4,<2.5"
- IMAGE="ubuntu:xenial" ODOO_VERSION=10.0 ODOO_INSTALL_TYPE=buildout ANSIBLE_VERSION="2.4,<2.5"
- IMAGE="ubuntu:xenial" ODOO_VERSION=10.0 ODOO_INSTALL_TYPE=pip ANSIBLE_VERSION="2.4,<2.5"
# Odoo 11.0
- IMAGE="ubuntu:xenial" ODOO_VERSION=11.0 ODOO_INSTALL_TYPE=standard ANSIBLE_VERSION="2.4,<2.5"
- IMAGE="ubuntu:xenial" ODOO_VERSION=11.0 ODOO_INSTALL_TYPE=buildout ANSIBLE_VERSION="2.4,<2.5"
- IMAGE="ubuntu:xenial" ODOO_VERSION=11.0 ODOO_INSTALL_TYPE=pip ANSIBLE_VERSION="2.4,<2.5"

install:
# Spawn a LXD container
Expand Down
31 changes: 29 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,14 +1,19 @@
# Odoo [![Build Status](https://travis-ci.org/osiell/ansible-odoo.png)](https://travis-ci.org/osiell/ansible-odoo)

Ansible role to install Odoo from a Git or Mercurial repository,
Ansible role to install Odoo from a Git or Mercurial repository, or from pip,
and configure it.

This role supports two types of installation:
This role supports three types of installation:

* **standard**: install the Odoo dependencies from APT repositories and the
Odoo project from a Git/Hg repository. Odoo is configured with Ansible options
(`odoo_config_*` ones).

* **pip**: install the Odoo dependencies from APT repositories and the
Odoo project and modules from a pip requirements.txt file. Odoo is configured
with Ansible options
(`odoo_config_*` ones).

* **buildout**: build the Odoo project from a Git/Hg repository containing a
Buildout configuration file based on the
[anybox.recipe.odoo](https://pypi.python.org/pypi/anybox.recipe.odoo/) recipe.
Expand Down Expand Up @@ -101,6 +106,28 @@ Here we set some options required by the ``connector`` framework:
odoo_config_workers: 8
```

### odoo_install_type: pip

Pip installation (assuming that PostgreSQL is installed and running on
the same host). We need to ensure that the environment variable LC_ALL is used
if Odoo version 11 is to be used:

```yaml
- name: Odoo
hosts: odoo_server
become: yes
roles:
- role: odoo
odoo_install_type: pip
odoo_version: 11.0
odoo_pip_requirements_url: https://raw.githubusercontent.com/OCA/sample-oca-pip-requirements/11.0/requirements.txt
odoo_config_admin_passwd: SuPerPassWorD
environment:
LC_ALL: en_US.UTF-8
```


### odoo_install_type: buildout

With a Buildout installation type, Odoo is installed and configured directly
Expand Down
5 changes: 5 additions & 0 deletions defaults/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,11 @@ odoo_config_custom: {}
#your_option1: value1
#your_option2: value2

# Pip installation options (odoo_install_type == 'pip')
odoo_pip_venv_path: "{{ odoo_workdir }}/sandbox"
odoo_pip_requirements_url: "file:///home/{{ odoo_user }}/requirements.txt"
odoo_pip_odoo_bin_path: "{{ odoo_workdir }}/sandbox/src/odoo/odoo-bin"

# Buildout installation options (odoo_install_type == 'buildout')
odoo_buildout_version: 2.9.5
odoo_buildout_venv_path: "{{ odoo_workdir }}/sandbox"
Expand Down
8 changes: 7 additions & 1 deletion tasks/install.yml
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@
update={{ project_path.stat.exists == False and 'yes'
or (odoo_repo_update and 'yes' or 'no') }}
depth={{ odoo_repo_depth }}
when: odoo_repo_type == 'git' and odoo_repo_url
when: odoo_install_type != 'pip' and odoo_repo_type == 'git' and odoo_repo_url
notify: Restart Odoo
tags:
- odoo_project
Expand All @@ -66,6 +66,12 @@
tags:
- odoo_install_type_buildout

- name: Pip installation
import_tasks: install_pip.yml
when: odoo_install_type == 'pip'
tags:
- odoo_install_type_pip

- name: Install NPM packages
import_tasks: install_npm.yml
when: (odoo_version | int) >= 9
Expand Down
48 changes: 48 additions & 0 deletions tasks/install_pip.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
---

- name: Generate sample requirements.txt file
template: src=odoo-{{ odoo_version }}-pip-requirements.txt dest="/home/{{ odoo_user }}/requirements.txt"
owner={{ odoo_user }} group={{ odoo_user }} mode=0600

- name: Install build dependencies
apt: pkg={{ item }}
state=installed
update_cache={{ odoo_apt_update_cache }}
cache_valid_time={{ odoo_apt_cache_valid_time }}
with_items: "{{ odoo_pip_build_dependencies }}"

- name: Prepare the Python virtual environment
become: yes
become_user: "{{ odoo_user }}"
shell: "{{ odoo_pip_venv_cmd }}"
args:
creates: "{{ odoo_pip_venv_path }}"

- name: Download the pip requirements file
get_url: url="{{ odoo_pip_requirements_url }}"
force=yes
dest="/home/{{ odoo_user }}/requirements.txt"

- name: Install Odoo dependencies (PyPi)
pip:
name: "{{ item }}"
virtualenv: "{{ odoo_pip_venv_path }}"
with_items: "{{ odoo_pip_dependencies }}"

- name: Install Odoo from pip external requirements file
pip:
requirements: /home/{{ odoo_user }}/requirements.txt
extra_args: --upgrade
virtualenv: "{{ odoo_pip_venv_path }}"


- import_tasks: config.yml
tags:
- odoo_config

- name: Generate Odoo init script
template: src=odoo-pip.init dest=/etc/init.d/{{ odoo_service }}
owner=root group=root mode=0755
force={{ odoo_force_config and 'yes' or 'no' }}
backup=yes
notify: Restart Odoo
2 changes: 2 additions & 0 deletions templates/odoo-10.0-pip-requirements.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
https://github.com/odoo/odoo/archive/10.0.tar.gz#egg=odoo
-e git+https://github.com/OCA/[email protected]#egg=odoo10_addon_date_range&subdirectory=setup/date_range
4 changes: 4 additions & 0 deletions templates/odoo-10.0.conf
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
[options]
{% if odoo_install_type == 'pip' %}
addons_path =
{% else %}
addons_path = {{ odoo_config_addons_path.__class__.__name__ == 'list' and odoo_config_addons_path | join(',') or odoo_config_addons_path }}
{% endif %}
admin_passwd = {{ odoo_config_admin_passwd }}
csv_internal_sep = {{ odoo_config_csv_internal_sep }}
data_dir = {{ odoo_config_data_dir }}
Expand Down
2 changes: 2 additions & 0 deletions templates/odoo-11.0-pip-requirements.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
https://github.com/odoo/odoo/archive/11.0.tar.gz#egg=odoo
-e git+https://github.com/OCA/[email protected]#egg=odoo11_addon_date_range&subdirectory=setup/date_range
4 changes: 4 additions & 0 deletions templates/odoo-11.0.conf
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
[options]
{% if odoo_install_type == 'pip' %}
addons_path =
{% else %}
addons_path = {{ odoo_config_addons_path.__class__.__name__ == 'list' and odoo_config_addons_path | join(',') or odoo_config_addons_path }}
{% endif %}
admin_passwd = {{ odoo_config_admin_passwd }}
csv_internal_sep = {{ odoo_config_csv_internal_sep }}
data_dir = {{ odoo_config_data_dir }}
Expand Down
1 change: 1 addition & 0 deletions templates/odoo-8.0-pip-requirements.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
https://github.com/odoo/odoo/archive/8.0.tar.gz#egg=odoo
4 changes: 4 additions & 0 deletions templates/odoo-8.0.conf
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
[options]
{% if odoo_install_type == 'pip' %}
addons_path =
{% else %}
addons_path = {{ odoo_config_addons_path.__class__.__name__ == 'list' and odoo_config_addons_path | join(',') or odoo_config_addons_path }}
{% endif %}
admin_passwd = {{ odoo_config_admin_passwd }}
auto_reload = {{ odoo_config_auto_reload }}
csv_internal_sep = {{ odoo_config_csv_internal_sep }}
Expand Down
1 change: 1 addition & 0 deletions templates/odoo-9.0-pip-requirements.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
https://github.com/odoo/odoo/archive/9.0.tar.gz#egg=odoo
4 changes: 4 additions & 0 deletions templates/odoo-9.0.conf
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
[options]
{% if odoo_install_type == 'pip' %}
addons_path =
{% else %}
addons_path = {{ odoo_config_addons_path.__class__.__name__ == 'list' and odoo_config_addons_path | join(',') or odoo_config_addons_path }}
{% endif %}
admin_passwd = {{ odoo_config_admin_passwd }}
csv_internal_sep = {{ odoo_config_csv_internal_sep }}
data_dir = {{ odoo_config_data_dir }}
Expand Down
87 changes: 87 additions & 0 deletions templates/odoo-pip.init
Original file line number Diff line number Diff line change
@@ -0,0 +1,87 @@
#!/bin/bash
### BEGIN INIT INFO
# Provides: {{ odoo_service }}
# Required-Start: $remote_fs $syslog
# Required-Stop: $remote_fs $syslog
# Should-Start: $network
# Should-Stop: $network
# Default-Start: 2 3 4 5
# Default-Stop: 0 1 6
# Short-Description: Start odoo daemon at boot time
# Description: Enable service provided by daemon.
### END INIT INFO
## more info: http://wiki.debian.org/LSBInitScripts

. /lib/lsb/init-functions

PATH=/usr/local/bin:/usr/local/sbin:/sbin:/bin:/usr/sbin:/usr/bin
WORKDIR={{ odoo_workdir }}
VIRTUALENV={{ odoo_pip_venv_path }}
DAEMON={{ odoo_pip_odoo_bin_path }}
NAME={{ odoo_service }}
DESC={{ odoo_service }}
LOGFILE={{ odoo_logdir }}/{{ odoo_service }}.log
PIDFILE=/var/run/${NAME}.pid
USER={{ odoo_user }}
export LOGNAME=$USER
{% if odoo_init_env %}
# Custom environment variables
{% for name, value in odoo_init_env.iteritems() %}
export {{ name }}={{ value }}
{% endfor %}
{% endif %}

test -x $DAEMON || exit 0
set -e

function _start() {
. $VIRTUALENV/bin/activate
# '--load' is used here as Odoo ignores the 'server_wide_modules' option
# from the configuration file
# Odoo: https://github.com/odoo/odoo/pull/13685
# OCB: https://github.com/OCA/OCB/pull/553
start-stop-daemon --chdir=${WORKDIR} --start --quiet --pidfile $PIDFILE --chuid $USER:$USER --background --make-pidfile --exec $DAEMON -- --logfile $LOGFILE{{ odoo_config_server_wide_modules not in [False, 'None', ''] and ' --load=%s' % odoo_config_server_wide_modules or '' }}
}

function _stop() {
start-stop-daemon --stop --quiet --pidfile $PIDFILE --oknodo --retry 3
rm -f $PIDFILE
}

function _status() {
start-stop-daemon --status --quiet --pidfile $PIDFILE
return $?
}


case "$1" in
start)
echo -n "Starting $DESC: "
_start
echo "ok"
;;
stop)
echo -n "Stopping $DESC: "
_stop
echo "ok"
;;
restart|force-reload)
echo -n "Restarting $DESC: "
_stop
sleep 1
_start
echo "ok"
;;
status)
echo -n "Status of $DESC: "
_status && echo "running" || echo "stopped"
;;
*)
N=/etc/init.d/$NAME
echo "Usage: $N {start|stop|restart|force-reload|status}" >&2
exit 1
;;
esac

exit 0

11 changes: 11 additions & 0 deletions tests/test_pip.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
---

- hosts: localhost
become: yes
roles:
- ansible-odoo
vars:
odoo_install_type: pip
odoo_service: odoo-pip
environment:
LC_ALL: en_US.UTF-8
13 changes: 13 additions & 0 deletions tests/test_pip_changed.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
---

- hosts: localhost
become: yes
roles:
- ansible-odoo
vars:
odoo_install_type: pip
odoo_service: odoo-pip
odoo_init_env:
CHANGED_TEST: 1
environment:
LC_ALL: en_US.UTF-8
23 changes: 23 additions & 0 deletions vars/Debian-8_Odoo-10.yml
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,29 @@ odoo_npm_packages:
- name: phantomjs-prebuilt
version: 2.1.15

odoo_pip_dependencies:
- pip==9.0.1
- wrapt
- odoo-autodiscover==2.0.0
- setuptools-odoo==2.0.2.post1

odoo_pip_build_dependencies:
- python-virtualenv
- build-essential
- python-dev
- libxml2-dev
- libxslt1-dev
- libpq-dev
- libldap2-dev
- libsasl2-dev
- libopenjp2-7-dev
- libjpeg62-turbo-dev
- libtiff5-dev
- libfreetype6-dev
- liblcms2-dev
- libwebp-dev
- libssl-dev

odoo_buildout_build_dependencies:
- python-virtualenv
- build-essential
Expand Down
Loading

0 comments on commit c1f8496

Please sign in to comment.