doodba (Docker Odoo Base)

repository·master·Indexed 20 days ago

https://github.com/tecnativa/doodba

A highly opinionated Docker base image for Odoo developers built on Debian. Doodba provides a structured environment to manage Odoo versions, custom patches, third-party repositories, and dependencies. It includes tools like the `addons` CLI for module management and `autoaggregate` for git repository aggregation via `repos.yaml` and `addons.yaml` configurations.

Tokens
6.9K
Snippets
21
Records
37
Agent score
69%

What's inside doodba

  1. Overview of Doodba

    master
    Doodba (Docker Odoo Base) is a highly opinionated Docker base image designed to facilitate building custom Odoo projects. It does not include Odoo itself; instead, it provides a standardized project structure, a collection of best practices, and tools to manage the complex customizations (patches, merges, repositories, and dependencies) typically required when developing with Odoo. It is built on top of Debian.
  2. Enable hot code reloading with `inotify`

    master

    Doodba supports hot code reloading for Odoo versions 11.0 and later. When starting Odoo with the --dev flag, you can pass reload or all as an argument to enable this feature via inotify.

    If you use the Doodba Copier Template, this is enabled by default in development environments.

  3. Manage project source code with repos.yaml and addons.yaml

    master

    Project source code resides in /opt/odoo/custom/src. Doodba uses two main files to manage this:

    1. repos.yaml: A git-aggregator configuration that defines remotes, targets (branches), and merges for your repositories. This is used to pull in Odoo core, OCA modules, or custom repos at build time.
    2. addons.yaml: Defines which specific addons/modules from the downloaded repositories should be activated in your project.

    Important Folders:

    • /opt/odoo/custom/src/odoo: REQUIRED. Contains the Odoo source code.
    • /opt/odoo/custom/src/private: REQUIRED. Contains your project's private addons.

    Recommendation: Use repos.yaml for everything except the private folder. In your .gitignore and .dockerignore, ignore everything in odoo/custom/src/* except for the private folder.

  4. Understand the Doodba directory structure

    master

    Doodba organizes files into three main directories under /opt/odoo. Understanding this structure is key to customizing your Odoo environment:

    • /opt/odoo/custom: The primary location for your project-specific files (source code, configuration, dependencies, SSH keys).
    • /opt/odoo/common: Contains internal logic and shared scripts used by the build and entrypoint processes.
    • /opt/odoo/auto: Contains automatically generated files at build time, such as symlinks to selected addons and the merged odoo.conf.

    Note: For Doodba to function correctly, your Odoo source code must be located in the odoo folder within the structure.

  5. Customize repository patterns via build arguments

    master

    Doodba automatically downloads repositories based on DEFAULT_REPO_PATTERN and DEFAULT_REPO_PATTERN_ODOO. You can override these patterns by passing them as build arguments in your docker-compose.yaml file.

    services:
      odoo:
        build:
          args:
            DEFAULT_REPO_PATTERN: &origin "https://github.com/Tecnativa/{}.git"
            DEFAULT_REPO_PATTERN_ODOO: *origin
  6. Configure custom entrypoints and build scripts

    master

    You can extend the container's lifecycle by placing executables in the following directories within /opt/odoo/custom:

    • /opt/odoo/custom/entrypoint.d: Executables here run when the container launches, immediately before the main command.
    • /opt/odoo/custom/build.d: Executables here are aggregated with /opt/odoo/common/build.d, sorted alphabetically, and executed during the build process.
  7. Build a project subimage from Doodba

    master

    Doodba is a base image containing tools and ONBUILD instructions. You must build your own project subimage from it. Your project's Dockerfile should look like this:

    FROM tecnativa/doodba
    MAINTAINER Me <me@example.com>

    Crucial: Your project must include a ./custom folder alongside your Dockerfile for the ONBUILD logic to work.

  8. Set up SSH keys and deployment keys

    master

    The /opt/odoo/custom/ssh directory functions like a standard ~/.ssh directory (equivalent to ~root/.ssh). This is used to provide deployment keys for accessing private git repositories.

    • Default keys: Files named id_rsa, id_rsa.pub, id_dsa, or identity[.pub] are used by default.
    • Custom keys: Use a config file to specify IdentityFile paths.
    • Host checking: Host key checking is enabled by default. You must provide a known_hosts file for any repositories accessed via SSH. To disable this for a specific host, use StrictHostKeyChecking no in your config file.
    # Example config for a private repo
    Host repo.example.com
      IdentityFile ~/.ssh/my_private_key
    
    # Example to disable host key checking
    Host repo.example.com
      StrictHostKeyChecking no
  9. Pin Doodba image versions using SHA256 digests

    master

    To ensure stability and prevent unexpected updates, pin your Doodba image version using its sha256 digest rather than a tag.

    1. Find the digest by inspecting a local image:
    docker image inspect --format='{{.RepoDigests}}' tecnativa/doodba:10.0-onbuild
    1. Use the digest in your Dockerfile:
    # Hash-pinned version of tecnativa/doodba:10.0-onbuild
    FROM tecnativa/doodba@sha256:fba69478f9b0616561aa3aba4d18e4bcc2f728c9568057946c98d5d3817699e1
    FROM tecnativa/doodba@sha256:fba69478f9b0616561aa3aba4d18e4bcc2f728c9568057946c98d5d3817699e1
  10. How to start with Doodba

    master
    To begin working with Doodba, you should use the provided project template. This ensures you follow the intended directory structure and configuration patterns required for the image to function correctly.
  11. Debug Python code with `debugpy` in VSCode

    master

    To use the VSCode debugger, you can enable it by setting the DEBUGPY_ENABLE=1 environment variable for your Odoo container.

    1. In your Python code, add a breakpoint trigger:
    import debugpy
    debugpy.listen(6899)
    print("Waiting for debugger attach")
    debugpy.wait_for_client()
    debugpy.breakpoint()
    print('break on this line')
    1. In your environment, if using the official template, boot with:
    export DOODBA_DEBUGPY_ENABLE=1
    docker-compose -f devel.yaml up -d
    1. Configure VSCode by creating a .vscode/launch.json file with the following minimal configuration to attach to the container:
    {
      "version": "0.2.0",
      "configurations": [
        {
          "name": "Attach to debug in devel.yaml",
          "type": "python",
          "request": "attach",
          "pathMappings": [
            {
              "localRoot": "${workspaceRoot}/odoo",
              "remoteRoot": "/opt/odoo"
            }
          ],
          "port": 6899,
          "host": "localhost"
        }
      ]
    }
    export DOODBA_DEBUGPY_ENABLE=1
    docker-compose -f devel.yaml up -d
  12. Aggregate repositories with `autoaggregate` and `repos.yaml`

    master

    The autoaggregate script (a wrapper for git-aggregator) allows you to merge multiple git repositories into your project. You define these in a repos.yaml file.

    Example repos.yaml configuration:

    ./odoo:
      defaults:
        # Shallow repositories are faster & thinner.
        depth: $DEPTH_MERGE
      remotes:
        ocb: https://github.com/OCA/OCB.git
        odoo: https://github.com/odoo/odoo.git
      target: ocb $ODOO_VERSION
      merges:
        - ocb $ODOO_VERSION
        - odoo refs/pull/13635/head
      shell_command_after:
        # Useful to merge a diff when there's no git history correlation
        - curl -sSL https://github.com/odoo/odoo/pull/37187.diff | patch -fp1
    ./odoo:
      defaults:
        depth: $DEPTH_MERGE
      remotes:
        ocb: https://github.com/OCA/OCB.git
        odoo: https://github.com/odoo/odoo.git
      target: ocb $ODOO_VERSION
      merges:
        - ocb $ODOO_VERSION
        - odoo refs/pull/13635/head
      shell_command_after:
        - curl -sSL https://github.com/odoo/odoo/pull/37187.diff | patch -fp1