Skip to content

Commit

Permalink
Merge pull request #267 from gurneyalex/fix-scripts
Browse files Browse the repository at this point in the history
fix bin/ utilities
  • Loading branch information
gurneyalex authored Jan 18, 2024
2 parents 7d50c3c + 4a4084a commit 42edd0f
Show file tree
Hide file tree
Showing 35 changed files with 93 additions and 49 deletions.
2 changes: 1 addition & 1 deletion 11.0/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ ENV ODOO_VERSION=11.0 \
# the place where you put the data of your project (csv, ...)
ODOO_DATA_PATH=/odoo/data \
DEMO=False \
ADDONS_PATH=/odoo/local-src,/odoo/src/addons \
ADDONS_PATH=/odoo/odoo/addons,/odoo/odoo/src/odoo/addons \
OPENERP_SERVER=/odoo/odoo.cfg

ENTRYPOINT ["docker-entrypoint.sh"]
Expand Down
2 changes: 1 addition & 1 deletion 12.0/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ ENV ODOO_VERSION=12.0 \
# the place where you put the data of your project (csv, ...)
ODOO_DATA_PATH=/odoo/data \
DEMO=False \
ADDONS_PATH=/odoo/local-src,/odoo/src/addons \
ADDONS_PATH=/odoo/odoo/addons,/odoo/odoo/src/odoo/addons \
OPENERP_SERVER=/odoo/odoo.cfg

ENTRYPOINT ["docker-entrypoint.sh"]
Expand Down
2 changes: 1 addition & 1 deletion 13.0/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ ENV ODOO_VERSION=13.0 \
# the place where you put the data of your project (csv, ...)
ODOO_DATA_PATH=/odoo/data \
DEMO=False \
ADDONS_PATH=/odoo/local-src,/odoo/src/addons \
ADDONS_PATH=/odoo/odoo/addons,/odoo/odoo/src/odoo/addons \
OPENERP_SERVER=/odoo/odoo.cfg

ENTRYPOINT ["docker-entrypoint.sh"]
Expand Down
2 changes: 1 addition & 1 deletion 14.0-bullseye/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ ENV ODOO_VERSION=14.0 \
# the place where you put the data of your project (csv, ...)
ODOO_DATA_PATH=/odoo/data \
DEMO=False \
ADDONS_PATH=/odoo/local-src,/odoo/src/addons \
ADDONS_PATH=/odoo/odoo/addons,/odoo/odoo/src/odoo/addons \
OPENERP_SERVER=/odoo/odoo.cfg

ENTRYPOINT ["docker-entrypoint.sh"]
Expand Down
2 changes: 1 addition & 1 deletion 15.0/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ ENV ODOO_VERSION=15.0 \
# the place where you put the data of your project (csv, ...)
ODOO_DATA_PATH=/odoo/data \
DEMO=False \
ADDONS_PATH=/odoo/local-src,/odoo/src/addons \
ADDONS_PATH=/odoo/odoo/addons,/odoo/odoo/src/odoo/addons \
OPENERP_SERVER=/odoo/odoo.cfg

ENTRYPOINT ["docker-entrypoint.sh"]
Expand Down
2 changes: 1 addition & 1 deletion 16.0/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ ENV ODOO_VERSION=16.0 \
# the place where you put the data of your project (csv, ...)
ODOO_DATA_PATH=/odoo/data \
DEMO=False \
ADDONS_PATH=/odoo/local-src,/odoo/src/addons \
ADDONS_PATH=/odoo/odoo/addons,/odoo/odoo/src/odoo/addons \
OPENERP_SERVER=/odoo/odoo.cfg

ENTRYPOINT ["docker-entrypoint.sh"]
Expand Down
2 changes: 1 addition & 1 deletion 17.0/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ ENV ODOO_VERSION=17.0 \
# the place where you put the data of your project (csv, ...)
ODOO_DATA_PATH=/odoo/data \
DEMO=False \
ADDONS_PATH=/odoo/local-src,/odoo/src/addons \
ADDONS_PATH=/odoo/odoo/addons,/odoo/odoo/src/odoo/addons \
OPENERP_SERVER=/odoo/odoo.cfg

ENTRYPOINT ["docker-entrypoint.sh"]
Expand Down
2 changes: 1 addition & 1 deletion bin/docker-entrypoint.sh
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ export PGAPPNAME=${HOSTNAME}

