_# jeffery # focus on Odoo and other open source IT solutions # IT基础架构资深专家,开源解决方案专家,odoo资深专家__Q:913547235 讨论群397750860

使用 pycharm调试docker环境运行的Odoo


2019114日 星期一

安装docker

windows系统,参考 docker官方文档

Mac系统,参考 docker官方文档

 

 

构建自定义ODOO镜像

标准ODOO镜像可能不包含特别的python模块,或者Linux工具,此时需要 自定义 Odoo镜像

 

dockerfile

编写dockerfile,例如加入需要的python

  10.1 git:(master) cat Dockerfile 

FROM odoo:10.0

MAINTAINER Odoo S.A. <info@odoo.com>

 

USER root

 

COPY ./pip.conf /root/.pip/pip.conf

 

RUN set -x; \  

    pip install pypinyin pypdf

 

# Set default user when running the container

USER odoo

 

ENTRYPOINT ["/entrypoint.sh"]

CMD ["odoo"]

 

说明: 上面的自定义镜像,是在Odoo10 基础上,安装了 pypinyin 模块,为了使用本地pip镜像,例如 pip.conf 内容

  10.1 git:(master) cat pip.conf 

[global]

index-url=http://mirrors.aliyun.com/pypi/simple/

[install]

trusted-host=mirrors.aliyun.com

 

构建镜像

基于dockerfile构建镜像

  10.1 git:(master) docker build . -t odoo:10.1

Sending build context to Docker daemon  3.072kB

Step 1/8 : FROM odoo:10.0

---> 50bfb7575fe2

Step 2/8 : MAINTAINER Odoo S.A. <info@odoo.com>

---> Using cache

---> 353b1366ee28

Step 3/8 : USER root

---> Using cache

---> 27ec1ca1072c

Step 4/8 : COPY ./pip.conf /root/.pip/pip.conf

---> Using cache

---> ebdd6547d4e1

Step 5/8 : RUN set -x;     pip install pypinyin pypdf

---> Using cache

---> 72edd5d9d792

Step 6/8 : USER odoo

---> Using cache

---> 0cc904972ec2

Step 7/8 : ENTRYPOINT ["/entrypoint.sh"]

---> Using cache

---> e4738346b7a3

Step 8/8 : CMD ["odoo"]

---> Using cache

---> 793edee6ab30

Successfully built 793edee6ab30

Successfully tagged odoo:10.1

 

这样,就会建立odoo:10.1 镜像

比如 docker images查看镜像

  10.1 git:(master) docker images

REPOSITORY                      TAG                 IMAGE ID            CREATED             SIZE

odoo                            10.1                793edee6ab30        3 days ago          894MB   <<<<<

<none>                          <none>              2ebbc09b340c        4 days ago          888MB

<none>                          <none>              5e1be85e3ee9        4 days ago          894MB

<none>                          <none>              cd0e2acac50b        4 days ago          536MB

<none>                          <none>              317e442f4416        4 days ago          561MB

<none>                          <none>              7d6ae7c50fb6        4 days ago          549MB

<none>                          <none>              73c08dfaaf64        4 days ago          546MB

pycharm_helpers                 PY-183.6156.16      0430ed2d37ee        6 days ago          37.1MB

odoo                            13.0                b77d7d215af3        7 days ago          1.14GB

<none>                          <none>              7b449bc0b8bd        7 days ago          535MB

odoo                            11.0                ac8c1f2da96a        11 days ago         1.07GB

odoo                            12.0                a914ad271b31        11 days ago         1.15GB

<none>                          <none>              687217ff7424        2 weeks ago         84.1MB

postgres                        12                  f88dfa384cc4        2 weeks ago         348MB

odoo                            10.0                50bfb7575fe2        2 weeks ago         888MB

debian                          stretch-slim        c2f145c34384        2 weeks ago         55.3MB

debian                          buster-slim         105ec214185d        2 weeks ago         69.2MB

debian                          latest              8e9f8546050d        2 weeks ago         114MB

busybox                         latest              19485c79a9bb        2 months ago        1.22MB

shadowsocks/shadowsocks-libev   latest              4ae4e89442e8        2 months ago        17.4MB

dpage/pgadmin4                  latest              15aebd95450f        3 months ago        237MB

postgres                        10                  897b33033d64        3 months ago        230MB

postgres                        11                  53912975086f        3 months ago        312MB

mplatform/mquery                latest              0e11d82ddb1d        2 years ago         7.11MB

 

 

使用docker compose编排 Odoo

odoo是基于多个服务,用docker compose 对这些服务进行编排,会比较方便。

 

编写 docker-compose.yml

编写 docker-compose.yml 文件,内容如下

  odoo10c cat docker-compose.yml 

version: '3.3'

 

