I-team博客的gitlab-runner持续集成实践

代码星冰乐

专注成就未来

首页 归档 关于

I-team博客的gitlab-runner持续集成实践

Jun 10, 2018 | ChanghuiNhaifeiWu | 总结 | 阅读
文章目录
  1. 1. 持续集成工具 gitlab-runner 介绍
  2. 2. Hexo 博客环境迁移
    1. 2.1. 迁移前版本控制
    2. 2.2. 博客环境安装
  3. 3. gitlab-runner环境搭建
    1. 3.1. gitlab-runner的安装
    2. 3.2. gitlab-runner注册到gitlab官网
    3. 3.3. 创建.gitlab-ci.yml,并放着工程的根目录下
    4. 3.4. 查看gitlab上的构建结果
  4. 4. 小结
  5. 5. 参考文章

作 者:ChanghuiNhaifeiWu
原文链接:https://www.hchstudio.cn/article/2018/29b5/
版权声明:非特殊声明均为本站原创作品,转载时请注明作者和原文链接。


由于版权原因,请阅读原文 --> I-team博客的gitlab-runner持续集成实践

关注我们

作 者:ChanghuiNhaifeiWu
原文链接:https://www.hchstudio.cn/article/2018/29b5/
版权声明:非特殊声明均为本站原创作品,转载时请注明作者和原文链接。

作 者:ChanghuiNhaifeiWu
原文链接:https://www.hchstudio.cn/article/2018/29b5/
版权声明:非特殊声明均为本站原创作品,转载时请注明作者和原文链接。

做为一个略微看过nodejs语法,但又不懂nodejs的攻城狮,搭建hexo环境很是麻烦,要考虑到翻墙、版本兼容等问题。于是乎,博主每换一个电脑,为了能继续发博客,都需要在新电脑上花一天时间重新搞一下 hexo 环境,楼主感觉还是有简洁的方案来实现我一提交代码就可以自动发布博客,不需要再手动操作一波,这样岂不美哉。so,也就有了今天的经历,代码可以持续集成,博客也可以。楼主的解决方案是使用gitlab与gitlab-runner实现博客部署的持续集成,效果真的不要太好。

持续集成工具 gitlab-runner 介绍

gitlab-ci全称是gitlab continuous integration的意思,也就是持续集成。中心思想是当每一次push到gitlab的时候,都会触发一次脚本执行,然后脚本的内容包括了测试,编译,部署等一系列自定义的内容。而gitlab-runner 是 gitlab 提供的持续集成工具。

简单的说,要让CI工作可总结为以下几点:

  • 在仓库根目录创建一个名为.gitlab-ci.yml 的文件。
  • 为该项目配置一个runner服务,楼主这里使用的是使用gitlab提供代码厂库,在自己的腾讯云服务器上运行gitlab-runner服务。
  • 完成上面的步骤后,每次push代码到Git仓库, runner就会自动开始pipeline。

gitlab-ci的具体部署流程如下图所示(图来自网络,侵权删)
gitlab-runner

Hexo 博客环境迁移

迁移前版本控制

其实每个nodejs工程根目录下都有一个package.json文件,里面都包含了我们所用的插件信息,只需要我们在安装插件的时候注意加上–save,就会自动把插件信息保存到 package.json 中。

如果目录下没有 package.json 文件也不要紧,在跟目录命令行中运行 npm init 即可生成。

博客环境安装

前面做好版本控制,那接下来的事情就好做了。

  1. 备份你的代码,注意:代码中不需要包含 node_modules 文件夹了
  2. 先在新电脑中装上 nodejs 环境
  3. 由于国内安装 npm 的一些插件需要翻墙,所以这里直接用淘宝镜像:cnpm,安装方法:npm install -g cnpm –registry=https://registry.npm.taobao.org
  4. 安装hexo客户端:cnpm install hexo-cli -g
  5. 新建博客目录:hexo init
  6. 把你备份的代码放到此目录下,如果有重复的文件直接覆盖就行
  7. 安装 hexo 插件:cnpm install
    就这样,新的博客环境迁移完成了,执行 hexo s 开始你新的博客征程吧!

gitlab-runner环境搭建

gitlab-runner的安装

使用gitlab官网提供的下载地址太慢,所以找到了一个国内的镜像地址:

  1. 新建 gitlab-ci-multi-runner.repo

    1
    touch /etc/yum.repos.d/gitlab-ci-multi-runner.repo
  2. 将以下内容写入文件

