odoo在线开发环境部署实录(vscode)

1、前言

本文记录了通过docker、docker-compose部署code-server、postgresql,搭建odoo在线开发环境的过程,综合体验很爽,适合小规模开发团队使用。

搭建的适合小团队的免费开源在线开发环境,基于 code-server实现,目前还比较粗糙,过程需要手动的地方较多,但用起来刚刚的,小伙伴说挺好用的,调试很方便,代码修改后可以立刻在线看到效果,可以邀请客户一起进行敏捷交付。后期还可以在devops路上走的更远。

安装环境:
vmware hypervision、centos 8,python 3.7

2、安装docker

# 获取阿里云yum镜像文件
curl -o /etc/yum.repos.d/CentOS-Base.repo https://mirrors.aliyun.com/repo/Centos-8.repo
# 非阿里云主机需要替换地址
sed -i -e '/mirrors.cloud.aliyuncs.com/d' -e '/mirrors.aliyuncs.com/d' /etc/yum.repos.d/CentOS-Base.repo
# 重建 yun cache
yum clean all
yum makecache
# 使用yum升级系统
yum update  --nobest

#删除旧的docker
sudo yum remove docker                   docker-client                   docker-client-latest                   docker-common                   docker-latest                   docker-latest-logrotate                   docker-logrotate                   docker-engine

# 安装最新版的containerd.io
dnf install https://mirrors.aliyun.com/docker-ce/linux/centos/7/x86_64/nightly/Packages/containerd.io-1.2.6-3.3.el7.x86_64.rpm

#安装Yum源管理工具
yum install -y yum-utils device-mapper-persistent-data lvm2

#安装阿里云的docker-ce源
yum-config-manager --add-repo https://mirrors.aliyun.com/docker-ce/linux/centos/docker-ce.repo
yum makecache

#安装docker-ce

yum install docker-ce docker-ce-cli

#配置docker 镜像
sudo mkdir -p /etc/docker
sudo tee /etc/docker/daemon.json <<-'EOF'
{
  "registry-mirrors": ["https://heusyzko.mirror.aliyuncs.com"]
}
EOF
sudo systemctl daemon-reload
sudo systemctl restart docker

3、安装 docker-compose

curl -L https://get.daocloud.io/docker/compose/releases/download/1.26.2/docker-compose-`uname -s`-`uname -m` > /usr/local/bin/docker-compose
chmod +x /usr/local/bin/docker-compose

5、编辑Dockerfile文件

vs code的插件建议自行在官方市场下载后,放到extensions目录。
下载地址:
https://marketplace.visualstudio.com/

odoo开发环境常用插件如下:

名称 说明
python Python extension for Visual Studio Code
Chinese (Simplified) Language Pack for Visual Studio Code 中文语言包
Odoo Code Snippets odoo 代码提示器
GitLens git增强插件,可以很方便看到代码的提交修改记录,还至此在代码行提示代码的变更信息
Bracket Pair Colorizer 2 括号显示不同颜色,对于js等括号多的很友好

准备vpn

1、准备华为secoclient for linux
从华为网站http://support.huawei.com/enterprise下载SecoClient 软件包

2、将软件包解压后,文件放置在Dockerfile同级的tmp文件夹中,便于dockerfile一次性COPY到容器中

secoclient-linux-64-7.0.2.26.run

3、准备vpn安装脚本
脚本文件放在Dockerfile同级的copyfiles文件夹中,便于dockerfile一次性COPY到容器中

#! /bin/bash
# installvpn.sh
cd /copyfiles
./secoclient-linux-64-7.0.2.26.run
ln -s /usr/local/SecoClient/serviceclient/SecoClientCS /root/startvpn
cp -R /copyfiles/SecoClient /root/
cp /copyfiles/setroute.sh /root/
cp /copyfiles/sources.list /etc/apt/

4、准备路由表修改脚本

因为客户的vpn客户端登录后,会增加到10.0.0.0/16的默认路由,这条路由与我的code-server所在网络环境路由冲突,因此需要手工调整路由表,如果code-server的网络没有在10.0.0.0/16网络,就不需要修改路由表

脚本文件setroute.sh放置在Dockerfile同级copyfiles文件夹中,便于dockerfile一次性COPY到容器中

yangjiajun
Yangjj4021

#! /bin/bash
# setroute.sh
HOST_IP=$(ifconfig cnem_vnic|grep inet|awk '{print $2}'|tr -d "addr:")
route del -net 10.0.0.0 netmask 255.255.0.0
route add -net 10.0.9.0 netmask 255.255.255.0 gw $HOST_IP


准备odoo依赖的pip包需求文件用于pip批量安装

lib.txt,放置在Dockerfile同级的copyfiles文件夹中。

