使用私有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功能非常完善,只需要简单几步,就可以完成项 ...
随机推荐
- Codeforces Round #722 (Div. 2) A~D题解
补题链接:Here 1529A. Eshag Loves Big Arrays [题意描述] 给定一个长度为 \(n\) 的正整数数组 \(a\) ,现在可执行若干次操作(可为 \(0\)) 具体操作 ...
- 推荐收藏!年度Top20开源许可证风险等级
开源许可现状 开发人员经常在软件中引入开源的代码片段.函数.方法和操作代码.因此,软件代码中经常会包含各种声明不同许可证的子组件.这些子组件的许可证条款和条件与项目整体主许可证的条款和条件冲突时,就会 ...
- 广州|阿里云 Serverless 技术实战营邀你来玩!
活动简介 "Serverless 技术实战与创新沙龙 " 是一场以 Serverless 为主题的开发者活动,活动受众以关注Serverless 技术的开发者.企业决策人.云原生领 ...
- 3 分钟创建 Serverless Job 定时获取新闻热搜
不用掏手机,不用登微博,借助 SAE 定时任务就可以实现每小时获取实时新闻热搜!SAE 场景体验火热开启中,参与还可领好礼! Job 作为一种运完即停的负载类型,在企业级开发中承载着丰富的使用场景.S ...
- 13、SpringBoot-配置文件里密码加密
系列导航 springBoot项目打jar包 1.springboot工程新建(单模块) 2.springboot创建多模块工程 3.springboot连接数据库 4.SpringBoot连接数据库 ...
- pmp考试巩固知识点
1.冲刺评审会是需要相关的干系人参加的,在冲刺评审会上干系人可以审查并澄清角色.责任和管理模式2.采购中的争议,往往找合同和SOW,SOW是对需要采购的详细范围的描述,与供应商在可交付成果方面有争议时 ...
- Redis 哨兵模式高可用
本文为博主原创,未经允许不得转载: 目录: 1. 哨兵 Sentinel 介绍 2. 哨兵架构特点及工作原理 3. redis哨兵架构搭建步骤 4. 哨兵数据丢失 5. spring boot 整合 ...
- C++中不支持strdup(),使用_strdup()
1.问题 C4996 'strdup': The POSIX name for this item is deprecated. Instead, use the ISO C and C++ conf ...
- 【TouchGFX】Callback
回调函数模板定义 单参数回调函数模板 实现回调函数接口: 实现合法性检查接口: 实现执行接口: 按键触发回调实现 定义回调数据结构对象 使用回调数据结构构造函数 执行接口实现 整个切换机制的管理主体对 ...
- [转帖]一文读懂 | 如何快速部署 OceanBase 开源版
2021-11-281398 版权 本文涉及的产品 云数据库 RDS MySQL Serverless,0.5-2RCU 50GB 推荐场景: 学生管理系统数据库设计搭建个人博客 立即试用 云防火墙, ...