services:

  # Web Application Service Definition

  # --------

  #

  # All of the information needed to start up an odoo web

  # application container.

  web:

    image: odoo:10.1

    depends_on:

        - db

        - pgadmin

 

    # Port Mapping

    # --------

    #

    # Here we are mapping a port on the host machine (on the left)

    # to a port inside of the container (on the right.) The default

    # port on Odoo is 8069, so Odoo is running on that port inside

    # of the container. But we are going to access it locally on

    # our machine from localhost:9000.

    ports:

      - 9000:8069

 

    # Data Volumes

    # --------

    #

    # This defines files that we are mapping from the host machine

    # into the container.

    #

    # Right now, we are using it to map a configuration file into

    # the container and any extra odoo modules.

    volumes:

      - ./config:/etc/odoo

    # - ./addons:/mnt/extra-addons

      - ../../git-repo/geely-mts:/mnt/extra-addons

 

    # Odoo Environment Variables

    # --------

    #

    # The odoo image uses a few different environment

    # variables when running to connect to the postgres

    # database.

    #

    # Make sure that they are the same as the database user

    # defined in the db container environment variables.

    environment:

      - HOST=db

      - USER=odoo

      - PASSWORD=odoo

 

  # Database Container Service Definition

  # --------

  #

  # All of the information needed to start up a postgresql

  # container.

  db:

    image: postgres:11

 

    # Database Environment Variables

    # --------

    #

    # The postgresql image uses a few different environment

    # variables when running to create the database. Set the

    # username and password of the database user here.

    #

    # Make sure that they are the same as the database user

    # defined in the web container environment variables.

    environment:

      - POSTGRES_PASSWORD=odoo

      - POSTGRES_USER=odoo

      - POSTGRES_DB=postgres  # Leave this set to postgres

 

  pgadmin:

    image: dpage/pgadmin4

    depends_on:

        - db

    environment:

      PGADMIN_DEFAULT_EMAIL: ${PGADMIN_DEFAULT_EMAIL:-admin}

      PGADMIN_DEFAULT_PASSWORD: ${PGADMIN_DEFAULT_PASSWORD:-admin}

    volumes:

       - pgadmin:/root/.pgadmin

    ports:

      - "${PGADMIN_PORT:-5050}:80"

 

volumes:

    pgadmin:

 

 

说明:

1.        Odoo 服务,使用自定义的镜像,例如 Odoo10.1

2.       编排了 PG服务

3.       编排 PGADMIN 方便对PG 进行管理

 

测试 docker-compose.yml

 

使用 docker-compose 启动 Odoo, 运行命令

  odoo10c docker-compose up

odoo10c_db_1 is up-to-date

odoo10c_pgadmin_1 is up-to-date

Recreating odoo10c_web_1 ... done

Attaching to odoo10c_db_1, odoo10c_pgadmin_1, odoo10c_web_1

pgadmin_1  | NOTE: Configuring authentication for SERVER mode.

pgadmin_1  | 

pgadmin_1  | [2019-11-03 13:02:57 +0000] [1] [INFO] Starting gunicorn 19.9.0

pgadmin_1  | [2019-11-03 13:02:57 +0000] [1] [INFO] Listening at: http://[::]:80 (1)

 

第一次运行 docker-compose 时,会创建相关的容器,上面的例子显示更新容器,是因为容器之前已经创建好。

 

此时,用浏览器访问  http://127.0.0.1:9000 即可访问到 Odoo服务 ; 访问  http://127.0.0.1:5050 即可访问到 pgadmin

 

 Odoo镜像说明

官方 Odoo镜像会在 在 docker-compose.yml 所在目录建立 2个目录,用于挂载到 Odoo容器用做 volume,其中:addons挂载到 /mnt/extra-addons , 以及  config 挂载到 /etc/odoo

Odoo容器默认使用 /etc/odoo/odoo.conf 作为配置文件。

 

所以,1,如果要自定义配置,修改 config/odoo.conf 文件即可,可以从 odoo docker 项目拷贝 原始 配置文件 作为 config/odoo.conf  2,如果要挂载自定义的ADDONS,挂载到 addons 目录即可。

 

 

Pycharm 调用 docker compose 远程运行Odoo

 

配置pycharm 使用 docker compose

 

 使用 pycharm Odoo 模块项目导入

image

 

preference ,选择 项目解释器

image

 

在项目解释器, 点击 ⚙️图标,选择 ADD

在弹窗,选择 docker compose

image

server 处,选择 docker 服务器,或者 新建docker 服务器。

注意:

如果是 windows平台,需要 关闭Docker  TLS ,如何关闭,具体 参考PYcharm官方文档,或者docker 文档

image

configuration file 选择前面建立的服务编排  docker-compose.yml 文件

 

service 选择 web  注意, Pycharm 自动识别出 编排文件包含的所有服务,并且按字母排序

 

然后,点击OK 确认。

pycharm将会 去docker容器,侦测python的版本,完成后,远程解释器将会配置如下图所示

image

 


使用 远程解释器运行 Odoo

 

 建立 开发专用 Odoo配置

 

因为 pycharm 会将 项目 挂载到 容器的 /opt/project 下,如Odoo默认的 extra-addons不同;

所以,需要为 开发建立一个专用的 配置文件,例如  config/odoo-dev.conf

 

注意,这个文件存放在 docker-compose.yml文件目录

 

在这个 文件里面将   addons_path 指向  /opt/project

例如

addons_path = /opt/project

 

备注:

项目被挂载到 /opt/project 时由pycharm 生成的 docker compose 所指定

image

 

 配置 run configuration

 

run 菜单,选择 edit configuration,在弹窗

image


 

在 脚本 输入  /usr/bin/odoo

在 参数 输入 -c /etc/odoo/odoo-dev.conf

 

python 解释器,选择 前面建立的 远程python

 

运行 Odoo

 

点击 run  按钮,运行 Odoo

 pycharm将 调用 docker compose 运行Odoo,如图


image

posted on 2019-11-04 21:10  odoouse  阅读(2198)  评论(0编辑  收藏  举报

导航

_# jeffery # focus on Odoo and other open source IT solutions # IT基础架构资深专家,开源解决方案专家,odoo资深专家