Odoo Test Docker Environment
Relevant source files
The following files were used as context for generating this wiki page:
The Odoo Test Docker Environment is a containerized infrastructure designed to provide a reproducible and isolated instance of Odoo 17 and PostgreSQL for development and testing purposes. This environment allows developers to verify the integration of the OdooConnectorAPI against a live ERP system without requiring a manual local installation of Odoo or its dependencies.
The environment is orchestrated using Docker Compose, defining the necessary services, networking, and security configurations to simulate a production-like Odoo instance. It serves as the target for connection tests and API endpoint verification during the development lifecycle.
Sources: README.md:3-8, odoo/docker-compose.yml:1-53
Environment Architecture
The test environment consists of two primary services: a web application service running Odoo 17 and a database service running PostgreSQL 13. These services communicate over a private bridge network named mynetwork.
Service Components
| Service | Image | Role | Port Mapping |
|---|---|---|---|
web | odoo:17 | Odoo ERP application server | 8069:8069 |
db | postgres:13 | PostgreSQL database backend | Internal only |
Sources: odoo/docker-compose.yml:3-53
Service Relationship Diagram
The following diagram illustrates the dependency and network relationship between the Odoo application and its database within the Docker environment.
The Odoo web service depends on the db service and connects to it using internal hostname db.
Sources: odoo/docker-compose.yml:25-27, 28-32, 53
Configuration and Security
The environment implements resource limits and security hardening to ensure stable testing conditions. Both services are restricted in terms of CPU and memory usage to prevent resource exhaustion during automated tests.
Resource Limits and Security Options
| Feature | Configuration Value | Target Service |
|---|---|---|
| CPU Limit | 0.50 | web, db |
| Memory Limit | 512M | web, db |
| Security Opt | no-new-privileges | web, db |
| Capabilities (Drop) | ALL | web, db |
| Capabilities (Add) | NET_BIND_SERVICE | web |
| Capabilities (Add) | CHOWN, SETGID, SETUID | db |
Sources: odoo/docker-compose.yml:5-24, 38-51
Environment Variables
The Odoo container is configured via environment variables to establish the initial connection to the database and initialize the system.
# Odoo Web Environment (Snippet)
environment:
HOST: "db"
USER: "odoo"
PASSWORD: "odoo"
# PostgreSQL Database Environment (Snippet)
environment:
POSTGRES_DB: "odoodb"
POSTGRES_USER: "odoo"
POSTGRES_PASSWORD: "odoo"
Sources: odoo/docker-compose.yml:28-33, 49-53
Connection Testing
A dedicated module, test_odoo_connection.py, is provided to verify the availability and accessibility of the Odoo instance once the Docker environment is running.
Connection Verification Flow
The test script uses the odoorpc library to perform a login handshake with the Odoo container exposed on the host's port 8069.
Sources: odoo/test_odoo_connection.py:7-12
Testing Logic
The connection test attempts to login to the specific database odoodb created during the Docker startup process using default credentials.
def test_odoo_connection():
"""Test connection to the Odoo server."""
odoo = odoorpc.ODOO('localhost', port=8069)
try:
odoo.login('odoodb', 'admin', 'admin') # Database, username, password
print("Successfully connected to Odoo 17!")
except ConnectionError as e:
print(f"Error connecting to Odoo 17: {e}")
Sources: odoo/test_odoo_connection.py:6-13
Health Checks
Both services include health check configurations to ensure they are ready to accept traffic.
- Odoo Web: Uses
curlto verify the web interface onhttp://localhost:8069. - PostgreSQL: Uses
pg_isreadyto verify database availability for theodoouser.
Sources: odoo/docker-compose.yml:12-16, 34-38
Integration with OdooConnectorAPI
While the test environment provides the Odoo instance, the OdooConnectorAPI (defined in app/main.py) acts as the gateway. In a local development scenario using docker-compose.yml at the root, the API is configured to point to this Odoo environment using environment variables.
# Root docker-compose.yml (Snippet)
services:
web:
environment:
ODOO_URL: ${ODOO_URL}
ODOO_DB: ${ODOO_DB}
ODOO_USERNAME: ${ODOO_USERNAME}
ODOO_PASSWORD: ${ODOO_PASSWORD}
Sources: docker-compose.yml:8-12, app/main.py:9-13
The Odoo Test Docker Environment provides a self-contained, secure, and resource-constrained Odoo instance, enabling consistent testing of RPC calls and API endpoints for the OdooConnectorAPI project.