Skip to content

Commit

Permalink
Reorganize directory structure
Browse files Browse the repository at this point in the history
* /opt/odoo/etc/odoo.cfg.tmpl → /templates/odoo.cfg.tmpl
* /opt/odoo/etc/odoo.cfg → /etc/odoo.cfg
* /opt/odoo → /odoo
* /opt/odoo/bin → /odoo-bin
* /opt/odoo/bin_compat → /odoo-bin-compat (for 9.0)
* /opt/odoo/before-migrate-entrypoint.d → /before-migrate-entrypoint.d
* /opt/odoo/start-entrypoint.d → /start-entrypoint.d

This way we have the same path ./odoo outside and inside of the
container.

bin, etc and entrypoints are not in /odoo, so we can share the whole
"odoo" directory with a host volume without shadowing them.

Closes #67
  • Loading branch information
guewen committed Jul 31, 2018
1 parent 55fa05f commit 9ddc668
Show file tree
Hide file tree
Showing 21 changed files with 125 additions and 129 deletions.
29 changes: 12 additions & 17 deletions 10.0/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,9 @@ FROM debian:jessie
MAINTAINER Camptocamp

# create the working directory and a place to set the logs (if wanted)
RUN mkdir -p /opt/odoo /var/log/odoo
RUN mkdir -p /odoo /var/log/odoo

WORKDIR "/opt/odoo"

COPY ./base_requirements.txt ./
COPY ./base_requirements.txt /odoo
COPY ./install /install

# build and dev packages
Expand Down Expand Up @@ -36,27 +34,27 @@ RUN set -x; \
&& /install/wkhtml_12_1_2.sh \
&& /install/dev_package.sh \
&& pip install -U pip setuptools \
&& pip install -r base_requirements.txt \
&& pip install -r /odoo/base_requirements.txt \
&& /install/purge_dev_package_and_cache.sh

# grab gosu for easy step-down from root and dockerize to generate template and
# wait on postgres
RUN /install/gosu.sh && /install/dockerize.sh

COPY ./src_requirements.txt ./
COPY ./bin /opt/bin
COPY ./etc /opt/etc
COPY ./before-migrate-entrypoint.d /opt/before-migrate-entrypoint.d
COPY ./start-entrypoint.d /opt/start-entrypoint.d
COPY ./MANIFEST.in ./
COPY ./src_requirements.txt /odoo
COPY ./bin /odoo-bin
COPY ./templates /templates
COPY ./before-migrate-entrypoint.d /before-migrate-entrypoint.d
COPY ./start-entrypoint.d /start-entrypoint.d
COPY ./MANIFEST.in /odoo

VOLUME ["/data/odoo", "/var/log/odoo"]

# Expose Odoo services
EXPOSE 8069 8072

ENV ODOO_VERSION=10.0 \
PATH=/opt/bin:$PATH \
PATH=/odoo-bin:$PATH \
LANG=C.UTF-8 \
LC_ALL=C.UTF-8 \
DB_HOST=db \
Expand All @@ -67,11 +65,8 @@ ENV ODOO_VERSION=10.0 \
ODOO_BASE_URL=http://localhost:8069 \
ODOO_REPORT_URL=http://localhost:8069 \
DEMO=False \
ADDONS_PATH=/opt/odoo/local-src,/opt/odoo/src/addons \
OPENERP_SERVER=/opt/etc/odoo.cfg
ADDONS_PATH=/odoo/local-src,/odoo/src/addons \
OPENERP_SERVER=/etc/odoo.cfg

# set to /opt so we can have the same path outside and inside of the container:
# docker run --rm odoo pytest odoo/external-src/abc/xyz/tests/test.py
WORKDIR "/opt"
ENTRYPOINT ["docker-entrypoint.sh"]
CMD ["odoo"]
File renamed without changes.
34 changes: 15 additions & 19 deletions 11.0/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,10 @@ FROM debian:stretch
MAINTAINER Camptocamp

# create the working directory and a place to set the logs (if wanted)
RUN mkdir -p /opt/odoo /var/log/odoo
RUN mkdir -p /odoo /var/log/odoo

