当前位置: 首页 > backend >正文

使用docker编译onlyoffice server 8.2.2 成功版 含踩坑记录

前言:

为方便学习研究onlyoffice,熟悉onlyoffice内部原理和逻辑。添加定制化配置和优化层次结构。在本地环境进行打包编译。最开始因为不熟悉打包的命令和过程,走了不少弯路。尝试了多种不同的组合。如:build_tools最新9.0+组件最新9.0+ubuntu-20.04 build_tools-7.1.1.16+组件最新9.0+ubuntu-16.04 build_tools-8.2.2.34+组件最新9.0+ubuntu-16.04 build_tools-8.2.2.34+组件8.2.2.34+ubuntu-16.04 (成功)。其他的组合也有可能成功,但是如果对内部原理研究不深就很容易失败。

本机环境:

windows 10 专业版
docker-desktop版本:4.30.0 (149282)
docker 版本:26.1.1

前期准备:

  • 足够的磁盘空间,因为使用docker容器进行编译,导致最开始把C盘撑爆了,又花时间从C盘中迁移出来。所以至少准备50G的磁盘空间。迁移的方案参见:https://zhutong.blog.csdn.net/article/details/148801508
  • 科学上网。至少准备30G流量,我先后测试了多个版本和多种失败的方式总共消耗了200G左右。前期规划准备好,避免出现流量不够导致包下载失败。因为有的组件的make方法执行失败后,再次执行时该组件前期下载的包会重复下载,导致浪费流量。
  • onlyoffice编译工具是build_tools,github地址为 https://github.com/ONLYOFFICE/build_tools。需要注意的是这玩意有时效性,build_tools只是一个打包工具,打包所需要的组件,如core、server等是通过git在线下载的,这就导致一个问题就是打包工具的版本有一定的概率是和当前代码的匹配度是不够的,引发各种各样的问题。最开始的时候没有看打包的源码,以为按照官网的操作步骤肯定是没错的,结果每次都拉最新的代码,导致出错的原因每次还都不一样,非常崩溃。
  • 为解决上面的问题,这边最终成功的版本是8.2.2,小版本是8.2.2.34,也是8.2.2的最后一个标签。相对应的组件也是相同的版本。以下是打包server所需的组件:{‘core’: [False, False], ‘sdkjs’: [False, False], ‘onlyoffice.github.io’: [False, False], ‘web-apps’: [False, False], ‘dictionaries’: [False, False], ‘core-fonts’: [False, False], ‘server’: [False, False], ‘document-server-integration’: [False, False], ‘document-templates’: [False, False]},在执行打包命令之前需要从github上将包提前下载到本地,并放在操作系统的根目录下。

操作步骤

构建打包的环境,使用docker创建Ubuntu的系统环境。build_tools下载8.2.2.34版本的源码到本地。
直接在源码的Dockerfile文件中修改为:也可根据需要进行添加

FROM ubuntu:16.04
ENV TZ=Etc/UTC
RUN ln -snf /usr/share/zoneinfo/$TZ /etc/localtime && echo $TZ > /etc/timezone
RUN apt-get -y update && \apt-get -y install python \python3 \sudo
RUN rm /usr/bin/python && ln -s /usr/bin/python2 /usr/bin/python
ADD . /build_tools
WORKDIR /build_tools
CMD cd tools/linux && \python3 ./automate.py server

执行docker build命令打包为镜像。

docker build --network host -t onlyoffice-build ./

运行docker容器:

docker run -dit --net host --name onlyoffice16 onlyoffice-build:latest bash

到这一步前期的环境已经准备好了,一般不会出错。注意不要配置 --restart
接下来进入容器中进行打包。

docker exec -it onlyoffice16 bash

进入容器默认的路径是/build_tools,切换至上一层目录,下载相关组件。

git clone --branch v8.2.2.34 https://github.com/ONLYOFFICE/core.git
git clone --branch v8.2.2.34 https://github.com/ONLYOFFICE/sdkjs.git
git clone https://github.com/ONLYOFFICE/onlyoffice.github.io.git
git clone --branch v8.2.2.34 https://github.com/ONLYOFFICE/web-apps.git
git clone --branch v8.2.2.34 https://github.com/ONLYOFFICE/dictionaries.git
git clone --branch v8.2.2.34 https://github.com/ONLYOFFICE/core-fonts.git
git clone --branch v8.2.2.34 https://github.com/ONLYOFFICE/server.git
git clone --branch v8.2.2.34 https://github.com/ONLYOFFICE/document-server-integration.git
git clone --branch v8.2.2.34 https://github.com/ONLYOFFICE/document-templates.git

然后进入到/build_tools/tools/linux/目录,执行

python3 ./autometa.py server --update=0