argh==0.26.2
Babel==2.3.4
beautifulsoup4==4.5.3
chardet==2.3.0
decorator==4.4.1
docopt==0.6.2
docutils==0.13.1
feedparser==5.1.3
gevent
greenlet
html2text==2016.9.19
Jinja2==2.8
libsass==0.12.3
lxml
Mako==1.0.6
MarkupSafe==0.23
mock==2.0.0
networkx==2.4
num2words==0.5.9
ofxparse==0.14
passlib==1.7.0
pathtools==0.1.2
pbr==1.10.0
phonenumbers==8.10.22
Pillow
pinyin==0.4.0
psutil==5.0.1
psycopg2==2.7.6.1
pydot
pyldap
pyparsing==2.1.10
PyPDF2==1.26.0
pyserial==3.2.1
python-dateutil==2.5.3
python-stdnum==1.5
pytz==2016.7
pyusb==1.0.0
PyYAML==3.12
qrcode==5.3
redis==3.3.11
reportlab==3.3.0
requests==2.12.4
roman==2.0.0
six
suds-jurko
urllib3
vatnumber
vobject
watchdog
Werkzeug==0.11.15
xlrd
XlsxWriter
xlwt
pylint

注:pylint用于python 代码检查,用法如下:

pylint --load-plugins=pylint_odoo -e odoolint ...

例如:

touch {ADDONS-PATH}/__init__.py
pylint --load-plugins=pylint_odoo -d all -e odoolint {ADDONS-PATH}

准备apt-get镜像源文件 sources.list

放置在Dockerfile同级的copyfiles文件夹中。

deb http://mirrors.aliyun.com/debian  stable main contrib non-free
deb http://mirrors.aliyun.com/debian  stable-updates main contrib non-free

准备dockerfile

FROM codercom/code-server:latest
USER root
# 更新源
RUN mkdir /copyfiles
COPY copyfiles /copyfiles
RUN cd /copyfiles \
 && cp sources.list /etc/apt \
 && apt-get update \
 && apt-get upgrade -y \
 && apt-get install -y net-tools python3 python3-pip python3-dev build-essential libssl-dev libffi-dev  libxml2-dev libxslt1-dev zlib1g-dev libldap2-dev libsasl2-dev \
 && pip3 config set global.index-url http://mirrors.aliyun.com/pypi/simple \
 && pip3 config set install.trusted-host mirrors.aliyun.com \
 && pip3 install -r /copyfiles/lib.txt \
 && pip3 install --upgrade --pre pylint-odoo

WORKDIR /home/coder/project
# 容器启动code-server:指定插件目录,指定中文
ENTRYPOINT ["code-server","--locale","zh-cn","--host","0.0.0.0","--port","8080", "--user-data-dir", "/home/coder","--cert",""]

6、build 自定义docker image

docker build -t boshine/psclouder:latest --rm=true .

docker-compose up -d
docker exec -it pscloud bash

7、编辑docker-compose

如果团队多人一起协同开发,建议每个人部署一个code-server容器,实现环境隔离。
配合github/gitee/gitlab等代码管理服务器使用。

version: "3"

services:
  pg:
    image: postgres:12
    ports:
      - 5432:5432
    environment:
      - POSTGRES_DB=postgres
      - POSTGRES_PASSWORD=odoo
      - POSTGRES_USER=odoo
      - PGDATA=/var/lib/postgresql/data/pgdata
    volumes:
      - /root/pg/data:/var/lib/postgresql/data/pgdata
      - /root/pg/tmp:/tmp
  pscloud:
    container_name: psclouder
    image: boshine/psclouder:latest
    links:
      - pg
    depends_on:
      - pg
    ports:
      - "8068:8080"
      - "8069:8069"
    volumes:
      - "/root/pscloud:/home/"
      - "/root/pscloud/root:/root"
      - "/root/pscloud/tmp:/tmp"
    environment:
      PASSWORD: pscloud
      TZ: Asia/Shanghai
    restart: always
    privileged: true
    user: root

  odoozhang:
    container_name: odoozhang
    image: boshine/psclouder:latest
    links:
      - pg
    depends_on:
      - pg
    ports:
      - "18068:8080"
      - "18069:8069"
    volumes:
      - "/root/odoozhang:/home/"
      - "/root/odoozhang/root:/root"
      - "/root/odoozhang/tmp:/tmp"
    environment:
      PASSWORD: pscloud
      TZ: Asia/Shanghai
    restart: always
    privileged: true
    user: root

  odooma:
    container_name: odooma
    image: boshine/psclouder:latest
    links:
      - pg
    depends_on:
      - pg
    ports:
      - "28068:8080"
      - "28069:8069"
    volumes:
      - "/root/odooma:/home/"
      - "/root/odooma/root:/root"
      - "/root/odooma/tmp:/tmp"
    environment:
      PASSWORD: pscloud
      TZ: Asia/Shanghai
    restart: always
    privileged: true
    user: root

8、使用docker-compose运行coder容

docker-compose -f odoo.yml up -d
上一篇:【odoo】关联字段的增删改


下一篇:odoo 多个数据库http请求指定数据库