LoginSignup
10
10

More than 5 years have passed since last update.

etcd で 20 行くらいで continuous integration 的なものを構築する

Posted at

漢なら通知系は etcd ですね!

etcd を使って continuous integration 的なものも容易に構築できます.

まず, worker(build)ノードで以下のような node.js + shelljs でスクリプトを作ります.
curl をインストールしておくのを忘れずに.

etcd 自体は REST + JSON なので言語を選ばず利用できますが, 簡単に Mac/Linux/Windows でクロスプラットフォームを実現できるので node.js + shelljs をオススメします.

サーバ(remote)側に etcd を入れて port 4001 で動作させ, worker ノードからは ssh でログインできるものとします.

require('shelljs/global')


function worker() {
    console.log("wait notify");
    exec("ssh remote curl -s -L http://127.0.0.1:4001/v2/keys/build_notify?wait=true", function(code, output) {

      // Describe your build instruction here.
      exec('git pull');
      …


      setTimeout(function() {
          worker();
      }, 0);
    });
}

worker();

wait=true にすると build_notify キーに変更があるまでブロックします. exec() をコールバック付きで記述しないと待っている間 CPU リソースを使うので注意ください.

あとはサーバ側なり git repo 側で, なにかしらイベント(git commit など)があったときに以下のように build_notify キーをアップデートするようにします.

curl -s -L http://127.0.0.1:4001/v2/keys/build_notify -XPUT -d value="notify"

キーにアップデートがあると, wait=true で待っているクライアントに通知が行きます. etcd 内部でキーには atomic なインデックスが付いていますので, wait=true のあとでキーが変更されたときのみ通知が行きます. 便利ですね!

まとめ

etcd に対して, worker は複数登録して待つことができます. etcd は分散キーバリュー的なものなので, ビルドサーバが 1,000 ノードくらいあっても余裕かもしれませんね!

todo

認証周りを SSL クライアント証明書ベースにする.

10
10
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
10
10