不要用这个命令代替python3 automate.py server --branch=v8.2.2.34。不好用。
解释一下:build_tools支持打包多种类型的产品,如desktop、server等,不加server默认是全部,此处只打包server。
update=0的意思是不拉取最新的组件代码。使用本地已有的组件代码。configure.py文件中有每个参数的解释。
此处不需要额外的参数配置。
顺利的话几个小时就会出现下面的日志,表示打包已经成功。并在/build_tools文件夹下生成out目录。

  % Total    % Received % Xferd  Average Speed   Time    Time     Time  CurrentDload  Upload   Total   Spent    Left  Speed
100 11045  100 11045    0     0   8322      0  0:00:01  0:00:01 --:--:--  8323% Total    % Received % Xferd  Average Speed   Time    Time     Time  CurrentDload  Upload   Total   Spent    Left  Speed
100 22832  100 22832    0     0  20999      0  0:00:01  0:00:01 --:--:-- 21004% Total    % Received % Xferd  Average Speed   Time    Time     Time  CurrentDload  Upload   Total   Spent    Left  Speed
100 16631  100 16631    0     0  14651      0  0:00:01  0:00:01 --:--:-- 14652% Total    % Received % Xferd  Average Speed   Time    Time     Time  CurrentDload  Upload   Total   Spent    Left  Speed
100 11045  100 11045    0     0  12467      0 --:--:-- --:--:-- --:--:-- 12466% Total    % Received % Xferd  Average Speed   Time    Time     Time  CurrentDload  Upload   Total   Spent    Left  Speed
100 22832  100 22832    0     0  22974      0 --:--:-- --:--:-- --:--:-- 22969% Total    % Received % Xferd  Average Speed   Time    Time     Time  CurrentDload  Upload   Total   Spent    Left  Speed
100 16631  100 16631    0     0  17998      0 --:--:-- --:--:-- --:--:-- 17998
delete warning [file not exist]: /build_tools/scripts/../out/linux_64/onlyoffice/documentserver-snap/var/www/onlyoffice/documentserver/example/nodejs/example

遇到的问题:

core、server等组件源码拉取最新代码的时:

  • HEAD is now at be6df45 [|attr] crash && memory leak Traceback (most
    recent call last): File “/core/Common/3dParty/html/fetch.py”, line
    23, in base.replaceInFileUtf8(base_directory +
    “/katana-parser/src/tokenizer.c”, “static inline bool
    katana_is_html_space(char c);”, “static inline bool2
    katana_is_html_space(char c);”) AttributeError: module ‘base’ has no
    attribute ‘replaceInFileUtf8’. Did you mean: ‘replaceInFile’?

重新执行 python3 ./automate.py server 后报其他错误。

  • [fetch & build]: harfbuzz Traceback (most recent call last): File
    “/core/Common/3dParty/harfbuzz/./make.py”, line 30, in
    base.check_module_version(“1”, clear_module) AttributeError: module ‘base’ has no attribute ‘check_module_version’. Did you mean:
    ‘check_build_version’?
    原因是make.py直接读取build_tools文件夹[sys.path.append(“…/…/…/…/build_tools/scripts”)],为了测试多个版本的build_tools,我的文件夹名称是build_tools-8.2.2.34,修改回原始名称后解决。
    In file included from
    …/…/boost/build/linux_64/include/boost/shared_ptr.hpp:17:0,
    from …/…/…/…/OfficeCryptReader/source/CryptTransform.h:37,
    from …/…/…/…/OfficeCryptReader/source/ECMACryptFile.cpp:34:
    …/…/boost/build/linux_64/include/boost/smart_ptr/shared_ptr.hpp:17:65:
    fatal error: boost/config.hpp: No such file or directory compilation
    terminated.
    /core/Common/3dParty/cryptopp/project/Makefile.linux_64:6982: recipe
    for target
    ‘core_build/linux_64/release/obj/core/OfficeCryptReader/source/ECMACryptFile.o’
    failed make: ***
    [core_build/linux_64/release/obj/core/OfficeCryptReader/source/ECMACryptFile.o]
    Error 1 make: *** Waiting for unfinished jobs… Error (make): 2
    Error (./make.py): 1

解决方案:删除/core/Common/3dParty/boost/build文件夹后,重新执行python3 ./automate.py server

  • make: *** No rule to make target ‘/core/Common/3dParty/md/md4c/src/md4c.c’, needed by ‘core_build/linux_64/release/obj/core/Common/3dParty/md/md4c/src/md4c.o’. Stop.
    make: *** Waiting for unfinished jobs…
    Error (make): 2
    Error (./make.py): 1

原因未找到,失败。将源码切换至8.2.2.34后解决。

  • depot_tools/ninja.py: Could not find Ninja in the third_party of the current project, nor in your PATH.
    Please take one of the following actions to install Ninja:
  • If your project has DEPS, add a CIPD Ninja dependency to DEPS.
  • Otherwise, add Ninja to your PATH after depot_tools.
    Error (ninja): 1

