Sign inSign up

vimiix/og_psycopg2_builder

By vimiix

•Updated about 3 years ago

用于构建 openGauss-connector-python-psycopg2 的镜像

Image
0

1.2K

vimiix/og_psycopg2_builder repository overview

⁠用于构建 openGauss-connector-python-psycopg2 的镜像

The goal of the manylinux project is to provide a convenient way to distribute binary Python extensions as wheels on Linux. This effort has produced PEP 513⁠ (manylinux1), PEP 571⁠ (manylinux2010), PEP 599⁠ (manylinux2014) and PEP 600⁠ (manylinux_x_y). -----来自 manylinux⁠ 仓库

⁠介绍

这个镜像是基于 PEP599 定义的 manylinux2014 版本(x86_64和arm64 均为 CentOS 7 系统),内置了编译好的用于 opengauss 的 libpq.so 及其相关依赖,以及编译 psycopg2 所需的 pg_config 二进制,用于构建用于 openGauss 的 Python 驱动: openGauss-connector-python-psycopg2⁠

使用该镜像可以直接在容器内执行以下指令进行全版本 wheel 包的构建:

# active db envrionment
source ~/.bashrc

export GIT_REPO=${GIT_REPO:-https://gitee.com/opengauss/openGauss-connector-python-psycopg2.git}
export GIT_BRANCH=${GIT_BRANCH:-master}
export PSYCOPG_VERSION=$(TZ=Asia/Shanghai date "+%Y%m%d.%H%M")

git clone --filter=blob:none  --depth 1 --branch $GIT_BRANCH $GIT_REPO
cd $(basename $GIT_REPO .git)
sed -i "s/^PSYCOPG_VERSION.*/PSYCOPG_VERSION=\"$PSYCOPG_VERSION\"/g" setup.py

for py_version in /opt/python/*; do
    # Generate wheel which not include required libs to ./dist directory
    $py_version/bin/python setup.py bdist_wheel
done

for whl in ./dist/*.whl; do
    # Repair dynamic libs for every wheel, and generate new wheel to ./wheelhouse
    auditwheel repair $whl
done

echo "Wheels generated successfully to `pwd`/wheelhouse"

构建完成后,所有的 wheel 包都在仓库目录下的 wheelhouse 目录中,可根据不同的使用场景进行分发。

⁠为什么需要这个镜像?

首先,为了编译能用于 opengauss 的 psycopg2 驱动,必须将使用 opengauss server 编译出来的 libpq及相关依赖,因为:

  1. 驱动中增加了 og 新增的接口;
  2. og 的三方库都增加了一些 CVE 漏洞的补丁,更安全;

其次,现在社区提供的安装包方案是:提供给用户两个目录,一个 psycopg2 目录和一个依赖动态库的 lib 目录,用户使用时需将 lib 添加到 LD_LIBRARY_PATH 的环境变量中,以使得被驱动调用到。这样的方式有几个弊端:

  1. 社区目前提供的包是使用 python3.7 编译出来的,所以仅能用于 python3.7 的环境使用,如果需支持更多版本,需社区增加更多版本的流水线;
  2. 将驱动依赖的 lib 目录添加到 LD_LIBRARY_PATH 的方式会导致驱动所在服务器其他的进程如果也依赖同名的动态库时,错误的引用到驱动的包,造成不必要的麻烦;
  3. 安装有点hack,提供目录的方式,需用户手动拷贝目录并修改权限来安装,仅仅拷贝完后,pip list 无法真正被识别到;
  4. 目前社区编译出来的动态库,无法直接用 auditwheel 来修复 wheel 包,报错:the presence of too-recent versioned symbols,所以需在容器中重新编译相关依赖;

而使用该镜像编译出来的 wheel 包有这些好处:

  1. 最大程度的支持大部分的 linux 发行版操作系统
  2. 可以在单个镜像内编译 cpython 3.6~3.12 的所有版本的 wheel 包
  3. 使用 auditwheel 修复过的 wheel 包中内置了 _psycopg2.so 所依赖的动态库,并自动注入维护了 RPATH 段,在依赖动态库的名称中注入了哈希字符串。这样既不需要设置 LD_LIBRARY_PATH 环境变量,也避免了和系统库重名的问题。
  4. 生成的是经过编译的 wheel 包,安装仅需 pip install <name.whl> 即可快速安装完成。

Tag summary

Content type

Image

Digest

sha256:8ff1b4901…

Size

760.7 MB

Last updated

about 3 years ago

docker pull vimiix/og_psycopg2_builder