# As docker-compose exec do not launch the entrypoint
# init PG variable into .bashrc so it will be initialized
# when doing docker-compose exec odoo gosu odoo bash
# when doing docker-compose exec odoo odoo bash
echo "
export PGHOST=${DB_HOST}
export PGPORT=${DB_PORT}
Expand Down
2 changes: 1 addition & 1 deletion bin/lint
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#!/bin/bash
set -e

flake8 /odoo/local-src --exclude=__init__.py
flake8 $LOCAL_CODE_PATH --exclude=__init__.py
8 changes: 4 additions & 4 deletions bin/list_dependencies.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
# Provide a list of module which are dependencies
# of local-src modules excluding local-src modules
# of odoo/addons modules excluding odoo/addons modules
#
# Arguments:
# list of module (coma separated), restrict list of
Expand All @@ -13,17 +13,17 @@
import os
import ast

LOCAL_SRC_DIR = os.path.join("/odoo", "local-src")
LOCAL_CODE_PATH = os.getenv('LOCAL_CODE_PATH',"/odoo/odoo/addons")

dependencies = set()
local_modules = os.listdir(LOCAL_SRC_DIR)
local_modules = os.listdir(LOCAL_CODE_PATH)
if len(sys.argv) > 1:
modules = sys.argv[1].split(",")
else:
modules = local_modules
for mod in modules:
# read __manifest__
manifest_path = os.path.join(LOCAL_SRC_DIR, mod, "__manifest__.py")
manifest_path = os.path.join(LOCAL_CODE_PATH, mod, "__manifest__.py")
if not os.path.isfile(manifest_path):
continue
with open(manifest_path) as manifest:
Expand Down
4 changes: 1 addition & 3 deletions bin/migrate
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,9 @@ set -e
if ! PGPASSWORD=$DB_PASSWORD psql -lqtA -h $DB_HOST -U $DB_USER | grep -q "^$DB_NAME|"; then
PGPASSWORD=$DB_PASSWORD createdb -h $DB_HOST -U $DB_USER -O $DB_USER $DB_NAME
fi

CONFIGFILE=/odoo/migration.yml
MARABUNTA_DB_HOST=$DB_HOST \
MARABUNTA_DATABASE=$DB_NAME \
MARABUNTA_DB_USER=$DB_USER \
MARABUNTA_DB_PASSWORD=$DB_PASSWORD \
MARABUNTA_DB_PORT=$DB_PORT \
unbuffer marabunta --migration-file $CONFIGFILE
unbuffer marabunta --migration-file $MIGRATION_CONFIG_FILE
7 changes: 3 additions & 4 deletions bin/runtests
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#!/bin/bash
#
# Run unit tests of local-src modules
# Run unit tests of odoo/addons modules
#
# mainly used from Travis,
# it creates a database,
Expand Down Expand Up @@ -30,11 +30,10 @@ set -e

wait_postgres.sh

LOCAL_SRC_DIR=/odoo/local-src
CACHE_DIR=${CACHE_DIR:=/tmp/cachedb}

