VSCode+Docker搭建Odoo17开发环境

转载【https://www.jianshu.com/p/9fc9df17f848】

参考:https://hub.docker.com/_/odoo

项目结构

+ .devcontainer
  - devcontainer.json
  - docker-compose.yml
+ .vscode
  - launch.json
+ data
+ addon1
  - data
  - models
  - views
  - security
  - __init__.py
  - __manifest__.py
+ addon2
  odoo.conf
  .gitignore
  .flake8

几个主要配置文件

docker-compose.yml

version: "3"

networks:
  default:
    external: false

services:
  pgsql15:
    image: postgres:15
    container_name: pgsql15
    environment:
      - POSTGRES_DB=postgres
      - POSTGRES_USER=oduser
      - POSTGRES_PASSWORD=od_pwd
      - PGDATA=/var/lib/postgresql/data
    volumes:
      - odoo-db-data:/var/lib/postgresql/data
  odoo17:
    image: odoo:17
    container_name: odoo17
    depends_on:
      - pgsql15
    volumes:
      - ../:/mnt/extra-addons
    environment:
      - ODOO_RC=/mnt/extra-addons/odoo.conf
      - HOST=pgsql15
      - USER=oduser
      - PASSWORD=od_pwd
    ports:
      - 8069:8069
      - 8072:8072

volumes:
  odoo-web-data:
  odoo-db-data:

devcontainer.json

{
    "name": "odoo17_dev",
    "dockerComposeFile": "./docker-compose.yml",
    "service": "odoo17",
    "overrideCommand": true,                        // 屏蔽容器的启动命令
    "workspaceFolder": "/mnt/extra-addons",
    "onCreateCommand": "pip3 config set global.index-url https://mirrors.aliyun.com/pypi/simple",
    "shutdownAction": "stopCompose",
    "shell": "bash",
    "features": {
        
    },
    "postCreateCommand": [

    ],
    "customizations": {
        "vscode": {
            "settings": {
                // 容器内的全局设置
                "terminal.integrated.shellIntegration.enabled": true,
                "terminal.integrated.defaultProfile.linux": "bash"
            },
            "extensions": [
                "ms-python.python",
                "ms-python.vscode-pylance",
                "ms-python.flake8",
                "ms-python.autopep8",
                "ms-python.isort",
                "cweijan.vscode-postgresql-client2",
                "guodongsun.vscode-git-cruise",
                "redhat.vscode-xml"
            ]
        }
    }
}

odoo.conf

[options]
addons_path = /mnt/extra-addons
list_db = True
db_host = pgsql15
db_user = oduser
db_password = od_pwd
data_dir = /mnt/extra-addons/data
# workers = 2

launch.json

{
    "version": "0.2.0",
    "configurations": [
        {
            "name": "odoo",
            "type": "python",
            "request": "launch",
            "program": "/usr/bin/odoo",
            "args": [
                "-c",
                "/mnt/extra-addons/odoo.conf"
            ],
            "console": "integratedTerminal",
            // "gevent": true,      // 需要多线程的时候需要开启此选项,但是开了这个选项之后可能会导致DEBUG失效,进不去断点
            "justMyCode": false
        }
    ]
}

 

版权声明:
作者:xiaoniba
链接:https://blog.xiaoniba.com/2024/02/03/vscodedocker%e6%90%ad%e5%bb%baodoo17%e5%bc%80%e5%8f%91%e7%8e%af%e5%a2%83/
来源:小泥吧的博客
文章版权归作者所有,未经允许请勿转载。

THE END
分享
二维码
< <上一篇
下一篇>>