Buildbotの設定ファイル


< 前 |

チュートリアルをこなしてみると、Buildbotとしての設定はMaster側の master.cfg のみで、Worker側は基本的にビルド以外の何も行わないことがわかる。

次に進む前にこの master.cfg を確認してみることにする。

master.cfg

冒頭

master.cfg
# -*- python -*-
# ex: set filetype=python:

from buildbot.plugins import *

見ておわかりだと思うが、この設定ファイルはPythonそのものになっている。

master.cfg
# This is a sample buildmaster config file. It must be installed as
# 'master.cfg' in your buildmaster's base directory.

# This is the dictionary that the buildmaster pays attention to. We also use
# a shorter alias to save typing.
c = BuildmasterConfig = {}

設定の実体は BuildmasterConfig と名付けられたディクショナリで、以下アクセスはc['key'] のように行う。

WORKERS セクション

workers

master.cfg
####### WORKERS

# The 'workers' list defines the set of recognized workers. Each element is
# a Worker object, specifying a unique worker name and password.  The same
# worker name and password must be configured on the worker.
c['workers'] = [worker.Worker("example-worker", "pass")]

c['workers'] はWorkerを定義する部分で、実体は buildbot.plugins.worker.Worker のインスタンスを要素とするリスト。

Worker(username, password) 形式で、渡した認証情報でWorker側プロセスと認証を行う。

protocols

master.cfg
# 'protocols' contains information about protocols which master will use for
# communicating with workers. You must define at least 'port' option that workers
# could connect to your master with this protocol.
# 'port' must match the value configured into the workers (with their
# --master option)
c['protocols'] = {'pb': {'port': 9989}}

c['protocols'] はMaster側の接続待ちプロトコル。
オプションは様々にあるが、上記の場合は無指定(localhost)の 9989 番ポートをbindする。

CHANGESOURCES セクション

change_source

master.cfg
####### CHANGESOURCES

# the 'change_source' setting tells the buildmaster how it should find out
# about source code changes.  Here we point to the buildbot version of a python hello-world project.

c['change_source'] = []
c['change_source'].append(changes.GitPoller(
        'git://github.com/buildbot/hello-world.git',
        workdir='gitpoller-workdir', branch='master',
        pollinterval=300))

c['change_source'] は監視対象を列挙する。

ChangeSource と呼ばれるオブジェクトのリストで、buildbot.plugins.changes 以下などに配置されている GitPollerHgPoller などのリポジトリをポーリングする Poller に加えて、GitHubやBitBucket専用の監視オブジェクトなどを列挙する。

SCHEDULERS セクション

schedulers

master.cfg
####### SCHEDULERS

# Configure the Schedulers, which decide how to react to incoming changes.  In this
# case, just kick off a 'runtests' build

c['schedulers'] = []
c['schedulers'].append(schedulers.SingleBranchScheduler(
                            name="all",
                            change_filter=util.ChangeFilter(branch='master'),
                            treeStableTimer=None,
                            builderNames=["runtests"]))
c['schedulers'].append(schedulers.ForceScheduler(
                            name="force",
                            builderNames=["runtests"]))

c['schedulers'] はビルドスケジュールなどのスケジュールを列挙する。
ここで定義されているのはブランチの変更を監視してあるBuilderを実行する SingleBranchScheduler と、あるBuilderを手動で強制実行する ForceScheduler のふたつ。

ここで指定する builderName には、下の BUILDERS セクションで定義されている名前を指定する。

BUILDERS セクション

(factory)

master.cfg
####### BUILDERS

# The 'builders' list defines the Builders, which tell Buildbot how to perform a build:
# what steps, and which workers can execute them.  Note that any particular build will
# only take place on one worker.

factory = util.BuildFactory()
# check out the source
factory.addStep(steps.Git(repourl='git://github.com/buildbot/hello-world.git', mode='incremental'))
# run the tests (note that this will require that 'trial' is installed)
factory.addStep(steps.ShellCommand(command=["trial", "hello"],
                                   env={"PYTHONPATH": "."}))

ビルド処理の単位はBuilderでまとめるのだが、このインスタンスは

  1. Factoryを準備
  2. Factoryに、処理順にStepを追加
  3. FactoryからBuilderを作成

の順で作成する。上の例だと

  1. util.BuildFactory を作成
  2. Step追加
    1. Gitリポジトリからの取得を行う steps.Git を作成して追加
    2. シェルスクリプト実行を行う steps.ShellCommand を作成して追加

まで行っている。

builders

master.cfg
c['builders'] = []
c['builders'].append(
    util.BuilderConfig(name="runtests",
      workernames=["example-worker"],
      factory=factory))

このBuilderFactoryを用いてBuilderを作り、 c['builders'] に追加する。
この時にBuilderを担わせるWorkerは、WORKERSセクションで定義した名前をリスト形式で指定する。

別のテスト実施やリリースビルド作成などは、これを繰り返して c['builders'] に複数のBuilderを追加していく。

BUILDBOT SERVICES セクション

services

master.cfg
####### BUILDBOT SERVICES

# 'services' is a list of BuildbotService items like reporter targets. The
# status of each build will be pushed to these targets. buildbot/reporters/*.py
# has a variety to choose from, like IRC bots.

c['services'] = []

c['services'] には追加サービスを登録する。
コメントにもある通りIRCボットのようなものが該当する。

PROJECT IDENTITY セクション

title, titleURL

master.cfg
####### PROJECT IDENTITY

# the 'title' string will appear at the top of this buildbot installation's
# home pages (linked to the 'titleURL').

c['title'] = "Hello World CI"
c['titleURL'] = "https://buildbot.github.io/hello-world/"

サイト上部に記述されるタイトルを c['title']、実際のリポジトリや配布先のURLを c['titleURL'] に記述する。
両方とも文字列扱い。

buildbotURL

master.cfg
# the 'buildbotURL' string should point to the location where the buildbot's
# internal web server is visible. This typically uses the port number set in
# the 'www' entry below, but with an externally-visible host name which the
# buildbot cannot figure out without some help.

c['buildbotURL'] = "http://localhost:8010/"

c['buildbotURL'] は、配置するURLそのものを記述する。
これはサイト構築時に使われるURLなので、アクセス先から確実に参照できるものを指定する。

www

master.cfg
# minimalistic config to activate new web UI
c['www'] = dict(port=8010,
                plugins=dict(waterfall_view={}, console_view={}, grid_view={}))

c['www'] はBuildbotのWebインターフェイス側の設定を担う。形式はディクショナリ。
バインドしているポート、表示プラグインとしてウォーターフォール、コンソール、グリッドの各表示を設定している。

DB URL セクション

db

master.cfg
####### DB URL

c['db'] = {
    # This specifies what database buildbot uses to store its state.  You can leave
    # this at its default for all but the largest installations.
    'db_url' : "sqlite:///state.sqlite",
}

c['db'] はデータベースの指定。
BuildbotはO/RマッパーとしてSQLAlchemyを利用しているので、SQLAlchemyのURL記法を用いて接続先のデータベースを指定する。

内容としては以上となる。
量としてはそれほど多くないが、生のPythonであることは念頭に置いていくと幸せになるかもしれない。

次 → (書くかも)