if [ -z $1 ]; then
LOCAL_ADDONS=$(find ${LOCAL_SRC_DIR}/* -maxdepth 0 -type d -and -not -name server_environment_files -printf "%f\n" |
LOCAL_ADDONS=$(find ${LOCAL_CODE_PATH}/* -maxdepth 0 -type d -and -not -name server_environment_files -printf "%f\n" |
awk -vORS=, '{print $1}' |
sed 's/,$/\n/')
else
Expand Down Expand Up @@ -73,7 +72,7 @@ else
pg_dump -Fp -d $DB_NAME_TEST -O -f "$CACHED_DUMP"
fi
fi
echo "🔧🔧 Install local-src modules 🔧🔧"
echo "🔧🔧 Install odoo/addons modules 🔧🔧"
odoo --stop-after-init --workers=0 --database $DB_NAME_TEST --test-enable --log-level=test --log-handler=":INFO" --without-demo="" --db-filter=$DB_NAME_TEST -i ${LOCAL_ADDONS}

dropdb ${DB_NAME_TEST}
2 changes: 1 addition & 1 deletion bin/testdb-gen
Original file line number Diff line number Diff line change
Expand Up @@ -16,5 +16,5 @@ fi

echo "creating database ${DB_NAME}"
createdb -h ${DB_HOST} -O ${DB_USER} ${DB_NAME}
gosu odoo odoo --stop-after-init --workers=0 --log-level=warn --without-demo="" "$@"
odoo --stop-after-init --workers=0 --log-level=warn --without-demo="" "$@"
echo "done"
2 changes: 1 addition & 1 deletion bin/testdb-update
Original file line number Diff line number Diff line change
Expand Up @@ -15,5 +15,5 @@ if ! psql -lqtA -h ${DB_HOST} | grep -q "^$DB_NAME|"; then
fi

echo "updating database ${DB_NAME}"
gosu odoo odoo --stop-after-init --workers=0 --log-level=warn --without-demo="" "$@"
odoo --stop-after-init --workers=0 --log-level=warn --without-demo="" "$@"
echo "done"
13 changes: 6 additions & 7 deletions example/odoo/Dockerfile → example/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,8 @@ MAINTAINER Camptocamp
# 2. or adding each directory, this solution will reduce the build and download
# time of the image on the server (layers are reused)
RUN mkdir -p /odoo/src/odoo
COPY ./src /odoo/src/odoo
COPY ./external-src /odoo/external-src
COPY ./local-src /odoo/local-src
COPY ./odoo/src/odoo /odoo/src/odoo
COPY ./odoo/addons /odoo/odoo/addons
COPY ./data /odoo/data
COPY ./songs /odoo/songs
COPY ./setup.py /odoo/
Expand All @@ -26,11 +25,11 @@ RUN set -x; \

COPY ./requirements.txt /odoo/
USER odoo
RUN pip install -e /odoo
RUN pip install -e /odoo/src/odoo
WORKDIR /odoo
RUN pip install --user -e .
RUN pip install --user -r requirements.txt

# Project's specifics packages
RUN cd /odoo && pip install -r requirements.txt

ENV ADDONS_PATH=/odoo/local-src,/odoo/src/odoo/addons
ENV ADDONS_PATH=/odoo/odoo/addons,/odoo/src/odoo/addons

Original file line number Diff line number Diff line change
Expand Up @@ -12,4 +12,4 @@ RUN set -x; \
COPY ./requirements.txt /odoo/
RUN cd /odoo && pip install -r requirements.txt

ENV ADDONS_PATH=/odoo/local-src,/odoo/src/addons
ENV ADDONS_PATH=/odoo/odoo/addons,/odoo/src/addons
8 changes: 4 additions & 4 deletions example/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,26 +8,26 @@ Follow the steps:

1. Create directories. This is mandatory, they will be copied in the image

mkdir -p odoo/external-src odoo/local-src odoo/data odoo/songs
mkdir -p odoo/addons data songs

2. Add a submodule for Odoo (official or OCA/OCB)

git submodule init
git submodule add [email protected]:odoo/odoo.git odoo/src

3. Optionally add submodules for external addons in `odoo/external-src`

git submodule add [email protected]:OCA/server-tools.git odoo/external-src/server-tools

4. Optionally add custom addons in `odoo/local-src`
4. Optionally add custom addons in `odoo/addons`

6. Create the Dockerfile, the bare minimum being (see also [the example
file](odoo/Dockerfile) that installs additional dependencies):

FROM camptocamp/odoo-project:11.0
MAINTAINER <name>

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

7. Build your image

Expand Down
File renamed without changes
1 change: 1 addition & 0 deletions example/docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ services:
- ADMIN_PASSWD=# set me
- RUNNING_ENV=dev
- LOG_HANDLER=:WARN
- LOCAL_CODE_PATH=/odoo/odoo/addons
- MARABUNTA_MODE=demo # could be 'full' for the db with all the data
- MARABUNTA_ALLOW_SERIE=True # should not be set in production

Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
1 change: 0 additions & 1 deletion example/odoo/external-src/README.md

This file was deleted.

21 changes: 21 additions & 0 deletions example/pyproject.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
[build-system]
requires=['setuptools-odoo', 'wheel', "setuptools>=67.0"]

[tool.black]
line-length = 88
skip-string-normalization = 'True'
include = '\.pyi?$'
exclude = '''
/(
\.git
| \.mypy_cache
| \.tox
| \.venv
| src/odoo
| src/enterprise
| odoo/paid-modules
| data
)/
| /__openerp__.py
| /__manifest__.py
'''
4 changes: 4 additions & 0 deletions example/odoo/requirements.txt → example/requirements.txt
Original file line number Diff line number Diff line change
@@ -1,2 +1,6 @@
# project's packages, customize for your needs:
unidecode==0.4.14
setuptools-odoo
setuptools>=67.0
wheel
-e /odoo/src/odoo
15 changes: 15 additions & 0 deletions example/setup.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
from setuptools import find_packages, setup

setup(
name="odoo-project",
version='1.0.0',
description="Odoo Project",
license='GNU Affero General Public License v3 or later (AGPLv3+)',
author="Camptocamp",
author_email="[email protected]",
url="www.camptocamp.com",
packages=['songs'] + ['songs.%s' % p for p in find_packages('./songs')],
include_package_data=True,
odoo_addons=True,
)

File renamed without changes.
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -30,5 +30,5 @@ def setup_company(ctx, req):

def main(ctx):
"""Create demo data"""
req = Requirement.parse("my-project-name")
req = Requirement.parse("odoo-project")
setup_company(ctx, req)
File renamed without changes.
9 changes: 5 additions & 4 deletions example/test-compose.yml
Original file line number Diff line number Diff line change
@@ -1,18 +1,17 @@
# Composition used to run automated tests on the images
# Used by the Makefile at the repository's root

version: '2'
version: '3.8'

services:
odoo:
build: ./odoo/
build: .
depends_on:
- db
- kwkhtmltopdf
volumes:
- "data-odoo:/data/odoo"
- "./odoo/src/odoo:/odoo/src/odoo/odoo"
- "./odoo/src/addons:/odoo/src/odoo/addons"
- "./odoo/addons:/odoo/odoo/addons"
environment:
- DB_USER=odoo
- DB_PASS=odoo
Expand All @@ -22,6 +21,8 @@ services:
- MARABUNTA_MODE=demo # could be 'full' for the db with all the data
- KWKHTMLTOPDF_SERVER_URL=http://kwkhtmltopdf:8080
- ODOO_REPORT_URL=http://odoo:8069
- LOCAL_CODE_PATH=/odoo/odoo/addons
- MIGRATION_CONFIG_FILE=/odoo/migration.yml
# cached database dumps config for `runmigration` and `runtests`
- CREATE_DB_CACHE=false # set it to 'true' to create dumps
- LOAD_DB_CACHE=true # by default will always search for existing dumps
Expand Down
25 changes: 16 additions & 9 deletions test.sh
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#!/bin/bash
set -Eeuo pipefail
set -Exeuo pipefail

#
# Run tests on the image
Expand Down Expand Up @@ -62,11 +62,18 @@ cd "$TMP"
echo '>>> Downloading Odoo src'
rm -rf "$TMP/odoo/src"
wget -nv -O /tmp/odoo.tar.gz "$ODOO_URL"
tar xfz /tmp/odoo.tar.gz -C odoo/
mv "odoo/odoo-$VERSION" odoo/src
ls odoo/src
mkdir -p odoo/src
tar xfz /tmp/odoo.tar.gz -C odoo/src
mv "odoo/src/odoo-$VERSION" odoo/src/odoo
ls odoo/src/odoo
echo '>>> Run test for base image'
sed "s|FROM .*|FROM ${IMAGE_LATEST}|" -i odoo/Dockerfile
sed "s|FROM .*|FROM ${IMAGE_LATEST}|" -i Dockerfile
sed "s|version=.*|version=""'""${VERSION}"".1.0.0""'"",|" -i setup.py
sed "s|\(.version.: .\)[0-9.]*\(.*\)|\\1$VERSION.0.0.0\\2|" -i odoo/addons/dummy_test/__manifest__.py
echo $VERSION.0.0.0 > VERSION

cat setup.py
cat odoo/addons/dummy_test/__manifest__.py
mkdir .cachedb

echo '>>> * migration: standard'
Expand All @@ -79,10 +86,10 @@ docoruncmd odoo dropdb odoodb
echo '>>> * migration: use the dump and migrate to new version'
docorunmigration -e LOAD_DB_CACHE="true"
docodown
echo " - version: 15.0.1" >>odoo/migration.yml
echo " operations:" >>odoo/migration.yml
echo " post:" >>odoo/migration.yml
echo " - anthem songs.install.demo::create_partners" >>odoo/migration.yml
echo " - version: 15.0.1" >>migration.yml
echo " operations:" >>migration.yml
echo " post:" >>migration.yml
echo " - anthem songs.install.demo::create_partners" >>migration.yml
docoruncmd odoo dropdb odoodb

echo '>>> * migration: use a ceil version'
Expand Down

0 comments on commit 42edd0f

Please sign in to comment.