Buildbot|Buildbot First Run 持续集成框架

Buildbot 当前最新 发布版 2.1(最早接触时是0.8.12),The Continuous Integration Framework。
自 2019年2月 发布 2.0 开始,全面转向 Python 3,不再支持 Python 2.7。
Buildbot is shipped in two components: the buildmaster (called buildbot for legacy reasons) and the buildslave.
Buildbot|Buildbot First Run 持续集成框架
文章图片
Buildbot architectural overview 请按照 First Run Tutorial 认识一下 Buildbot。
Python 环境
现在 Linux 已经预装 Python 2.7(符合安装要求),我们测试机上的完整版本 2.7.5(python --version),Python 默认安装许多 modules,比如 easy_install 等。

python -c "help('modules')" # 查看 python 已经安装的模块 modules python -m mod # run library module as a script (terminates option list). 这个命令可以查看是否安装了指定的 mod 模块。 python -m SimpleHTTPServer port 可以临时在 port 端口启动一个 HTTP SERVER。

Note
Buildbot does not require root access. Run the commands in this tutorial as a normal, unprivileged user.
即:将 Buildbot 安装在 Virtualenv 虚拟 Python 环境下。
cd #进入用户根目录 mkdir -p tmp/buildbot cd tmp/buildbot virtualenv --no-site-packages sandbox # 创建一个名为sandbox的虚拟环境 source sandbox/bin/activate # 启用并进入虚拟环境:(sandbox)[michael@localhost buildbot]$ ... easy_install sqlalchemy==0.7.10 easy_install buildbot==0.8.12 # 安装 buildbot master

我不打算详述整个过程,仅列举一下新鲜点或者遇到的问题。
安装 virtualenv
virtualenv - Virtual Python Environment builder.
  • PyPI - the Python Package Index (virtualenv);
  • PyPA - Python Packaging Authority (virtualenv);
  • virtualenv Installation;
To install version 13.1.2 globally from source:
$ curl -O https://pypi.python.org/packages/source/v/virtualenv/virtualenv-13.1.2.tar.gz # 或者使用 wget $ tar zxvf virtualenv-13.1.2.tar.gz $ cd virtualenv-13.1.2 $ [sudo] python setup.py install

** 指明 buildbot 版本 **
在安装 buildbot 时请指明版本,否则匹配到最新版本 0.9.0b3,报告错误:
Best match: buildbot 0.9.0b3
...
Processing buildbot-0.9.0b3.zip
...
error: Setup script exited with error: package directory 'buildbot/test' does not exist
** sandbox 环境 **
  • 虚拟环境下的 python 版本 2.7.5,Twisted 版本 15.4.0;
    python -c "import twisted; print twisted.__version__")
  • 执行 source sandbox/bin/activate 后,即启用并进入虚拟环境:
    (sandbox)[michael@localhost buildbot]$
Creating a master
buildbot create-master master mv master/master.cfg.sample master/master.cfg buildbot start master tail -f master/twistd.log # 可以查看到启动成功的日志

** 了解 buildbot 命令 **
buildbot --help
buildbot create-master --help
Creating a slave
cd cd tmp/buildbot source sandbox/bin/activate easy_install buildbot-slave==0.8.12 # 安装buildbot-slave buildslave create-slave slave localhost:9989 example-slave pass buildslave start slave tail -f slave/twistd.log

diagnostic tool
buildbot --version # If it shows you the versions of Buildbot and Twisted, the install went ok. buildslave --version pydoc buildbot # Help on package buildbot,比如 buildbot 依赖的包。pydoc: the Python documentation tool。

初始界面 访问:http://192.168.1.91:8010/
Buildbot|Buildbot First Run 持续集成框架
文章图片
localhost -> 192.168.1.91.png Buildbot|Buildbot First Run 持续集成框架
文章图片
Waterfall Display.png Linux centos-release 和 kernel-release
$ cat /etc/centos-release CentOS Linux release 7.1.1503 (Core) $ uname -r # --kernel-release 3.10.0-229.el7.x86_64 $ cat /proc/version Linux version 3.10.0-229.el7.x86_64 (builder@kbuilder.dev.centos.org) (gcc version 4.8.2 20140120 (Red Hat 4.8.2-16) (GCC) ) #1 SMP Fri Mar 6 11:36:42 UTC 2015

配置 buildbot 的设计思路很好,她的一个基本理念就是 将 buildslave 设计得极其简单易用,不需要什么配置。buildbot 的配置都在 buildmaster 的 master.cfg 文件。
The buildslaves are designed to require an absolute minimum of configuration, reducing the effort a potential volunteer needs to expend to be able to contribute a new test environment to the project.
buildbot reconfig master # master/master.cfg 修改后重新加载,或者 buildbot restart master

架构分解 System Architecture
Buildbot|Buildbot First Run 持续集成框架
文章图片
Buildbot: Continuous Integration Framework Buildbot|Buildbot First Run 持续集成框架
文章图片
master & worker
  • Notifiers: Status targets
BuildSlave Connections

Buildbot|Buildbot First Run 持续集成框架
文章图片
buildslaves obtain source code from vcs
To perform builds, the buildslaves must typically obtain source code from a CVS/SVN/etc repository.
The buildmaster provides instructions for performing builds, but does not provide the source code itself.
Buildmaster Architecture
Buildbot|Buildbot First Run 持续集成框架
文章图片
Buildmaster Architecture
  • 1个 buildmaster,2个 buildslave(如2个平台)
  • master.cfg: 2个 scheduler,3个 builder
  • It is quite common to have many Builders sharing the same buildslave.
  • Within a single BuildSlave, each Builder creates its own SlaveBuilder instance.
Builders:
Simply put, a builder is an element that is in charge of performing some action or sequence of actions, normally something related to building software (for example, checking out the source, or make all), but it can also run arbitrary commands.
The 'builders' list defines the Builders, which tell Buildbot how to perform a build: what steps(with a series of BuildSteps, configured in a BuildFactory), and which slaves can execute them.
Note that any particular build will only take place on one slave(the only reason to use multiple BuildSlaves for a single Builder is to provide a measure of load-balancing.)
为一个 builder 指定多个 buildslave 的唯一原因是负载均衡,任何一个 build 只会在一个 buildslave 上执行。
【Buildbot|Buildbot First Run 持续集成框架】Status Delivery Architecture
Buildbot|Buildbot First Run 持续集成框架
文章图片
Status Delivery Architecture 参考
  • Docs;
  • Trac;
  • Guido van Rossum: Python buildbot 2006;
  • IBM developerWorks: Continuous integration with Buildbot;
  • Python Buildbot;
  • 在Python Web项目中使用Jenkins进行持续集成;
  • Ansible;
    Ansible is a radically simple IT automation platform that makes your applications and systems easier to deploy. Avoid writing scripts or custom code to deploy and update your applications— automate in a language that approaches plain English, using SSH, with no agents to install on remote systems.

    推荐阅读