Container¶
Tổng quan¶
Mỗi bản dựng được cô lập trong container riêng (container có namespace Linux).
Cơ sở là hệ thống Ubuntu, nơi tất cả các phụ thuộc cần thiết của Odoo, cũng như các gói hữu ích và phổ biến, được cài đặt.
If your project requires additional Python dependencies, or more recent releases,
you can define a requirements.txt
file in the root of your branches listing them.
The platform will take care to install these dependencies in your containers.
The pip requirements specifiers
documentation can help you write a requirements.txt
file.
To have a concrete example,
check out the requirements.txt file of Odoo.
The requirements.txt
files of submodules are taken into account as well. The platform
looks for requirements.txt
files in each folder containing Odoo modules: Not in the module folder itself,
but in their parent folder.
Cấu trúc thư mục¶
As the containers are Ubuntu based, their directory structure follows the linux Filesystem Hierarchy Standard. Ubuntu’s filesystem tree overview explains the main directories.
Sau đây là các thư mục liên quan đến Odoo.sh:
.
├── home
│ └── odoo
│ ├── src
│ │ ├── odoo Odoo Community source code
│ │ │ └── odoo-bin Odoo server executable
│ │ ├── enterprise Odoo Enterprise source code
│ │ ├── themes Odoo Themes source code
│ │ └── user Your repository branch source code
│ ├── data
│ │ ├── filestore database attachments, as well as the files of binary fields
│ │ └── sessions visitors and users sessions
│ └── logs
│ ├── install.log Database installation logs
│ ├── odoo.log Running server logs
│ ├── update.log Database updates logs
│ └── pip.log Python packages installation logs
└── usr
├── lib
│ ├── python2.7
│ └── dist-packages Python 2.7 standard libraries
│ ├── python3
│ └── dist-packages Python 3 standard libraries
│ └── python3.5
│ └── dist-packages Python 3.5 standard libraries
├── local
│ └── lib
│ ├── python2.7
│ │ └── dist-packages Python 2.7 third-party libraries
│ └── python3.5
│ └── dist-packages Python 3.5 third-party libraries
└── usr
└── bin
├── python2.7 Python 2.7 executable
└── python3.5 Python 3.5 executable
Cả Python 2.7 và 3.5 đều được cài đặt trong các container. Tuy nhiên:
Nếu dự án của bạn được cấu hình để sử dụng Odoo 10.0, máy chủ Odoo sẽ chạy bằng Python 2.7.
Nếu dự án của bạn được cấu hình để sử dụng Odoo 11.0 trở lên, máy chủ Odoo sẽ chạy bằng Python 3.5.
Shell cơ sở dữ liệu¶
Khi truy cập vào một container bằng shell, bạn có thể truy cập cơ sở dữ liệu bằng cách sử dụng psql.
odoo@odoo-addons-master-1.odoo.sh:~$ psql
psql (9.5.2, server 9.5.11)
SSL connection (protocol: TLSv1.2, cipher: ECDHE-RSA-AES256-GCM-SHA384, bits: 256, compression: off)
Type "help" for help.
odoo-addons-master-1=>
Be careful ! Use transactions (BEGIN…COMMIT/ROLLBACK) for every sql statements leading to changes (UPDATE, DELETE, ALTER, …), especially for your production database.
Cơ chế giao dịch là mạng lưới an toàn của bạn trong trường hợp xảy ra lỗi. Bạn chỉ cần khôi phục các thay đổi để đưa cơ sở dữ liệu về trạng thái trước đó.
Ví dụ, giả sử bạn quên đặt điều kiện WHERE.
odoo-addons-master-1=> BEGIN;
BEGIN
odoo-addons-master-1=> UPDATE res_users SET password = '***';
UPDATE 457
odoo-addons-master-1=> ROLLBACK;
ROLLBACK
Trong trường hợp đó, bạn có thể khôi phục lại những thay đổi không mong muốn mà bạn vừa vô tình thực hiện và viết lại câu lệnh:
odoo-addons-master-1=> BEGIN;
BEGIN
odoo-addons-master-1=> UPDATE res_users SET password = '***' WHERE id = 1;
UPDATE 1
odoo-addons-master-1=> COMMIT;
COMMIT
Tuy nhiên, đừng quên commit hoặc khôi phục giao dịch của bạn sau khi đã thực hiện. Giao dịch mở có thể khóa các bản ghi trong bảng của bạn và cơ sở dữ liệu đang chạy có thể chờ chúng được giải phóng. Điều này có thể khiến máy chủ bị treo vô thời hạn.
Ngoài ra, nếu có thể, hãy sử dụng cơ sở dữ liệu staging để kiểm thử các câu lệnh của bạn trước. Đây là một giải pháp an toàn bổ sung dành cho bạn.
Chạy máy chủ Odoo¶
Bạn có thể khởi động một phiên bản máy chủ Odoo từ một shell container. Bạn sẽ không thể truy cập nó từ bên ngoài bằng trình duyệt, nhưng bạn có thể:
sử dụng shell Odoo,
$ odoo-bin shell
>>> partner = env['res.partner'].search([('email', '=', 'asusteK@yourcompany.example.com')], limit=1)
>>> partner.name
'ASUSTeK'
>>> partner.name = 'Odoo'
>>> env['res.partner'].search([('email', '=', 'asusteK@yourcompany.example.com')], limit=1).name
'Odoo'
cài đặt một phân hệ,
$ odoo-bin -i sale --without-demo=all --stop-after-init
cập nhật một phân hệ,
$ odoo-bin -u sale --stop-after-init
chạy kiểm thử cho một phân hệ,
$ odoo-bin -i sale --test-enable --log-level=test --stop-after-init
Trong các lệnh trên, đối số:
--without-demo=all
prevents demo data to be loaded for all modules--stop-after-init
will immediately shutdown the server instance after it completed the operations you asked.
More options are available and detailed in the CLI documentation.
Bạn có thể tìm thấy đường dẫn addon được Odoo.sh sử dụng để chạy máy chủ của bạn trong nhật ký (~/logs/odoo.log). Tìm “odoo: addons paths”:
2018-02-19 10:51:39,267 4 INFO ? odoo: Odoo version 18.0
2018-02-19 10:51:39,268 4 INFO ? odoo: Using configuration file at /home/odoo/.config/odoo/odoo.conf
2018-02-19 10:51:39,268 4 INFO ? odoo: addons paths: ['/home/odoo/data/addons/18.0', '/home/odoo/src/user', '/home/odoo/src/enterprise', '/home/odoo/src/themes', '/home/odoo/src/odoo/addons', '/home/odoo/src/odoo/odoo/addons']
Hãy cẩn thận, đặc biệt là với cơ sở dữ liệu production. Các thao tác bạn thực hiện khi chạy phiên bản máy chủ Odoo này không bị cô lập: Các thay đổi sẽ có hiệu lực trong cơ sở dữ liệu. Luôn luôn tiến hành kiểm thử trên cơ sở dữ liệu staging.
Gỡ lỗi trong Odoo.sh¶
Việc gỡ lỗi bản dựng Odoo.sh không hẳn khác biệt so với ứng dụng Python khác. Bài viết này chỉ giải thích các đặc điểm và hạn chế của nền tảng Odoo.sh và giả định rằng bạn đã biết cách sử dụng trình gỡ lỗi.
Ghi chú
Nếu chưa biết cách gỡ lỗi ứng dụng Python, bạn có thể dễ dàng tìm thấy nhiều khóa học cơ bản trên Internet.
You can use pdb
, pudb
or ipdb
to debug your code on Odoo.sh.
As the server is run outside a shell, you cannot launch the debugger directly from your Odoo instance backend as the debugger needs a shell to operate.
pdb is installed by default in every container.
If you want to use pudb or ipdb you have to install it before.
Để thực hiện, bạn có hai tuỳ chọn:
tạm thời (chỉ có trong bản dựng hiện tại):
$ pip install pudb --user
hay
$ pip install ipdb --user
permanent: add
pudb
oripdb
to your projectrequirements.txt
file.
Sau đó chỉnh sửa mã, nơi bạn muốn kích hoạt trình gỡ lỗi và thêm mã này:
import sys
if sys.__stdin__.isatty():
import pdb; pdb.set_trace()
The condition sys.__stdin__.isatty()
is a hack that detects if you run Odoo from a shell.
Lưu tệp và sau đó chạy Odoo Shell:
$ odoo-bin shell
Cuối cùng, thông qua Odoo Shell, bạn có thể kích hoạt đoạn mã/hàm/phương thức mà bạn muốn gỡ lỗi.
