前往小程序,Get更优阅读体验!
立即前往
首页
学习
活动
专区
工具
TVP
发布
社区首页 >专栏 >​gitlab+jenkins打造ceph的rpm自动编译

​gitlab+jenkins打造ceph的rpm自动编译

作者头像
用户1260683
发布2019-05-09 11:25:33
1.1K0
发布2019-05-09 11:25:33
举报

前置条件

准备jenkins和gitlab的安装,这个过程请自行谷歌,介绍一下软件版本:

  • Jenkins ver. 2.164.2
  • gitlab 11.9.8
  • CentOS 7.4 64bit

jenkins 插件设置

需要添加的插件:Gitlab Hook、Build Authorization Token Root、Gitlab Authentication、Gitlab

gitlab新建ceph

源码包上传到gitlab

在 http://download.ceph.com/tarballs/ 下载对应的软件包版本,以12.2.12为例

解压软件包

代码语言:javascript
复制
[root@demohost1 supdev]# tar zxf ceph-12.2.12.tar.gz #解压
[root@demohost1 ceph-12.2.12]# cd ceph-12.2.12
[root@demohost1 ceph-12.2.12]# ls
admin    ceph-erasure-code-corpus  ChangeLog       CONTRIBUTING.rst  debian            do_freebsd.sh  fusetrace        make-apk.sh   man                  pom.xml     README.alpine.md    README.solaris     share                  udev
alpine   ceph-object-corpus        cmake           COPYING           doc               Doxyfile       INSTALL          make-debs.sh  mirroring            qa          README.FreeBSD      README.xio         src
AUTHORS  ceph.spec                 CMakeLists.txt  COPYING-GPL2      doc_deps.deb.txt  etc            install-deps.sh  make-dist     NEWS                 README      README.git-subtree  run-make-check.sh  SubmittingPatches.rst
bin      ceph.spec.in              CodingStyle     COPYING-LGPL2.1   do_cmake.sh       examples       keys             make-srpm.sh  PendingReleaseNotes  README.aix  README.md           selinux            systemd
[root@demohost1 ceph-12.2.12]# find . -name ".gitignore"| xargs rm -f #关键步骤,剔除掉.gitignore,不然后面编译依赖检查会报错

初始化git,提交到gitlab仓库

代码语言:javascript
复制
[root@demohost1 ceph-12.2.12]# git init
Initialized empty Git repository in /home/supdev/ceph-12.2.12/.git/
[root@demohost1 ceph-12.2.12]# pwd
/home/demo/ceph-12.2.12
[root@demohost1 ceph-12.2.12]# git remote add origin http://gitlab.cephdemo.local/diluga/ceph.git
[root@demohost1 ceph-12.2.12]# git add --all .  
The file will have its original line endings in your working directory.
warning: CRLF will be replaced by LF in src/rapidjson/thirdparty/gtest/googletest/msvc/gtest_unittest.vcproj.
The file will have its original line endings in your working directory.

[root@demohost1 ceph-12.2.12]# git commit -m "Initial commit"
[master (root-commit) 85a9fab] Initial commit
 Committer: root <root@demohost1.h.chinabank.com.cn>
Your name and email address were configured automatically based
on your username and hostname. Please check that they are accurate.
You can suppress this message by setting them explicitly:

    git config --global user.name "Your Name"
    git config --global user.email you@example.com

After doing this, you may fix the identity used for this commit with:

    git commit --amend --reset-author

The file will have its original line endings in your working directory.
 46084 files changed, 9316748 insertions(+)
 create mode 100644 .gitmodule_mirrors
 create mode 100644 .gitmodules
 ...
 create mode 100644 udev/60-ceph-by-parttypeuuid.rules
 create mode 100644 udev/95-ceph-osd.rules


[root@demohost1 ceph-12.2.12]# git push -u origin master
Username for 'http://gitlab.cephdemo.local': diluga
Password for 'http://diluga@gitlab.cephdemo.local':
Counting objects: 48328, done.
Delta compression using up to 32 threads.
Compressing objects: 100% (47048/47048), done.
Writing objects: 100% (48328/48328), 83.34 MiB | 8.29 MiB/s, done.
Total 48328 (delta 12162), reused 0 (delta 0)
remote: Resolving deltas: 100% (12162/12162), done.
To http://gitlab.cephdemo.local/diluga/ceph.git
 * [new branch]      master -> master