1
2
3
4
5
6
7
[gitlab-ci-multi-runner]
name=gitlab-ci-multi-runner
baseurl=https://mirrors.tuna.tsinghua.edu.cn/gitlab-ci-multi-runner/yum/el7
repo_gpgcheck=0
gpgcheck=0
enabled=1
gpgkey=https://packages.gitlab.com/gpg.key
  1. 执行
1
2
sudo yum makecache
sudo yum install gitlab-ci-multi-runner
  1. 以上是楼主在centos上的安装过程,其他系统版本的安装请移步gitlab-runner其他系统版本的安装

gitlab-runner注册到gitlab官网

在终端输入gitlab-runner register 会出现以下过程:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
[root@localhost ~]# gitlab-runner register
Running in system-mode.

Please enter the gitlab-ci coordinator URL (e.g. https://gitlab.com/):
https://gitlab.com/
Please enter the gitlab-ci token for this runner:
your gitlab-ci token
Please enter the gitlab-ci description for this runner:
[localhost.localdomain]: my-runner
Please enter the gitlab-ci tags for this runner (comma separated):
your tag
Whether to run untagged builds [true/false]:
[false]: true
Registering runner... succeeded runner=c5552857
Please enter the executor: parallels, shell, virtualbox, docker+machine, docker-ssh+machine, docker, docker-ssh, ssh, kubernetes:
shell
Runner registered successfully. Feel free to start it, but if it's running already the config should be automatically reloaded!

在注册过程中有两个比较重要的参数一个是gitlab的URL,另一个就是注册的token,这两个参数可以在gitlab上找到,过程是Settings>CI/CD>Runners settings>Specific Runners,如下图所示
gitlab-runner-settings

另外还需要打开
gitlab-runner-settings

要是自己注册的gitlab-runner生效还学要禁用Shared Runners

以上过程是楼主在centos上操作的,其他版本请移步gitlab-runner注册到gitlab

创建.gitlab-ci.yml,并放着工程的根目录下

.gitlab-ci.yml具体配置请移步官方文档,下面给出楼主使用的.gitlab-ci.yml具体内容

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
variables:
GIT_STRATEGY: none

stages:
- build_and_deploy

job:
stage: build_and_deploy
script:
- cd /opt/I-team-fly
- git pull --tags origin dev
- hexo clean
- hexo g
- hexo d
only:
- dev

查看gitlab上的构建结果

gitlab-runner-settings

小结

当然这个过程中还是要涉及到几次使用ssh-key来设置免密登录,楼主就不在这里赘述了,请遇到问题的小伙伴自行Google。

参考文章

  • 基于Gitlab CI搭建持续集成环境
  • gitlab之gitlab-ci自动部署
  • Gitlab CI集成Gitlab Runner

关注我们

作 者:ChanghuiNhaifeiWu
原文链接:https://www.hchstudio.cn/article/2018/29b5/
版权声明:非特殊声明均为本站原创作品,转载时请注明作者和原文链接。

分享
总结hexo
使用Spring Boot实现博客统计服务阿里 RPC 框架 DUBBO 初体验
微信关注我们
分类
  • Android8
  • Go4
  • Java59
  • Kafka,Java1
  • Kotlin2
  • Linux1
  • MapReduce1
  • Python2
  • Raft1
  • Redis1
  • ThreadPoolExecutor1
  • go1
  • 工具1
  • 总结8
  • 旅游日记1
标签
Nginx ChanghuiN haifeiWu Android Java 设计模式 hexo Kotlin 算法 MySQL 源码解析 Python Redis golang web Kafka 配置中心 总结 性能优化 旅游日记 Shell Go 问题排查 译文 Docker Spring Boot 工具 学习笔记 WebFlux 性能测试 go 散列表 源码 netty Raft
最近文章
  • Kafka的日志复制机制
  • 从20到21
  • go 并发编程
  • 【译】了解Linux CPU负载-您何时应该担心?
  • Zookeeper 与分布式锁
  • 基于Redis的分布式锁到底安全吗?
  • 【译】Raft 学生指南
  • ThreadPoolExecutor 的简单梳理
  • MapReduce 的简单实现
  • 使用 Map 实现策略模式
福利专区
    免费SSL证书
      阿里云红包
        腾讯云专属福利
        Copyright © 2021 代码星冰乐. Powered by ChanghuiN. 版权所有 晋ICP备15001365号
        特别感谢: 云服务器服务商 、 CDN 服务商