使用私有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功能非常完善,只需要简单几步,就可以完成项 ...
随机推荐
- 2018年蓝桥杯B组C/C++国赛题解
1.换零钞 x星球的钞票的面额只有:100元,5元,2元,1元,共4种. 小明去x星旅游,他手里只有2张100元的x星币,太不方便,恰好路过x星银行就去换零钱. 小明有点强迫症,他坚持要求200元换出 ...
- 浏览器,navicat,IDEA--快捷键
mysql快捷键:ctrl+r 运行查询窗口的sql语句ctrl+shift+r 只运行选中的sql语句ctrl+q 打开一个新的查询窗口ctrl+w 关闭一个查询窗口ctrl+/ 注释sql语句 c ...
- 即学即会 Serverless | 如何解决 Serverless 应用开发部署的难题?
本文节选自<Serverless 开发速查手册>,关注Serverless 公众回复 手册 即可获得下载链接 作者 | 江昱(阿里云 Serverless 产品经理) 破局:工具链体系匮乏 ...
- vue <a>标签 href 是参数的情况下如何使用
想在页面中使用a标签打开一个新页面进行跳转 例如:msgZi.blogAddress 的值是 https://www.baidu.com 正确的写法: <a :href="goBlog ...
- 电脑面试两道问题(python+shell)
最近面试电脑代码面试遇到两个问题,供大家参考一下一.python脚本: 手写一个函数,实现两个数相加,并使用unittest与pytest工具测试函数正确性. 1.unnitest进行测试: impo ...
- KVM 核心功能:内存虚拟化
1 内存虚拟化简介 QEMU-KVM 提供内存的虚拟化,从虚拟机角度看其自身拥有的内存就是真实的物理内存.实际上,虚拟机是 host 上的一个 qemu 进程,在为虚拟机指定内存时,host 上并没有 ...
- 例2.9 建立一个带头结点的线性链表,用以存放输人的二进制数,链表中每个结点的data域存放一个二进制位。并在此链表上实现对二进制数加1的运算。
1.题目 例2.9建立一个带头结点的线性链表,用以存放输人的二进制数,链表中每个结点的data域存放一个二进制位.并在此链表上实现对二进制数加1的运算. 2.算法分析 3.代码 /* 二进制加1 */ ...
- [转帖]一文读懂 | 如何快速部署 OceanBase 开源版
2021-11-281398 版权 本文涉及的产品 云数据库 RDS MySQL Serverless,0.5-2RCU 50GB 推荐场景: 学生管理系统数据库设计搭建个人博客 立即试用 云防火墙, ...
- [转帖]一文浅析Nginx线程池!
https://zhuanlan.zhihu.com/p/616500765 Nginx通过使用多路复用IO(如Linux的epoll.FreeBSD的kqueue等)技术很好的解决了c10k ...
- [转帖]引人入胜,实战讲解“Java性能调优六大工具”之linux命令行工具
Java性能调优六大工具之Linux命令行工具 为了能准确获得程序的性能信息,需要使用各种辅助工具.本章将着重介绍用于系统性能分析的各种工具.熟练掌握这些工具,对性能瓶颈定位和系统故障排查都很有帮助. ...