Gitbook + Jenkins + Gitlab 搭建内网自动构建的 Gitbook

栏目: Java · 发布时间: 5年前

内容简介:最近在本地搭建了一个 Gitbook ,用于内网访问。总结一下简单流程形成此文,细节设置可以参考官网。推荐安装 openjdk-7-jre 和 openjdk-7-jdk ,但是其在 Ubuntu 16.04 和更高版本不再有效,可以安装 Java 8 或者 9 代替。Jenkins 更新比较快,如若过期,可以按如下命令更新。

最近在本地搭建了一个 Gitbook ,用于内网访问。总结一下简单流程形成此文,细节设置可以参考官网。

Gitbook

Install Git

sudo apt install git

Install Node.js

sudo apt install Node.js

Install npm

sudo apt install npm

Install gitbook

npm install gitbook-cli -g
gitbook -V

Test gitbook server-web

mkdir server
cd server
gitbook init
gitbook build .
gitbook serve .

Gitlab

Install and configure the necessary dependencies

sudo apt-get update
sudo apt-get install -y curl openssh-server ca-certificates

Install Postfix to send notification emails.

sudo apt-get install -y postfix

Add the GitLab package repository and install .

curl https://packages.gitlab.com/install/repositories/gitlab/gitlab-ee/script.deb.sh | sudo bash
sudo EXTERNAL_URL="https://gitlab.example.com" apt-get install gitlab-ee

Config gitlab

sudo mkdir -p /etc/gitlab
sudo touch /etc/gitlab/gitlab.rb
sudo chmod 600 /etc/gitlab/gitlab.rb
sudo vim /etc/gitlab/gitlab.rb
# external_url 'http://164.69.136.23' , config as local ip or url.
# Modification is suggested. If '502 GitLab is not responding...' error exists, modify 'unicorn['port']' in gitlab.rb. 

sudo gitlab-ctl reconfigure # reconfigure and restart.
sudo gitlab-ctl status

Jenkins

Install Java

推荐安装 openjdk-7-jre 和 openjdk-7-jdk ,但是其在 Ubuntu 16.04 和更高版本不再有效,可以安装 Java 8 或者 9 代替。

sudo apt-get install openjdk-7-jre
sudo apt-get install openjdk-7-jdk

Install Jenkins

wget -q -O - https://pkg.jenkins.io/debian/jenkins-ci.org.key | sudo apt-key add -
sudo sh -c 'echo deb http://pkg.jenkins.io/debian-stable binary/ > /etc/apt/sources.list.d/jenkins.list'
sudo apt-get update
sudo apt-get install jenkins

Upgrade Jenkins

Jenkins 更新比较快,如若过期,可以按如下命令更新。

sudo apt-get update
sudo apt-get install jenkins

Config Jenkins

sudo vi /etc/init.d/jenkins
# Modify HTTP_PORT is suggested.
sudo vi /etc/sudoers
# jenkins ALL=(ALL) NOPASSWD:ALL ; 赋予 Jenkins sudo 权限和无密权限

Install plugin

通过 web(eg: http://192.168.1.2:8080 ) 访问Jenkins 并安装插件 Git plugin和Gitlab Hook Plugin 。

初次登陆时注意 check web 提示的密码地址。

Nginx

Install nginx

sudo apt-get install nginx
# upgrade
sudo apt-add-repository ppa:nginx/stable
sudo apt-get update
sudo apt-get upgrade nginx -y

sudo service nginx start

nginx 默认使用 80 端口,打开浏览器输入: http://localhost/

Config nginx

sudo vi /etc/nginx/nginx.conf , 注释掉不需要的配置文件,并新配 server 。

# comment to solve "Welcome to nginx ..." issue.
# include /etc/nginx/conf.d/*.conf;
# include /etc/nginx/sites-enabled/*;
server {
        server_name localhost;
        listen 8082; # config port
        location / {
                root /home/lee/gitbook/www/mybook; # 自定义,用于存放 gitbook 内容
                #index  index.html index.html;

                #autoindex
                autoindex on;
                autoindex_exact_size on;
                autoindex_localtime on;
        }
}
nginx -t # 检查配置文件是否正常
nginx -s reload # 重启
若出现错误:
nginx:[error] open() "/run/nginx.pid" failed (2: No such file or directory)

nginx -c /etc/nginx/nginx.conf
nginx -s reload
nginx -s stop

Automaticaly trigger

Config gitlab

Add access token

user settings ---> Access Tokens

记录下 token ,一旦关闭网页,此 token 将不再可见。

Create mybook

新建一个项目

, 添加 webhooks.

a. Settings ---> Integrations 
b. add url: http://192.168.1.2:8082/gitlab/build_now (jenkins url) .
c. Select push event.
d. Add webhook.

在本地项目路径执行 ‘gitbook init’ 生成 README.md 和 SUMMARY.md 两个文件, push 到 gitlab.

Config Jenkins

Add tokens

# 系统管理 ---> 系统设置
Gitlab:
Connection name: gitlab
Gitlab host url: gitlab url
credentials: Add token, 填入上面 Access Tokens.
Test connection.

Config trigger

新建任务 —-> 构建一个自由风格的软件项目:

  1. 源码管理: git

    Repository URL:
    
    http://192.168.1.2:8081/root/mybook.git
    Credentials ---> Add , 填入 Gitlab 用户名和密码
    
  2. 构建 —-> 执行 shell

    gitbook build
    sudo rm -rf  /home/lee/gitbook/www/mybook
    sudo cp -a    _book  /home/lee/gitbook/www/mybook
    sudo chmod  777  /home/lee/gitbook/www/mybook
    

Preview

更新本地文件,然后 push 到 Gitlab, 查看 Jenkins 是否会自动触发构建。

如果 OK , 整个配置流程就完成了,也可以直接预览 Gitbook了。

http://192.168.1.2:8082 (nginx port)

以上所述就是小编给大家介绍的《Gitbook + Jenkins + Gitlab 搭建内网自动构建的 Gitbook》,希望对大家有所帮助,如果大家有任何疑问请给我留言,小编会及时回复大家的。在此也非常感谢大家对 码农网 的支持!

查看所有标签

猜你喜欢:

本站部分资源来源于网络,本站转载出于传递更多信息之目的,版权归原作者或者来源机构所有,如转载稿涉及版权问题,请联系我们

Nginx Essentials

Nginx Essentials

Valery Kholodkov / Packt Publishing / 2015-7-1 / USD 34.99

About This Book Learn how to set up, configure, and operate an Nginx installation for day-to-day useExplore the vast features of Nginx to manage it like a pro, and use them successfully to run your......一起来看看 《Nginx Essentials》 这本书的介绍吧!

HTML 压缩/解压工具
HTML 压缩/解压工具

在线压缩/解压 HTML 代码

UNIX 时间戳转换
UNIX 时间戳转换

UNIX 时间戳转换

RGB HSV 转换
RGB HSV 转换

RGB HSV 互转工具