Skip to content

Commit 0696b74

Browse files
authored
Merge pull request #18 from guewen/custom-scripts
Add custom scripts in /opt/odoo/start-entrypoint.d
2 parents f220a20 + 641cd17 commit 0696b74

File tree

7 files changed

+68
-3
lines changed

7 files changed

+68
-3
lines changed

10.0/Dockerfile

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,7 @@ RUN curl https://github.com/jwilder/dockerize/releases/download/v0.2.0/dockerize
6666
COPY ./src_requirements.txt ./
6767
COPY ./bin bin
6868
COPY ./etc etc
69+
COPY ./start-entrypoint.d start-entrypoint.d
6970
COPY ./MANIFEST.in ./
7071

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

9.0/Dockerfile

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,7 @@ COPY ./src_requirements.txt ./
6767
COPY ./bin bin
6868
COPY ./bin_compat bin_compat
6969
COPY ./etc etc
70+
COPY ./start-entrypoint.d start-entrypoint.d
7071
COPY ./MANIFEST.in ./
7172

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

HISTORY.rst

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ the outside of the container and from the inside. Meaning, if we run the followi
3232

3333
docker-compose run --rm -e DB_NAME=dbtest odoo pytest -s odoo/local-src/my_addon/tests/test_feature.py::TestFeature::test_it_passes
3434

35-
The path ``odoo/local-src...`` is the path you see in your project (with auto-completion),
35+
The path ``odoo/local-src...`` is the path you see in your local project (with auto-completion),
3636
but it is valid from inside the container too.
3737

3838
The implication is that the projects' Dockerfile need to be adapted, for instance:
@@ -58,8 +58,13 @@ becomes:
5858
* Include pytest
5959
* Add testdb-gen, command that generates a test database to be used with pytest
6060
* Add testdb-update, command to update the addons of a database created with testdb-gen
61-
* run 'chown' on the volumes only if the user is different, should make the boot faster
62-
* run 'chown' for any command, not only when starting odoo, needed to run testdb-gen
61+
* 'chown' is executed on the volumes only if the user is different, should make the boot faster
62+
* 'chown' is executed for any command, not only when starting odoo, needed to run testdb-gen
63+
* Customizable ``web.base.url`` with environment variables ``ODOO_BASE_URL`` or
64+
``DOMAIN_NAME``
65+
* Allow to run custom scripts between ``migrate`` and the execution of
66+
``odoo``, by placing them in ``/opt/odoo/start-entrypoint.d`` (respecting
67+
``run-parts`` naming rules)
6368

6469
**Bugfixes**
6570

Makefile

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ build:
1515
$(eval TMP := $(shell mktemp -u))
1616
cp -r $(VERSION) $(TMP)
1717
cp -r bin/ $(TMP)
18+
cp -r start-entrypoint.d/ $(TMP)
1819
docker build --no-cache -t $(IMAGE_LATEST) $(TMP)
1920
rm -rf $(TMP)
2021

README.md

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,12 @@ Ports 8069 and 8072 are exposed by default.
3131

3232
## Environment variables
3333

34+
### ODOO_BASE_URL
35+
36+
If this variable is set, the `ir.config_parameter` `web.base.url`
37+
will be automatically set to this domain when the container
38+
starts. `web.base.url.freeze` will be set to `True`.
39+
3440
### MIGRATE
3541

3642
`MIGRATE` can be `True` or `False` and determines whether migration tool
@@ -137,3 +143,16 @@ docker-compose run --rm odoo dropdb testdb
137143

138144
Pytest uses a plugin (https://github.com/camptocamp/pytest-odoo) that corrects the
139145
Odoo namespaces (`openerp.addons`/`odoo.addons`) when running the tests.
146+
147+
## Start entrypoint
148+
149+
Any script in any language placed in `/opt/odoo/start-entrypoint.d` will be
150+
executed just between the migration and the start of Odoo. The order of
151+
execution of the files is determined by the `run-parts` 's rules.
152+
153+
The database is guaranteed to exist at this point so you can run queries on it.
154+
The scripts are run only if the command is `odoo`/`odoo.py`.
155+
156+
You can add your own scripts in this directory. They must be named something
157+
like `010_abc` (`^[a-zA-Z0-9_-]+$`) and must have no extension (or it would not
158+
be picked up by `run-parts`).

bin/docker-entrypoint.sh

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -106,6 +106,12 @@ if [ "$BASE_CMD" = "odoo" ] || [ "$BASE_CMD" = "odoo.py" ] ; then
106106
if [ -z "$MIGRATE" -o "$MIGRATE" = True ]; then
107107
gosu odoo migrate
108108
fi
109+
110+
START_ENTRYPOINT_DIR=/opt/odoo/start-entrypoint.d
111+
if [ -d "$START_ENTRYPOINT_DIR" ]; then
112+
/bin/run-parts --verbose "$START_ENTRYPOINT_DIR"
113+
fi
114+
109115
exec gosu odoo "$@"
110116
fi
111117

start-entrypoint.d/000_set_base_url

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
#!/bin/bash
2+
3+
DOMAIN=${ODOO_BASE_URL:-${DOMAIN_NAME}}
4+
5+
if [ -n "$DOMAIN" ]; then
6+
echo "Setting Base URL to domain ${DOMAIN}"
7+
psql --quiet -h db << EOF
8+
9+
WITH update_param AS (
10+
UPDATE ir_config_parameter
11+
SET value = '${DOMAIN}'
12+
WHERE key = 'web.base.url'
13+
RETURNING *
14+
)
15+
INSERT INTO ir_config_parameter
16+
(value, key, create_uid, write_uid, create_date, write_date)
17+
SELECT '${DOMAIN}', 'web.base.url', 1, 1, now(), now()
18+
WHERE NOT EXISTS (SELECT * FROM update_param);
19+
20+
WITH update_param AS (
21+
UPDATE ir_config_parameter
22+
SET value = 'True'
23+
WHERE key = 'web.base.url.freeze'
24+
RETURNING *
25+
)
26+
INSERT INTO ir_config_parameter
27+
(value, key, create_uid, write_uid, create_date, write_date)
28+
SELECT 'True', 'web.base.url.freeze', 1, 1, now(), now()
29+
WHERE NOT EXISTS (SELECT * FROM update_param);
30+
31+
EOF
32+
fi

0 commit comments

Comments
 (0)