WORKDIR "/opt/odoo"

COPY ./base_requirements.txt ./
COPY ./extra_requirements.txt ./
COPY ./base_requirements.txt /odoo
COPY ./extra_requirements.txt /odoo
COPY ./install /install

# Moved because there was a bug while installing `odoo-autodiscover`. There is
Expand Down Expand Up @@ -41,27 +39,27 @@ RUN set -x; \
&& /install/wkhtml_12_4.sh \
&& /install/dev_package.sh \
&& python3 -m pip install --force-reinstall pip setuptools \
&& pip3 install -r base_requirements.txt --ignore-installed \
&& pip3 install -r /odoo/base_requirements.txt --ignore-installed \
&& /install/purge_dev_package_and_cache.sh

# grab gosu for easy step-down from root and dockerize to generate template and
# wait on postgres
RUN /install/gosu.sh && /install/dockerize.sh

COPY ./src_requirements.txt ./
COPY ./bin /opt/bin
COPY ./etc /opt/etc
COPY ./before-migrate-entrypoint.d /opt/before-migrate-entrypoint.d
COPY ./start-entrypoint.d /opt/start-entrypoint.d
COPY ./MANIFEST.in ./
COPY ./src_requirements.txt /odoo
COPY ./bin /odoo-bin
COPY ./templates /templates
COPY ./before-migrate-entrypoint.d /before-migrate-entrypoint.d
COPY ./start-entrypoint.d /start-entrypoint.d
COPY ./MANIFEST.in /odoo

VOLUME ["/data/odoo", "/var/log/odoo"]

# Expose Odoo services
EXPOSE 8069 8072

ENV ODOO_VERSION=11.0 \
PATH=/opt/bin:$PATH \
PATH=/odoo-bin:$PATH \
LANG=C.UTF-8 \
LC_ALL=C.UTF-8 \
DB_HOST=db \
Expand All @@ -71,13 +69,11 @@ ENV ODOO_VERSION=11.0 \
DB_PASSWORD=odoo \
ODOO_BASE_URL=http://localhost:8069 \
ODOO_REPORT_URL=http://localhost:8069 \
ODOO_DATA_PATH=/opt/odoo/data \
# the place where you put the data of your project (csv, ...)
ODOO_DATA_PATH=/odoo/data \
DEMO=False \
ADDONS_PATH=/opt/odoo/local-src,/opt/odoo/src/addons \
OPENERP_SERVER=/opt/etc/odoo.cfg
ADDONS_PATH=/odoo/local-src,/odoo/src/addons \
OPENERP_SERVER=/etc/odoo.cfg

# set to /opt so we can have the same path outside and inside of the container:
# docker run --rm odoo pytest odoo/external-src/abc/xyz/tests/test.py
WORKDIR "/opt"
ENTRYPOINT ["docker-entrypoint.sh"]
CMD ["odoo"]
File renamed without changes.
33 changes: 14 additions & 19 deletions 9.0/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,10 @@ FROM debian:jessie
MAINTAINER Camptocamp

# create the working directory and a place to set the logs (if wanted)
RUN mkdir -p /opt/odoo /var/log/odoo
RUN mkdir -p /odoo /var/log/odoo

WORKDIR "/opt/odoo"

COPY ./base_requirements.txt ./
COPY ./extra_requirements.txt ./
COPY ./base_requirements.txt /odoo
COPY ./extra_requirements.txt /odoo
COPY ./install /install

# build and dev packages
Expand Down Expand Up @@ -37,28 +35,28 @@ RUN set -x; \
&& /install/wkhtml_12_1_2.sh \
&& /install/dev_package.sh \
&& pip install -U pip setuptools \
&& pip install -r base_requirements.txt \
&& pip install -r /odoo/base_requirements.txt \
&& /install/purge_dev_package_and_cache.sh

# grab gosu for easy step-down from root and dockerize to generate template and
# wait on postgres
RUN /install/gosu.sh && /install/dockerize.sh