Branch master set up to track remote branch master from origin.

jenkins 任务设置

新建一个自由风格的软件项目,输入"rpmbuilid_ceph"

之后在源码管理里面选择git,输入之前新建的gitlab项目信息,设置相应的分支,这里选的是默认master分支

Credentials部分,选择“添加”,输入gitlab的账号和密码如下

之后设置 构建触发器,选择“Build when a change is pushed to GitLab”,记录“GitLab webhook URL”,选择在 “Push Events” 和 “Accepted Merge Request Events” 两种事件类型的时候触发webhook通知。

同时在Secret token 点击“Generate”,记录生成的token字段

最后选择"构建” -> "执行 shell",输入对应的rpm编译打包脚本,点击保存,完成jenkins设置。

脚本如下

代码语言:javascript
复制
#!/bin/bash
rm -rf ~/rpmbuild
/usr/bin/rpmdev-setuptree
cp -f ./ceph.spec ~/rpmbuild/SPECS
#git archive master --prefix=ceph-12.2.12/ | bzip2 > ceph-12.2.12.tar.bz2
mkdir ceph-12.2.12
mv * ceph-12.2.12
cp .gitmodules ceph-12.2.12
tar -cvjSf ceph-12.2.12.tar.bz2 ceph-12.2.12
cp ceph-12.2.12.tar.bz2 ~/rpmbuild/SOURCES/
cd ~/rpmbuild
/usr/bin/rpmbuild -bb SPECS/ceph.spec

gitlab webhook设置

打开gitlab 对应的项目,在 settings -> integrations

输入之前的“GitLab webhook URL” 和 token,勾选 push和 merge 两种类型的事件,如果没用到SSL,则取消SSL认证。

启动编译

回到jenkins对应的"rpmbuild_ceph"任务列表,点击“立即构建”,开始编译ceph的rpm包,

编译过程可以通过点击具体任务,查看“控制台输出”,看到编辑的当前进度状态。

编译完成后,RPM包会存储在jenkins节点的/root/rpmbuild/下。

总结

上面的设置需要注意的有3点

  1. 代码提交到gitlab一定要剔除掉“.gitignore”,当然你可以手工去修改具体内容,不然后面编译会报错。
  2. jenkins是基于gitlab的pull和merge事件来触发后台的自动编译,所有后续在gitlab上面的代码pull和merge操作都会触发相应版本的rpm包编译,注意这里只针对源码的master分支做了处理,各位根据实际情况进行调整。
  3. 源码里面的“ceph.spec”文件写死了一些配置,如果你改变了编译流程细节,则需要修改对应的配置内容,比如源件包名称必须是"ceph-12.2.12.tar.bz2",具体可以参考ceph.spec内容。

ceph.spec 内容片断

代码语言:javascript
复制
Summary:        User space components of the Ceph file system
License:        LGPL-2.1 and CC-BY-SA-3.0 and GPL-2.0 and BSL-1.0 and BSD-3-Clause and MIT
%if 0%{?suse_version}
Group:          System/Filesystems
%endif
URL:            http://ceph.com/
Source0:        http://ceph.com/download/ceph-12.2.12.tar.bz2 #注意软件包名称
本文参与 腾讯云自媒体分享计划,分享自微信公众号。
原始发表:2019-04-22,如有侵权请联系 cloudcommunity@tencent.com 删除

本文分享自 Ceph对象存储方案 微信公众号,前往查看

如有侵权,请联系 cloudcommunity@tencent.com 删除。

本文参与 腾讯云自媒体分享计划  ,欢迎热爱写作的你一起参与!

评论
登录后参与评论
0 条评论
热度
最新
推荐阅读
目录
  • 前置条件
  • jenkins 插件设置
  • gitlab新建ceph
  • 源码包上传到gitlab
  • jenkins 任务设置
  • gitlab webhook设置
  • 启动编译
  • 总结
领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档