执行 root@docker-desktop:/build_tools/tools/linux# apt install ninja-build,报新的错误

  • ninja: Entering directory `out.gn/linux_64’ ninja: fatal: ninja
    version (1.5.1) incompatible with build file ninja_required_version
    version (1.7.2). Error (ninja): 1 Error (./make.py): 1
    原因是操作系统自带的ninja-build版本太低,无法满足编译的需求,手动升级ninja-build。
    解决方案:
git clone https://github.com/ninja-build/ninja /tmp/ninja 
cd /tmp/ninja 
git checkout v1.8.2 
./configure.py --bootstrap 
sudo mv ninja /usr/bin/ninja 
rm -rf /tmp/ninja
  • install qt…
    tar: This does not look like a tar archive
    xz: (stdin): File format not recognized
    tar: Child returned status 1
    tar: Error is not recoverable: exiting now
    Error (tar): 2
    原因:下载qt失败。

解决方案:
下载:https://download.qt.io/new_archive/qt/5.9/5.9.9/single/qt-everywhere-opensource-src-5.9.9.tar.xz
docker cp qt-everywhere-opensource-src-5.9.9.tar.xz onlyoffice8src:/build_tools/tools/linux/
mv qt-everywhere-opensource-src-5.9.9.tar.xz qt_source_5.9.9.tar.xz

  • [fetch & build]: icu svn: E170013: Unable to connect to a repository
    at URL ‘https://github.com/unicode-org/icu/tags/release-58-2/icu4c’
    svn: E160013: ‘/unicode-org/icu/tags/release-58-2/icu4c’ path not
    found Error (svn): 1 Error (./make.py): 1

解决方案:
到https://github.com/unicode-org/icu/tree/release-58-2下载源码:icu-release-58-2.zip
解压后将icu4c目录拷贝到:/home/onlyoffice/core/Common/3dParty/icu目录下,并且更名为icu目录
注意:不要使用git clone --branch release-58-2 https://github.com/unicode-org/icu.git 下载了3G多

  • SyntaxError: invalid syntax Error: Command
    ‘download_from_google_storage --no_resume --platform=win32 --no_auth
    –bucket chromium-clang-format -s v8/buildtools/win/clang-format.exe.sha1’ returned non-zero exit
    status 1 in /core/Common/3dParty/v8 File
    “/build_tools/scripts/…/…/core/Common/3dParty/v8/depot_tools/download_from_google_storage.py”,
    line 50
    return f’.{gcs_file_name}{MIGRATION_TOGGLE_FILE_SUFFIX}’
    ^ SyntaxError: invalid syntax

原因:这个方法不支持,至少python版本在3.6以上才支持,build_tools-7.1.1.76带的python版本是Python 3.5.2。官方在其他版本中修复:https://github.com/ONLYOFFICE/build_tools/issues/807
注意事项:

  1. 最好使用docker镜像进行打包,这样可以保证操作系统的纯净,减少外部环境的影响。
  2. server中常量的文件是:/server/Common/sources/constants.js。
  3. 多看build_tools源码对打包有帮助。可以在指定的位置局部执行,节省时间。
  4. 执行打包命令使用python3而不是python,结果差异很大。
http://www.xdnf.cn/news/14747.html

相关文章:

  • C++ STL深度剖析:Stack、queue、deque容器适配器核心接口
  • FDA IND审评流程及临床研究暂停要点
  • Ubuntu20.04离线安装Realtek b852无线网卡驱动
  • Java基础(Maven配置)
  • Vue工程化实现约定式路由自动注册
  • 汇总表支持表头分组,查询组件查询框可以调整高度,DataEase开源BI工具v2.10.11 LTS版本发布
  • Linux基本指令篇 —— tac指令
  • 基于JavaWeb的校园失物招领系统设计与实现
  • C++11 <chrono> 库特性:从入门到精通
  • 在shell中直接调用使用R
  • Spring Boot整合Redis指南
  • 强化学习理论基础:从Q-learning到PPO的算法演进(2)
  • RabbitMQ RPC模式Python示例
  • go写前端打包的自动化工具
  • oracle内存参数调整
  • 【Redis】解码Redis中的list类型,基本命令,内部编码方式以及适用的场景
  • 流程管理系统技术选型避坑指南(含开源)
  • 优化 ArcPy 脚本性能
  • Jmeter并发测试和持续性压测
  • AI+实时计算如何赋能金融系统?DolphinDB 在国泰君安期货年度中期策略会的演讲
  • 鸿蒙版FlutterSDK3.27.4可以使用了
  • 报道称CoreWeave洽谈收购Core Scientific,后者涨超30%
  • 人工智能-基础篇-2-什么是机器学习?(ML,监督学习,半监督学习,零监督学习,强化学习,深度学习,机器学习步骤等)
  • 报表控件stimulsoft教程:在报表、仪表板和 PDF 表单自动生成缩略图
  • 华为云鸿蒙应用入门级开发者认证 实验(HCCDA-HarmonyOS Cloud Apps)
  • 【缓存技术】深入分析如果使用好缓存及注意事项
  • C++(模板与容器)
  • python中学物理实验模拟:斜面受力分析
  • 苍穹外卖day3--公共字段填充+新增菜品
  • python基于协同过滤的动漫推荐系统