COPY ./src_requirements.txt ./
COPY ./bin /opt/bin
COPY ./bin_compat /opt/bin_compat
COPY ./etc /opt/etc
COPY ./before-migrate-entrypoint.d /opt/before-migrate-entrypoint.d
COPY ./start-entrypoint.d /opt/start-entrypoint.d
COPY ./MANIFEST.in ./
COPY ./src_requirements.txt /odoo
COPY ./bin /odoo-bin
COPY ./bin-compat /odoo-bin-compat
COPY ./templates /templates
COPY ./before-migrate-entrypoint.d /before-migrate-entrypoint.d
COPY ./start-entrypoint.d /start-entrypoint.d
COPY ./MANIFEST.in /odoo

VOLUME ["/data/odoo", "/var/log/odoo"]

# Expose Odoo services
EXPOSE 8069 8072

ENV ODOO_VERSION=9.0 \
PATH=/opt/bin:/opt/bin_compat:$PATH \
PATH=/odoo-bin:/odoo-bin-compat:$PATH \
LANG=C.UTF-8 \
LC_ALL=C.UTF-8 \
DB_HOST=db \
Expand All @@ -69,11 +67,8 @@ ENV ODOO_VERSION=9.0 \
ODOO_BASE_URL=http://localhost:8069 \
ODOO_REPORT_URL=http://localhost:8069 \
DEMO=False \
ADDONS_PATH=/opt/odoo/local-src,/opt/odoo/src/addons \
OPENERP_SERVER=/opt/etc/odoo.cfg
ADDONS_PATH=/odoo/local-src,/odoo/src/addons \
OPENERP_SERVER=/etc/odoo.cfg

# set to /opt so we can have the same path outside and inside of the container:
# docker run --rm odoo pytest odoo/external-src/abc/xyz/tests/test.py
WORKDIR "/opt"
ENTRYPOINT ["docker-entrypoint.sh"]
CMD ["odoo"]
File renamed without changes.
File renamed without changes.
20 changes: 18 additions & 2 deletions HISTORY.rst
Original file line number Diff line number Diff line change
Expand Up @@ -22,15 +22,31 @@ Release History
Unreleased
++++++++++

.. DANGER:: Breaking changes

Flavors: you have either to use the ``onbuild`` flavor, either to add the
``COPY`` instructions in your projects Dockerfiles.

Directories have been re-arranged, you must adapt addons-path, volumes or COPY instructions:

* /opt/odoo/etc/odoo.cfg.tmpl → /templates/odoo.cfg.tmpl
* /opt/odoo/etc/odoo.cfg → /etc/odoo.cfg
* /opt/odoo → /odoo
* /opt/odoo/bin → /odoo-bin
* /opt/odoo/bin_compat → /odoo-bin-compat (for 9.0)
* /opt/odoo/before-migrate-entrypoint.d → /before-migrate-entrypoint.d
* /opt/odoo/start-entrypoint.d → /start-entrypoint.d


**Features and Improvements**

* Refactor code to be able to share code between versions (see common and bin directories)
* Introduce Flavors of the image:

* normal image without "onbuild"
* normal image with "onbuild" instructions
* batteries-included image without "unbuild"
* batteries-included with "unbuild" instructions
* batteries-included image without "onbuild"
* batteries-included with "onbuild" instructions

* Batteries-included flavor includes a selected list of python packages commonly used in OCA addons (see extra_requirements.txt)
* Do not use the "latest" image, pick your flavor after you read the readme
Expand Down
8 changes: 4 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -190,12 +190,12 @@ then share the same user.

The main configuration options of Odoo can be configured through environment variables. The name of the environment variables are the same of the options but uppercased (eg. `workers` becomes `WORKERS`).

Look in [9.0/etc/openerp.cfg.tmpl](9.0/etc/openerp.cfg.tmpl) to see the full list.
Look in [11.0/templates/odoo.cfg.tmpl](11.0/templates/odoo.cfg.tmpl) to see the full list.

While most of the variables can be set in the docker-compose file so we can have different values for different environments, the `ADDONS_PATH` **must** be set in the `Dockerfile` of your project with a line such as:

```
ENV ADDONS_PATH=/opt/odoo/local-src,/opt/odoo/external-src/server-tools,/opt/odoo/src/addons
ENV ADDONS_PATH=/odoo/local-src,/odoo/external-src/server-tools,/odoo/src/addons
```

By setting this value in the `Dockerfile`, it will be integrated into the build and thus will be consistent across each environment.
Expand Down Expand Up @@ -240,9 +240,9 @@ Odoo namespaces (`openerp.addons`/`odoo.addons`) when running the tests.

## Start entrypoint

Any script in any language placed in `/opt/odoo/start-entrypoint.d` will be
Any script in any language placed in `/start-entrypoint.d` will be
executed just between the migration and the start of Odoo.
Similarly, scripts placed in `/opt/odoo/before-migrate-entrypoint.d` will be
Similarly, scripts placed in `/before-migrate-entrypoint.d` will be
executed just before the migration.

The order of execution of the files is determined by the `run-parts` 's rules.
Expand Down
6 changes: 4 additions & 2 deletions bin/check_package
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
#!/bin/bash

cat /opt/odoo/base_requirements.txt > requirements.txt
set -e

cat /odoo/base_requirements.txt > requirements.txt

if [ "$BATTERIES" = "True" ]
then cat /opt/odoo/extra_requirements.txt >> requirements.txt
then cat /odoo/extra_requirements.txt >> requirements.txt
fi

sed -i '/^\s*$/d' requirements.txt
Expand Down
46 changes: 22 additions & 24 deletions bin/docker-entrypoint.sh
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,6 @@ USER_ID=${LOCAL_USER_ID:-999}
echo "Starting with UID : $USER_ID"
id -u odoo &> /dev/null || useradd --shell /bin/bash -u $USER_ID -o -c "" -m odoo

BINDIR=$(dirname $0)
BASEDIR=$(readlink -f $BINDIR/..)

export PGHOST=${DB_HOST}
export PGPORT=${DB_PORT}
export PGUSER=${DB_USER}
Expand Down Expand Up @@ -60,47 +57,48 @@ case "$(echo "${DEMO}" | tr '[:upper:]' '[:lower:]' )" in
esac

# Create configuration file from the template
CONFIGDIR=/opt/etc
if [ -e $CONFIGDIR/openerp.cfg.tmpl ]; then
dockerize -template $CONFIGDIR/openerp.cfg.tmpl:$CONFIGDIR/odoo.cfg
TEMPLATES_DIR=/templates
CONFIG_TARGET=/etc/odoo.cfg
if [ -e $TEMPLATES_DIR/openerp.cfg.tmpl ]; then
dockerize -template $TEMPLATES_DIR/openerp.cfg.tmpl:$CONFIG_TARGET
fi
if [ -e $CONFIGDIR/odoo.cfg.tmpl ]; then
dockerize -template $CONFIGDIR/odoo.cfg.tmpl:$CONFIGDIR/odoo.cfg
if [ -e $TEMPLATES_DIR/odoo.cfg.tmpl ]; then
dockerize -template $TEMPLATES_DIR/odoo.cfg.tmpl:$CONFIG_TARGET
fi

if [ ! -f "$CONFIGDIR/odoo.cfg" ]; then
echo "Error: one of etc/openerp.cfg.tmpl, etc/odoo.cfg.tmpl, etc/odoo.cfg is required"
if [ ! -f "/etc/odoo.cfg" ]; then
echo "Error: one of /templates/openerp.cfg.tmpl, /templates/odoo.cfg.tmpl, /etc/odoo.cfg is required"
exit 1
fi

