使用私有gitlab搭建gitbook持续集成
在项目实践中,团队需要对用到的知识技术进行总结,即便于分享,也利于传承,而gitbook就是个不错的选择,使用gitbook-cli 对Markdown文档进行编译,生成静态文件,再通过web服务器(e.g. nginx)对外提供服务。
gitbook和gitlab搭建持续集成,可实现文档的即时更新,这也是我在DevOps实践的一部分。

环境搭建
1. 安装 Node.js
gitbook 是一个基于 Node.js 的命令行工具,下载安装 Node.js,安装完成之后,你可以使用下面的命令来检验是否安装成功。
$ node -v
2. 安装 gitbook
输入下面的命令来安装 gitbook
npm install gitbook-cli -g
安装完成之后,你可以使用下面的命令来检验是否安装成功
$ gitbook -V
更多详情请参照 gitbook 安装文档 来安装 gitbook
3. 安装 Gitlab Runner
下载二进制包
sudo curl -L --output /usr/local/bin/gitlab-runner https://gitlab-runner-downloads.s3.amazonaws.com/latest/binaries/gitlab-runner-linux-amd64
添加执行权限
sudo chmod +x /usr/local/bin/gitlab-runner
(可选)如果使用Docker,安装Docker
curl -sSL https://get.docker.com/ | sh
创建 GitLab CI 用户
sudo useradd --comment 'GitLab Runner' --create-home gitlab-runner --shell /bin/bash
以Service方式安装
sudo gitlab-runner install --user=gitlab-runner --working-directory=/home/gitlab-runner
sudo gitlab-runner start
4. 注册Runner
运行以下命令
sudo gitlab-runner register
输入GitLab 实例 URL Please enter the gitlab-ci coordinator URL
输入Gitlab注册的token (Gitlab admin权限才能看见)
Please enter the gitlab-ci token for this runner xxx
输入Runner描述,后面可在Gitlab UI上更新
Please enter the gitlab-ci description for this runner
输入Runner Tag,后面可在Gitlab UI上更新
Please enter the gitlab-ci tags for this runner (comma separated):
选择Runner executor
Please enter the executor: ssh, docker+machine, docker-ssh+machine, kubernetes, docker, parallels, virtualbox, docker-ssh, shell: shell
gitbook 配置
1. 目录结构
.
├── book.json
├── README.md
├── SUMMARY.md
├── chapter-1/
| ├── README.md
| └── something.md
└── chapter-2/
├── README.md
└── something.md
README.md
gitbook第一页内容是从文件 README.md 中提取的。如果这个文件名没有出现在 SUMMARY 中,那么它会被添加为章节的第一个条目book.json
该文件主要用来存放配置信息.bookignore
将读取.gitignore,.bookignore以及.ignore文件以获得文件和文件夹跳过列表Glossary.md
允许指定要显示为注释的术语及其各自的定义。根据这些条款,GitBook将自动构建一个索引并突出显示这些术语SUMMARY.md
用于存放GitBook的文件目录信息,左侧的目录就是根据这个文件来生成的,默认对应的文件是 SUMMARY.md,可以在 book.json 重新定义该文件的对应值。它通过Markdown中的列表语法来表示文件的父子关系注意 不被SUMMARY.md包含的文件不会被gitbook处理
SUMMARY.md示例:
# Summary * [Introduction](README.md)
* [Part I](part1/README.md)
* [Writing is nice](part1/writing.md)
* [gitbook is nice](part1/gitbook.md)
* [Part II](part2/README.md)
* [We love feedback](part2/feedback_please.md)
* [Better tools for authors](part2/better_tools.md)
通过使用 标题 或者 水平分割线 将 gitbook 分为几个不同的部分,如下所示:
# Summary ### Part I * [Introduction](README.md)
* [Writing is nice](part1/writing.md)
* [gitbook is nice](part1/gitbook.md) ### Part II * [We love feedback](part2/feedback_please.md)
* [Better tools for authors](part2/better_tools.md) --- * [Last part without title](part3/title.md)
目录中的章节可以使用锚点指向文件的特定部分
# Summary ### Part I * [Part I](part1/README.md)
* [Writing is nice](part1/README.md#writing)
* [gitbook is nice](part1/README.md#gitbook)
* [Part II](part2/README.md)
* [We love feedback](part2/README.md#feedback)
* [Better tools for authors](part2/README.md#tools)
2. 命令行
gitbook init
gitbook项目初始化,会自动生成两个必要的文件 README.md 和 SUMMARY.md
gitbook build [path]
构建gitbook项目生成静态网页,会生成一个 _book 文件夹(包含了 .md 对应的.html文件)
gitbook serve
该命令实际上会首先调用 gitbook build 编译 .md,完成以后会打开一个web服务器,监听在本地的4000端口。
生产的静态文件可单独放到tomcat或者nginx供静态访问
./
├── _book
│ ├── gitbook
│ │ ├── fonts
│ │ ├── gitbook.js
│ │ ├── gitbook-plugin-fontsettings
│ │ ├── gitbook-plugin-highlight
│ │ ├── gitbook-plugin-livereload
│ │ ├── gitbook-plugin-lunr
│ │ ├── gitbook-plugin-search
│ │ ├── gitbook-plugin-sharing
│ │ ├── images
│ ├── index.html
│ └── search_index.json
├── README.md
└── SUMMARY.md
gitbook update #更新gitbook到最新版本
gitbook install #安装依赖
gitbook builid --debug #输出错误信息
gitbook build --log=debug #指定log级别
3. 插件
gitbook 提供了丰富插件,默认带有 5 个插件,highlight、search、sharing、font-settings、livereload,如果要去除自带的插件, 可以在插件名称前面加 -,比如:
"plugins": [
"-search"
]
插件使用参考
gitlab 与gitbook集成
.gitlab-ci.yml 示例:
# requiring the environment of NodeJS 10
image: node:10
# add 'node_modules' to cache for speeding up builds
cache:
paths:
- node_modules/ # Node modules and dependencies
before_script:
- npm install gitbook-cli -g # install gitbook
- gitbook fetch 3.2.3 # fetch final stable version
- gitbook install # add any requested plugins in book.json
test:
stage: test
script:
- gitbook build . public # build to public path
only:
- branches # this job will affect every branch except 'master'
except:
- master
# the 'pages' job will deploy and build your site to the 'public' path
pages:
stage: deploy
script:
- gitbook build . public # build to public path
artifacts:
paths:
- public
expire_in: 1 week
only:
- master # this job will affect only the 'master' branch
参考

使用私有gitlab搭建gitbook持续集成的更多相关文章
- 用 GitLab CI 进行持续集成
简介 从 GitLab 8.0 开始,GitLab CI 就已经集成在 GitLab 中,我们只要在项目中添加一个 .gitlab-ci.yml 文件,然后添加一个 Runner,即可进行持续集成. ...
- 【补充】Gitlab 部署 CI 持续集成
上一篇:<劈荆斩棘:Gitlab 部署 CI 持续集成> 上一篇所配置的.gitlab-ci.yml: stages: - build - test before_script: - ec ...
- 使用VSTS/TFS搭建iOS持续集成环境
TFS 自2015版开始支持跨平台的持续集成环境,通过提供开源的build agent为 Windows / linux / macOS 提供了统一的持续集成环境管理能力.这篇文章给大家介绍一下如何使 ...
- Gitlab Jenkins WebHook 持续集成配置踩坑记
Jenkins相关介绍 Jenkins是一个开源软件项目,是基于Java开发的一种持续集成工具,用于监控持续重复的工作,旨在提供一个开放易用的软件平台,使软件的持续集成变成可能. 目的 配置Gitla ...
- 使用Jenkins+Calabash+Cocoapods搭建iOS持续集成环境
使用jenkins+calabash+cocoapods搭建ios持续集成环境 持续集成 持续集成到底是什么呢?依据敏捷大师Martin Fowler的定义: 持续集成是一种软件开发实践. 在持续集成 ...
- Jenkins+MSbuild+SVN实现快速搭建.net持续集成环境(构建、编辑、部署到服务器)
Jenkins是一个可扩展的持续集成引擎,Jenkins非常易于安装和配置,简单易用,下面开始搭建.net持续集成环境 Jenkins和SVN安装这里就不介绍了 一.准备工作 1.Jenkins中系统 ...
- 劈荆斩棘:Gitlab 部署 CI 持续集成
阅读目录: install configue gitlab-ci-multi-runner restore nuget packages bulid .sln run unit tests confi ...
- gitlab+gerrit+jenkins持续集成框架
1.持续集成之gitlab+gerrit+jenkins 1.1. GitLab 1.1.1. 简介 GitLab 是一个使用使用Ruby on Rails搭建的,用于仓库管理系统的开源项目.使用Gi ...
- 物联网架构成长之路(47)-利用GitLab实现CI持续集成
0.前言 前段时间,考虑到要练习部署一套CI/CD的系统.一开始考虑到Jenkins,随着这两天的了解,发现最新版的GitLab已经提供有CI/CD集成了.所以本次博客,干脆一步到位,直接用GitLa ...
- GitLab CI/CD持续集成设置
GitLab CI/CD持续设置 官方文档地址(https://docs.gitlab.com/ee/ci/README.html) GitLab CI.CD功能非常完善,只需要简单几步,就可以完成项 ...
随机推荐
- VIM 入门手册, (VS Code)
要想在VScode里使用Vim需要先行按照插件 安装 vim 插件 VS Code 中输入快捷键 shift + ctrl + x, 或直接打开 扩展安装导航 搜索 vim, 选择 Vim , 点击 ...
- 基于 eBPF 的 Serverless 多语言应用监控能力建设
作者:竞霄 监控能力作为基础运维能力和核心稳定性措施,开发运维人员可以通过监控系统有效进行故障定位,预防潜在风险,分析长期趋势进行容量规划和性能调优,是软件开发生命周期中必不可少的一环.与此同时,Se ...
- centos7使用nginx+uwsgi部署python django项目
在django框架中,我们一般直接通过python manage.py runserver来启动提供服务,但是如果生产环境此方法不可行,而且容易导致异常退出,于是需要借助uwsgi来作为守护进程. 操 ...
- 带你熟悉NLP预训练模型:BERT
本文分享自华为云社区<[昇思技术公开课笔记-大模型]Bert理论知识>,作者: JeffDing. NLP中的预训练模型 语言模型演变经历的几个阶段 word2vec/Glove将离散的文 ...
- 解决python报错:ModuleNotFoundError: No module named '_sysconfigdata_x86_64_conda_linux_gnu'
技术背景 在上一篇博客中执行过conda的更新以及用conda安装了gxx_linux-64之后,再执行pip的一些指令时,就会给出如下所示的报错: $ python3 -m pip list Tra ...
- 【收集】Tool
序 链接 备注 1 WinMerge - You will see the difference- 开源windows比对工具 2 AykutSarac/jsoncrack.com: Seamless ...
- VIte+Vue3 打包在本地 双击 index.html 打开项目
npm i @vitejs/plugin-legacy --save import legacy from '@vitejs/plugin-legacy'; export default define ...
- linux-网络状态-netstat
- linux-帮助-man和help
- [转帖]NET Framework 版本和依赖关系
https://learn.microsoft.com/zh-cn/dotnet/framework/migration-guide/versions-and-dependencies 每个版本的 . ...