From da5ab167ebc5765c91630846cd0850acd6ce8814 Mon Sep 17 00:00:00 2001
From: haozi007 <liuhao27@huawei.com>
Date: Thu, 26 Nov 2020 14:58:05 +0800
Subject: [PATCH 13/17] add ch docs for install iSulad

Signed-off-by: haozi007 <liuhao27@huawei.com>
---
 README.md              |   7 ++
 docs/build_guide.md    |  22 +++---
 docs/build_guide_zh.md | 164 +++++++++++++++++++++++++++++++++++++++++
 3 files changed, 182 insertions(+), 11 deletions(-)
 create mode 100644 docs/build_guide_zh.md

diff --git a/README.md b/README.md
index 9b34d615..1dd3cf1a 100644
--- a/README.md
+++ b/README.md
@@ -4,9 +4,16 @@
 
 `iSulad` is a lightweight container runtime daemon which is designed for IOT and Cloud infrastructure.`iSulad` has the characteristics of light, fast and not limited by hardware specifications and architecture, and can be applied more widely.
 
+## Documentation
+
+- [en build guide](./docs/build_guide.md)
+- [cn build guide](./docs/build_guide_zh.md)
+- [more usage guide](https://openeuler.org/zh/docs/20.09/docs/Container/iSula%E5%AE%B9%E5%99%A8%E5%BC%95%E6%93%8E.html)
+
 ## Getting Started
 
 ### Installing
+
 To install iSulad, you can use `rpm` or `yum` package manager command with `openEuler` repository.
 
 Or write repository file by hand:
diff --git a/docs/build_guide.md b/docs/build_guide.md
index 912139fa..2ee12c39 100644
--- a/docs/build_guide.md
+++ b/docs/build_guide.md
@@ -7,12 +7,12 @@ If you intend to contribute on iSulad. Thanks for your effort. Every contributio
 These dependencies are required for build:
 
 ### install basic dependencies based on Centos distribution
-```sh
+```bash
 $ sudo yum --enablerepo='*' install -y automake autoconf libtool cmake make libcap libcap-devel libselinux libselinux-devel libseccomp libseccomp-devel yajl-devel git libcgroup tar python3 python3-pip device-mapper-devel libarchive libarchive-devel libcurl-devel zlib-devel glibc-headers openssl-devel gcc gcc-c++ systemd-devel systemd-libs golang libtar libtar-devel
 ```
 
 ### install basic dependencies based on Ubuntu distribution
-```sh
+```bash
 $ sudo apt install -y libtool automake autoconf cmake make pkg-config libyajl-dev zlib1g-dev libselinux-dev libseccomp-dev libcap-dev libsystemd-dev git libcurl4-gnutls-dev openssl libdevmapper-dev golang python3 libtar libtar-dev
 ```
 
@@ -24,13 +24,13 @@ Please use the protobuf and grpc came with your distribution, if not exists then
 Note: grpc-1.22 can not support GCC 9+.
 
 ### set ldconfig and pkgconfig
-```
+```bash
 $ export PKG_CONFIG_PATH=/usr/local/lib/pkgconfig:$PKG_CONFIG_PATH
 $ export LD_LIBRARY_PATH=/usr/local/lib:/usr/lib:$LD_LIBRARY_PATH
 $ sudo -E echo "/usr/local/lib" >> /etc/ld.so.conf
 ```
 ### build and install protobuf
-```
+```bash
 $ git clone https://gitee.com/src-openeuler/protobuf.git
 $ cd protobuf
 $ git checkout openEuler-20.03-LTS-tag
@@ -44,7 +44,7 @@ $ sudo -E ldconfig
 ```
 
 ### build and install c-ares
-```
+```bash
 $ git clone https://gitee.com/src-openeuler/c-ares.git
 $ cd c-ares
 $ git checkout openEuler-20.03-LTS-tag
@@ -58,7 +58,7 @@ $ sudo -E ldconfig
 ```
 
 ### build and install grpc
-```
+```bash
 $ git clone https://gitee.com/src-openeuler/grpc.git
 $ cd grpc
 $ git checkout openEuler-20.03-LTS-tag
@@ -70,7 +70,7 @@ $ sudo -E ldconfig
 ```
 
 ### build and install http-parser
-```
+```bash
 $ git clone https://gitee.com/src-openeuler/http-parser.git
 $ cd http-parser
 $ git checkout openEuler-20.03-LTS-tag
@@ -82,7 +82,7 @@ $ sudo -E ldconfig
 ```
 
 ### build and install libwebsockets
-```
+```bash
 $ git clone https://gitee.com/src-openeuler/libwebsockets.git
 $ cd libwebsockets
 $ git checkout openEuler-20.03-LTS-tag
@@ -101,7 +101,7 @@ $ sudo -E ldconfig
 iSulad depend on some specific versions dependencies.
 
 ### build and install lxc
-```
+```bash
 $ git clone https://gitee.com/src-openeuler/lxc.git
 $ cd lxc
 $ tar -zxf lxc-4.0.3.tar.gz
@@ -114,7 +114,7 @@ $ sudo -E make install
 ```
 
 ### build and install lcr
-```
+```bash
 $ git clone https://gitee.com/openeuler/lcr.git
 $ cd lcr
 $ mkdir build
@@ -125,7 +125,7 @@ $ sudo -E make install
 ```
 
 ### build and install clibcni
-```
+```bash
 $ git clone https://gitee.com/openeuler/clibcni.git
 $ cd clibcni
 $ mkdir build
diff --git a/docs/build_guide_zh.md b/docs/build_guide_zh.md
new file mode 100644
index 00000000..182d6fec
--- /dev/null
+++ b/docs/build_guide_zh.md
@@ -0,0 +1,164 @@
+# 源码编译iSulad
+
+我们感谢为iSulad做的任何贡献。
+
+## 各发行版本的基本依赖安装
+
+这些依赖是编译依赖的基础组件：
+
+### openEuler的安装命令
+
+openEuler可以直接通过编译依赖自动安装的方式（其他rpm的发行版本也可以参考，但是存在部分包名不一致的情况），具体如下：
+
+```bash
+dnf builddep iSulad.spec
+```
+
+注：iSulad.spec直接用源码中的文件即可。
+
+### Centos的安装命令
+
+```bash
+$ sudo yum --enablerepo='*' install -y automake autoconf libtool cmake make libcap libcap-devel libselinux libselinux-devel libseccomp libseccomp-devel yajl-devel git libcgroup tar python3 python3-pip device-mapper-devel libarchive libarchive-devel libcurl-devel zlib-devel glibc-headers openssl-devel gcc gcc-c++ systemd-devel systemd-libs libtar libtar-devel
+```
+
+### Ubuntu的安装命令
+```bash
+$ sudo apt install -y libtool automake autoconf cmake make pkg-config libyajl-dev zlib1g-dev libselinux-dev libseccomp-dev libcap-dev libsystemd-dev git libcurl4-gnutls-dev openssl libdevmapper-dev python3 libtar libtar-dev
+```
+
+## 从源码构建和安装关键依赖
+下面的依赖组件，你的包管理中可能不存在，或者版本不满足要求。因此，需要从源码编译安装。protobuf和grpc建议直接通过包管理安装，除非没有或者版本太老。
+
+***注意：grpc-1.22不支持GCC 9+。***
+
+### 设置ldconfig和pkgconfig的路径
+
+编译安装的默认路径为`/usr/local/lib/`，因此需要把该路径添加到`PKG_CONFIG_PATH`和`LD_LIBRARY_PATH`，从而系统能找到我们编译安装的软件包和lib库。如果安装的`/usr/lib/`，可以忽略这一步。
+
+```bash
+$ export PKG_CONFIG_PATH=/usr/local/lib/pkgconfig:$PKG_CONFIG_PATH
+$ export LD_LIBRARY_PATH=/usr/local/lib:/usr/lib:$LD_LIBRARY_PATH
+$ sudo -E echo "/usr/local/lib" >> /etc/ld.so.conf
+```
+### 编译安装protobuf
+```bash
+$ git clone https://gitee.com/src-openeuler/protobuf.git
+$ cd protobuf
+$ git checkout openEuler-20.03-LTS-tag
+$ tar -xzvf protobuf-all-3.9.0.tar.gz
+$ cd protobuf-3.9.0
+$ sudo -E ./autogen.sh
+$ sudo -E ./configure
+$ sudo -E make -j $(nproc)
+$ sudo -E make install
+$ sudo -E ldconfig
+```
+
+### 编译安装c-ares
+```bash
+$ git clone https://gitee.com/src-openeuler/c-ares.git
+$ cd c-ares
+$ git checkout openEuler-20.03-LTS-tag
+$ tar -xzvf c-ares-1.15.0.tar.gz
+$ cd c-ares-1.15.0
+$ sudo -E autoreconf -if
+$ sudo -E ./configure --enable-shared --disable-dependency-tracking
+$ sudo -E make -j $(nproc)
+$ sudo -E make install
+$ sudo -E ldconfig
+```
+
+### 编译安装grpc
+```bash
+$ git clone https://gitee.com/src-openeuler/grpc.git
+$ cd grpc
+$ git checkout openEuler-20.03-LTS-tag
+$ tar -xzvf grpc-1.22.0.tar.gz
+$ cd grpc-1.22.0
+$ sudo -E make -j $(nproc)
+$ sudo -E make install
+$ sudo -E ldconfig
+```
+
+### 编译安装http-parser
+```bash
+$ git clone https://gitee.com/src-openeuler/http-parser.git
+$ cd http-parser
+$ git checkout openEuler-20.03-LTS-tag
+$ tar -xzvf http-parser-2.9.2.tar.gz
+$ cd http-parser-2.9.2
+$ sudo -E make -j CFLAGS="-Wno-error"
+$ sudo -E make CFLAGS="-Wno-error" install
+$ sudo -E ldconfig
+```
+
+### 编译安装libwebsockets
+```bash
+$ git clone https://gitee.com/src-openeuler/libwebsockets.git
+$ cd libwebsockets
+$ git checkout openEuler-20.03-LTS-tag
+$ tar -xzvf libwebsockets-2.4.2.tar.gz
+$ cd libwebsockets-2.4.2
+$ patch -p1 -F1 -s < ../libwebsockets-fix-coredump.patch
+$ mkdir build
+$ cd build
+$ sudo -E cmake -DLWS_WITH_SSL=0 -DLWS_MAX_SMP=32 -DCMAKE_BUILD_TYPE=Debug ../
+$ sudo -E make -j $(nproc)
+$ sudo -E make install
+$ sudo -E ldconfig
+```
+
+## 编译安装特定依赖版本
+iSulad依赖一些特定版本的组件，由于各组件是通过函数接口使用，因此，**必须保证各组件版本一致**。例如：
+
+- 统一使用各组件的master分支的代码进行构建；
+- 后续的releases版本会增加依赖的组件的版本号；
+- 也统一可以从[openEuler](https://openeuler.org/zh/download/)的特定OS版本，通过包管理工具获取各组件的`src.rpm`包的方式获取源码；
+- 也可以到[src-openeuler](https://gitee.com/src-openeuler)社区获取各组件相同分支的代码；
+
+### 编译安装lxc
+```bash
+$ git clone https://gitee.com/src-openeuler/lxc.git
+$ cd lxc
+$ tar -zxf lxc-4.0.3.tar.gz
+$ ./apply-patches
+$ cd lxc-4.0.3
+$ sudo -E ./autogen.sh
+$ sudo -E ./configure
+$ sudo -E make -j $(nproc)
+$ sudo -E make install
+```
+
+### 编译安装lcr
+```bash
+$ git clone https://gitee.com/openeuler/lcr.git
+$ cd lcr
+$ mkdir build
+$ cd build
+$ sudo -E cmake ..
+$ sudo -E make -j $(nproc)
+$ sudo -E make install
+```
+
+### 编译安装clibcni
+```bash
+$ git clone https://gitee.com/openeuler/clibcni.git
+$ cd clibcni
+$ mkdir build
+$ cd build
+$ sudo -E cmake ..
+$ sudo -E make -j $(nproc)
+$ sudo -E make install
+```
+
+### 编译安装iSulad
+```bash
+$ git clone https://gitee.com/openeuler/iSulad.git
+$ cd iSulad
+$ mkdir build
+$ cd build
+$ sudo -E cmake ..
+$ sudo -E make -j $(nproc)
+$ sudo -E make install
+```
-- 
2.25.1