if [ -z "$(pip list --format=columns | grep "/opt/odoo/src")" ]; then
if [ -z "$(pip list --format=columns | grep "/odoo/src")" ]; then
# The build runs 'pip install -e' on the odoo src, which creates an
# odoo.egg-info directory *inside /opt/odoo/src*. So when we run a container
# odoo.egg-info directory *inside /odoo/src*. So when we run a container
# with a volume shared with the host, we don't have this .egg-info (at least
# the first time).
# When it happens, we reinstall the odoo python package. We don't want to run
# the install everytime because it would slow the start of the containers
echo '/opt/odoo/src/odoo.egg-info is missing, probably because the directory is a volume.'
echo 'Running pip install -e /opt/odoo/src to restore odoo.egg-info'
pip install -e /opt/odoo/src
echo '/odoo/src/odoo.egg-info is missing, probably because the directory is a volume.'
echo 'Running pip install -e /odoo/src to restore odoo.egg-info'
pip install -e /odoo/src
# As we write in a volume, ensure it has the same user.
# So when the src is a host volume and we set the LOCAL_USER_ID to be the
# host user, the files are owned by the host user
chown -R odoo: /opt/odoo/src/odoo.egg-info
chown -R odoo: /odoo/src/odoo.egg-info
fi


# Same logic but for your custom project
if [ -z "$(pip list --format=columns | grep "/opt/odoo" | grep -v "/opt/odoo/src")" ]; then
echo '/opt/src/*.egg-info is missing, probably because the directory is a volume.'
echo 'Running pip install -e /opt/odoo to restore *.egg-info'
pip install -e /opt/odoo
chown -R odoo: /opt/odoo/*.egg-info
if [ -z "$(pip list --format=columns | grep "/odoo" | grep -v "/odoo/src")" ]; then
echo '/src/*.egg-info is missing, probably because the directory is a volume.'
echo 'Running pip install -e /odoo to restore *.egg-info'
pip install -e /odoo
chown -R odoo: /odoo/*.egg-info
fi


# Wait until postgres is up
$BINDIR/wait_postgres.sh
wait_postgres.sh

mkdir -p /data/odoo/{addons,filestore,sessions}
if [ ! "$(stat -c '%U' /data/odoo)" = "odoo" ]; then
Expand All @@ -113,7 +111,7 @@ fi
BASE_CMD=$(basename $1)
if [ "$BASE_CMD" = "odoo" ] || [ "$BASE_CMD" = "odoo.py" ] ; then

BEFORE_MIGRATE_ENTRYPOINT_DIR=/opt/odoo/before-migrate-entrypoint.d
BEFORE_MIGRATE_ENTRYPOINT_DIR=/odoo/before-migrate-entrypoint.d
if [ -d "$BEFORE_MIGRATE_ENTRYPOINT_DIR" ]; then
run-parts --verbose "$BEFORE_MIGRATE_ENTRYPOINT_DIR"
fi
Expand All @@ -122,7 +120,7 @@ if [ "$BASE_CMD" = "odoo" ] || [ "$BASE_CMD" = "odoo.py" ] ; then
gosu odoo migrate
fi

START_ENTRYPOINT_DIR=/opt/odoo/start-entrypoint.d
START_ENTRYPOINT_DIR=/odoo/start-entrypoint.d
if [ -d "$START_ENTRYPOINT_DIR" ]; then
run-parts --verbose "$START_ENTRYPOINT_DIR"
fi
Expand Down
5 changes: 1 addition & 4 deletions bin/lint
Original file line number Diff line number Diff line change
@@ -1,7 +1,4 @@
#!/bin/bash
set -e

BINDIR=$(dirname $0)
BASEDIR=$(readlink -f $BINDIR/..)

flake8 $BASEDIR/local-src --exclude=__init__.py
flake8 /odoo/local-src --exclude=__init__.py
2 changes: 1 addition & 1 deletion bin/migrate
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ if ! PGPASSWORD=$DB_PASSWORD psql -lqtA -h $DB_HOST -U $DB_USER | grep -q "^$DB_
PGPASSWORD=$DB_PASSWORD createdb -h $DB_HOST -U $DB_USER -O $DB_USER $DB_NAME
fi

CONFIGFILE=/opt/odoo/migration.yml
CONFIGFILE=/odoo/migration.yml
MARABUNTA_DB_HOST=$DB_HOST \
MARABUNTA_DATABASE=$DB_NAME \
MARABUNTA_DB_USER=$DB_USER \
Expand Down
Loading

0 comments on commit 9ddc668

Please sign in to comment.