94
Gateway CheckIn Pattern Jenkins * Git @kyon_mm in AAA 2014/06/28

JenkinsとGitで実装するGatewayCheckIn Pattern #AsianAA

  • Upload
    kyon-mm

  • View
    1.724

  • Download
    0

Embed Size (px)

DESCRIPTION

2014/06/28 に開催されたAsianAAでの発表資料です。

Citation preview

Page 1: JenkinsとGitで実装するGatewayCheckIn Pattern #AsianAA

Gateway CheckIn Pattern Jenkins * Git

@kyon_mm in AAA 2014/06/28

Page 2: JenkinsとGitで実装するGatewayCheckIn Pattern #AsianAA

Self Introduction

Page 3: JenkinsとGitで実装するGatewayCheckIn Pattern #AsianAA

Self Introduction• きょん(@kyon_mm) 26歳うさみみエンジニア

Page 4: JenkinsとGitで実装するGatewayCheckIn Pattern #AsianAA

Self Introduction• きょん(@kyon_mm) 26歳うさみみエンジニア

• Test Architect in Nagoya

Page 5: JenkinsとGitで実装するGatewayCheckIn Pattern #AsianAA

Self Introduction• きょん(@kyon_mm) 26歳うさみみエンジニア

• Test Architect in Nagoya

• Groovy, F#, C#, Scala

Page 6: JenkinsとGitで実装するGatewayCheckIn Pattern #AsianAA

Self Introduction• きょん(@kyon_mm) 26歳うさみみエンジニア

• Test Architect in Nagoya

• Groovy, F#, C#, Scala

• SCMBC, Nagoya.Testing, TDDBC

Page 7: JenkinsとGitで実装するGatewayCheckIn Pattern #AsianAA

Self Introduction• きょん(@kyon_mm) 26歳うさみみエンジニア

• Test Architect in Nagoya

• Groovy, F#, C#, Scala

• SCMBC, Nagoya.Testing, TDDBC

• TDD/BDDチョットデキル

Page 8: JenkinsとGitで実装するGatewayCheckIn Pattern #AsianAA

Self Introduction• きょん(@kyon_mm) 26歳うさみみエンジニア

• Test Architect in Nagoya

• Groovy, F#, C#, Scala

• SCMBC, Nagoya.Testing, TDDBC

• TDD/BDDチョットデキル

• 月曜日に長男が生まれました

Page 9: JenkinsとGitで実装するGatewayCheckIn Pattern #AsianAA

Agenda• ツール紹介

• 安全と高速の両立

• JenkinsとGitによるGateway CheckIn Pattern

• まとめ

• おまけ

Page 10: JenkinsとGitで実装するGatewayCheckIn Pattern #AsianAA

Jenkins

• Continuous Integration(CI) に特化したサーバーアプリケーションです。OSSですが、エンタープライズ版もあります。Javaがインストールされていれば動きます。

• http://jenkins-ci.org/

• 現状最も柔軟なCIツール。

Page 11: JenkinsとGitで実装するGatewayCheckIn Pattern #AsianAA

Git

• Distributed Version Control System(DVCS)に特化したアプリケーションです。OSSで、Linux, Mac, Windowsで動作します。

• http://git-scm.com/

• 現状最も人気のあるDVCSです。

Page 12: JenkinsとGitで実装するGatewayCheckIn Pattern #AsianAA

Agenda• ツール紹介

• 安全と高速の両立

• JenkinsとGitによるGateway CheckIn Pattern

• まとめ

• おまけ

Page 13: JenkinsとGitで実装するGatewayCheckIn Pattern #AsianAA

Gitのマージの不安全さ• CIなどでGitのマージを行うと便利そうに見えるときがある。

• イメージ

• git checkout id/xxx

• build

• git merge master

• git push origin master

Page 14: JenkinsとGitで実装するGatewayCheckIn Pattern #AsianAA

Gitのマージの不安全さ• Gitのマージはセマンティクスを保証しない。

• テストコードがセマンティクスを保証できているかどうかを判断するタイミングが、マージ前、マージ時、マージ後のときがあり、必ずしも十分なテストコードであるかどうかはわからない。

Page 15: JenkinsとGitで実装するGatewayCheckIn Pattern #AsianAA

不安全さ | 時間 を 人数で見る不安全さ

コミットする人数

手動マージ 自動マージ

時間

コミットする人数

手動マージ 自動マージ

Page 16: JenkinsとGitで実装するGatewayCheckIn Pattern #AsianAA

安全側に倒す• 人数が少ないうちは多少の時間を犠牲にして手動マージしたほうが安全なコミットをするほうがメリットが高いことが多い。

• スキル差があまりにあるときや、タスク分割が下手だと、いつまでもpushできないときがあるので、ペアプロ導入やコミット対象を気にしたタスク分割をする。

Page 17: JenkinsとGitで実装するGatewayCheckIn Pattern #AsianAA

特定テストを気軽に確認する• 自分の環境以外で全ての(例えば)UnitTestを確認するためにJenkinsは向いている。

Page 18: JenkinsとGitで実装するGatewayCheckIn Pattern #AsianAA

特定テストを気軽に確認する• 全員で1つのリポジトリを共有していると、テストが失敗したリビジョンが全員にpullされる可能性がある

• pushする前のルールが増えてしまい、下手したらいつまでもローカルで作業をするという悪循環が生まれる。

Page 19: JenkinsとGitで実装するGatewayCheckIn Pattern #AsianAA

特定テストを気軽に確認する• コミッター毎にpush専用の個人用リポジトリを用意することで、気軽にpush & CIをできるようにする。

• push専用リポジトリ = privateリポジトリ

• pull専用リポジトリ = centralリポジトリ

Page 20: JenkinsとGitで実装するGatewayCheckIn Pattern #AsianAA

Agenda• ツール紹介

• 安全と高速の両立

• JenkinsとGitによるGateway CheckIn Pattern

• まとめ

• おまけ

Page 21: JenkinsとGitで実装するGatewayCheckIn Pattern #AsianAA

Gateway CheckIn Pattern

Page 22: JenkinsとGitで実装するGatewayCheckIn Pattern #AsianAA

Gateway CheckIn Pattern

ある基準をクリアしたコードのみが共有される仕組み(すごいざっくり説明です。要出典)

Page 23: JenkinsとGitで実装するGatewayCheckIn Pattern #AsianAA

kyon_mm Local Repo

kyon_mm private Repo

Central Repo

developer central

edit & merge

pull | clonepushkick job

Page 24: JenkinsとGitで実装するGatewayCheckIn Pattern #AsianAA

kyon_mm Local Repo

kyon_mm private Repo

Central Repo

developer central

developer:compile & component test

central:compile & component test & integration test

Page 25: JenkinsとGitで実装するGatewayCheckIn Pattern #AsianAA

kyon_mm Local Repo

kyon_mm private Repo

Central Repo

developer central

developerジョブが成功したときのみ、pullできるリポジトリにpushされる。 このdeveloperジョブをGatewayと見なして、Gateway CheckInと呼ぶことが多いようです。

Page 26: JenkinsとGitで実装するGatewayCheckIn Pattern #AsianAA

kyon_mm Local Repo

kyon_mm private Repo

Central Repo

developer central

Gitolite Server

Jenkins Server

Page 27: JenkinsとGitで実装するGatewayCheckIn Pattern #AsianAA

kyon_mm Local Repo

kyon_mm private Repo

Central Repo

developer central

edit & merge

pull | clonepushkick job

Page 28: JenkinsとGitで実装するGatewayCheckIn Pattern #AsianAA

kyon_mm Local Repo

kyon_mm private Repo

Central Repo

developer central

edit & merge

pull | clonepushkick job

Page 29: JenkinsとGitで実装するGatewayCheckIn Pattern #AsianAA

kyon_mm Local Repo

kyon_mm private Repo

Central Repo

developer central

edit & merge

pull | clonepushkick job

Page 30: JenkinsとGitで実装するGatewayCheckIn Pattern #AsianAA

kyon_mm Local Repo

kyon_mm private Repo

Central Repo

developer central

edit & merge

pull | clonepushkick job

Page 31: JenkinsとGitで実装するGatewayCheckIn Pattern #AsianAA

kyon_mm Local Repo

kyon_mm private Repo

Central Repo

developer central

edit & merge

pull | clonepushkick job

Page 32: JenkinsとGitで実装するGatewayCheckIn Pattern #AsianAA

kyon_mm Local Repo

kyon_mm private Repo

Central Repo

developer central

edit & merge

pull | clonepushkick job

Page 33: JenkinsとGitで実装するGatewayCheckIn Pattern #AsianAA

kyon_mm Local Repo

kyon_mm private Repo

Central Repo

developer central

edit & merge

pull | clonepushkick job

Page 34: JenkinsとGitで実装するGatewayCheckIn Pattern #AsianAA

kyon_mm Local Repo

kyon_mm private Repo

Central Repo

developer central

edit & merge

pull | clonepushkick job

Page 35: JenkinsとGitで実装するGatewayCheckIn Pattern #AsianAA

kyon_mm Local Repo

kyon_mm private Repo

Central Repo

developer central

edit & merge

pull | clonepushkick job

Page 36: JenkinsとGitで実装するGatewayCheckIn Pattern #AsianAA

kyon_mm Local Repo

kyon_mm private Repo

Central Repo

developer central

bleis Local Repo

bleis private Repo

Page 37: JenkinsとGitで実装するGatewayCheckIn Pattern #AsianAA

kyon_mm Local Repo

kyon_mm private Repo

Central Repo

developer central

bleis Local Repo

bleis private Repo

Page 38: JenkinsとGitで実装するGatewayCheckIn Pattern #AsianAA

kyon_mm Local Repo

kyon_mm private Repo

Central Repo

developer central

bleis Local Repo

bleis private Repo

Page 39: JenkinsとGitで実装するGatewayCheckIn Pattern #AsianAA

kyon_mm Local Repo

kyon_mm private Repo

Central Repo

developer central

bleis Local Repo

bleis private Repo

Page 40: JenkinsとGitで実装するGatewayCheckIn Pattern #AsianAA

kyon_mm Local Repo

kyon_mm private Repo

Central Repo

developer central

bleis Local Repo

bleis private Repo

Page 41: JenkinsとGitで実装するGatewayCheckIn Pattern #AsianAA

kyon_mm Local Repo

kyon_mm private Repo

Central Repo

developer central

bleis Local Repo

bleis private Repo

Page 42: JenkinsとGitで実装するGatewayCheckIn Pattern #AsianAA

kyon_mm Local Repo

kyon_mm private Repo

Central Repo

developer central

bleis Local Repo

bleis private Repo

Page 43: JenkinsとGitで実装するGatewayCheckIn Pattern #AsianAA

kyon_mm Local Repo

kyon_mm private Repo

Central Repo

developer central

bleis Local Repo

bleis private Repo

Page 44: JenkinsとGitで実装するGatewayCheckIn Pattern #AsianAA

kyon_mm Local Repo

kyon_mm private Repo

Central Repo

developer central

bleis Local Repo

bleis private Repo

Page 45: JenkinsとGitで実装するGatewayCheckIn Pattern #AsianAA

kyon_mm Local Repo

kyon_mm private Repo

Central Repo

developer central

bleis Local Repo

bleis private Repo

Page 46: JenkinsとGitで実装するGatewayCheckIn Pattern #AsianAA

kyon_mm Local Repo

kyon_mm private Repo

Central Repo

developer central

bleis Local Repo

bleis private Repo

Page 47: JenkinsとGitで実装するGatewayCheckIn Pattern #AsianAA

kyon_mm Local Repo

kyon_mm private Repo

Central Repo

developer central

bleis Local Repo

bleis private Repo

Page 48: JenkinsとGitで実装するGatewayCheckIn Pattern #AsianAA

kyon_mm Local Repo

kyon_mm private Repo

Central Repo

developer central

bleis Local Repo

bleis private Repo

Page 49: JenkinsとGitで実装するGatewayCheckIn Pattern #AsianAA

kyon_mm Local Repo

kyon_mm private Repo

Central Repo

developer central

bleis Local Repo

bleis private Repo

Page 50: JenkinsとGitで実装するGatewayCheckIn Pattern #AsianAA

kyon_mm Local Repo

kyon_mm private Repo

Central Repo

developer central

bleis Local Repo

bleis private Repo

Page 51: JenkinsとGitで実装するGatewayCheckIn Pattern #AsianAA

kyon_mm Local Repo

kyon_mm private Repo

Central Repo

developer central

bleis Local Repo

bleis private Repo

kyon push

Page 52: JenkinsとGitで実装するGatewayCheckIn Pattern #AsianAA

kyon_mm Local Repo

kyon_mm private Repo

Central Repo

developer central

bleis Local Repo

bleis private Repo

kyon pushprivate build

Page 53: JenkinsとGitで実装するGatewayCheckIn Pattern #AsianAA

kyon_mm Local Repo

kyon_mm private Repo

Central Repo

developer central

bleis Local Repo

bleis private Repo

kyon pushprivate buildjenkins push

Page 54: JenkinsとGitで実装するGatewayCheckIn Pattern #AsianAA

kyon_mm Local Repo

kyon_mm private Repo

Central Repo

developer central

bleis Local Repo

bleis private Repo

kyon pushprivate build

central buildjenkins push

Page 55: JenkinsとGitで実装するGatewayCheckIn Pattern #AsianAA

kyon_mm Local Repo

kyon_mm private Repo

Central Repo

developer central

bleis Local Repo

bleis private Repo

kyon pushprivate build

central buildjenkins push

Page 56: JenkinsとGitで実装するGatewayCheckIn Pattern #AsianAA

kyon_mm Local Repo

kyon_mm private Repo

Central Repo

developer central

bleis Local Repo

bleis private Repo

kyon pushprivate build

central buildbleis pushjenkins push

Page 57: JenkinsとGitで実装するGatewayCheckIn Pattern #AsianAA

kyon_mm Local Repo

kyon_mm private Repo

Central Repo

developer central

bleis Local Repo

bleis private Repo

kyon pushprivate build

central buildbleis pushjenkins push

private build

Page 58: JenkinsとGitで実装するGatewayCheckIn Pattern #AsianAA

kyon_mm Local Repo

kyon_mm private Repo

Central Repo

developer central

bleis Local Repo

bleis private Repo

kyon pushprivate build

central buildbleis push

jenkins push

jenkins push

private build

Page 59: JenkinsとGitで実装するGatewayCheckIn Pattern #AsianAA

kyon_mm Local Repo

kyon_mm private Repo

Central Repo

developer central

bleis Local Repo

bleis private Repo

kyon pushprivate build

central buildbleis push

jenkins push

jenkins push

private build

Page 60: JenkinsとGitで実装するGatewayCheckIn Pattern #AsianAA

kyon_mm Local Repo

kyon_mm private Repo

Central Repo

developer central

bleis Local Repo

bleis private Repo

Page 61: JenkinsとGitで実装するGatewayCheckIn Pattern #AsianAA

kyon_mm Local Repo

kyon_mm private Repo

Central Repo

developer central

bleis Local Repo

bleis private Repo

Page 62: JenkinsとGitで実装するGatewayCheckIn Pattern #AsianAA

kyon_mm Local Repo

kyon_mm private Repo

Central Repo

developer central

bleis Local Repo

bleis private Repo

bleis push

Page 63: JenkinsとGitで実装するGatewayCheckIn Pattern #AsianAA

kyon_mm Local Repo

kyon_mm private Repo

Central Repo

developer central

bleis Local Repo

bleis private Repo

bleis pushprivate build

Page 64: JenkinsとGitで実装するGatewayCheckIn Pattern #AsianAA

kyon_mm Local Repo

kyon_mm private Repo

Central Repo

developer central

bleis Local Repo

bleis private Repo

bleis push

jenkins pushprivate build

Page 65: JenkinsとGitで実装するGatewayCheckIn Pattern #AsianAA

kyon_mm Local Repo

kyon_mm private Repo

Central Repo

developer central

bleis Local Repo

bleis private Repo

bleis push

jenkins pushprivate build

Page 66: JenkinsとGitで実装するGatewayCheckIn Pattern #AsianAA

kyon_mm Local Repo

kyon_mm private Repo

Central Repo

developer central

bleis Local Repo

bleis private Repo

bleis push

jenkins pushprivate build

Page 67: JenkinsとGitで実装するGatewayCheckIn Pattern #AsianAA

kyon_mm Local Repo

kyon_mm private Repo

Central Repo

developer central

bleis Local Repo

bleis private Repo

bleis push

jenkins push

bleis pull

private build

Page 68: JenkinsとGitで実装するGatewayCheckIn Pattern #AsianAA

kyon_mm Local Repo

kyon_mm private Repo

Central Repo

developer central

bleis Local Repo

bleis private Repo

bleis push

jenkins push

bleis pullprivate build

private build

Page 69: JenkinsとGitで実装するGatewayCheckIn Pattern #AsianAA

kyon_mm Local Repo

kyon_mm private Repo

Central Repo

developer central

bleis Local Repo

bleis private Repo

bleis push

jenkins push

bleis pullprivate buildjenkins push

private build

Page 70: JenkinsとGitで実装するGatewayCheckIn Pattern #AsianAA

kyon_mm Local Repo

kyon_mm private Repo

Central Repo

developer central

bleis Local Repo

bleis private Repo

bleis push

jenkins push

bleis pullprivate buildjenkins pushcentral build

private build

Page 71: JenkinsとGitで実装するGatewayCheckIn Pattern #AsianAA

Agenda• ツール紹介

• 安全と高速の両立

• JenkinsとGitによるGateway CheckIn Pattern

• まとめ

• おまけ

Page 72: JenkinsとGitで実装するGatewayCheckIn Pattern #AsianAA

構成まとめ• Gitリポジトリ数 : 開発者数 = n +1 : n

• Jenkinsジョブ数 = 2~

• privateからのみGitのhookでdeveloperジョブを起動。

• developerジョブ以降はJenkinsでジョブ連携

Page 73: JenkinsとGitで実装するGatewayCheckIn Pattern #AsianAA

使っているJenkins Pluginや設定• ビルドパラメータ

• Git Plugin

• Build PipeLine Plugin

• Scriptler Plugin

• Log Parser

• Job ConfigHistory

Page 74: JenkinsとGitで実装するGatewayCheckIn Pattern #AsianAA

まとめ• 実際にはもっと後続のジョブを連携させていますが、基本形は紹介した通りです。

• 少しずつ進歩してこの形になりましたが、基本的な形が出来てから3年ほど経過しましたが、5名程度以下の開発ではうまくいっています。(それ以上は知らない。

• 気軽にpushできるようにしたり、pullできるのはある基準での安全なコードのみに強制する仕組みもよい。

• リモートで仕事していると困るかもね :-p

Page 75: JenkinsとGitで実装するGatewayCheckIn Pattern #AsianAA

ご清聴ありがとうございました

Page 76: JenkinsとGitで実装するGatewayCheckIn Pattern #AsianAA

おまけ Jenkinsのダメなところ

Page 77: JenkinsとGitで実装するGatewayCheckIn Pattern #AsianAA

おまけ Jenkinsのダメなところ

•ジョブは関数でしかないわけだが、関数的に扱えない。

Page 78: JenkinsとGitで実装するGatewayCheckIn Pattern #AsianAA

おまけ Jenkinsのダメなところ

•ジョブは関数でしかないわけだが、関数的に扱えない。•同一のジョブを複数実行できない。再帰呼び出しも出来ない。例えば次ができない

Page 79: JenkinsとGitで実装するGatewayCheckIn Pattern #AsianAA

おまけ Jenkinsのダメなところ

•ジョブは関数でしかないわけだが、関数的に扱えない。•同一のジョブを複数実行できない。再帰呼び出しも出来ない。例えば次ができない

• JobAAA repo1

Page 80: JenkinsとGitで実装するGatewayCheckIn Pattern #AsianAA

おまけ Jenkinsのダメなところ

•ジョブは関数でしかないわけだが、関数的に扱えない。•同一のジョブを複数実行できない。再帰呼び出しも出来ない。例えば次ができない

• JobAAA repo1• JobBBB repo1

Page 81: JenkinsとGitで実装するGatewayCheckIn Pattern #AsianAA

おまけ Jenkinsのダメなところ

•ジョブは関数でしかないわけだが、関数的に扱えない。•同一のジョブを複数実行できない。再帰呼び出しも出来ない。例えば次ができない

• JobAAA repo1• JobBBB repo1• JobBBB repo2

Page 82: JenkinsとGitで実装するGatewayCheckIn Pattern #AsianAA

おまけ Jenkinsのダメなところ

•ジョブは関数でしかないわけだが、関数的に扱えない。•同一のジョブを複数実行できない。再帰呼び出しも出来ない。例えば次ができない

• JobAAA repo1• JobBBB repo1• JobBBB repo2

•マスター/スレーブで実行しているときに、スレーブマシンでジョブ実行中には「Jenkins自体の情報」を取得できない。

Page 83: JenkinsとGitで実装するGatewayCheckIn Pattern #AsianAA

おまけ 現状のCIで何を選ぶべきか

Page 84: JenkinsとGitで実装するGatewayCheckIn Pattern #AsianAA

おまけ 現状のCIで何を選ぶべきか

•簡単にやりたい!!!

Page 85: JenkinsとGitで実装するGatewayCheckIn Pattern #AsianAA

おまけ 現状のCIで何を選ぶべきか

•簡単にやりたい!!!• Wercker, Travis.CI

Page 86: JenkinsとGitで実装するGatewayCheckIn Pattern #AsianAA

おまけ 現状のCIで何を選ぶべきか

•簡単にやりたい!!!• Wercker, Travis.CI

•オンプレミスで簡単にやりたい!!!

Page 87: JenkinsとGitで実装するGatewayCheckIn Pattern #AsianAA

おまけ 現状のCIで何を選ぶべきか

•簡単にやりたい!!!• Wercker, Travis.CI

•オンプレミスで簡単にやりたい!!!• TeamCity

Page 88: JenkinsとGitで実装するGatewayCheckIn Pattern #AsianAA

おまけ 現状のCIで何を選ぶべきか

•簡単にやりたい!!!• Wercker, Travis.CI

•オンプレミスで簡単にやりたい!!!• TeamCity

Page 89: JenkinsとGitで実装するGatewayCheckIn Pattern #AsianAA

おまけ 現状のCIで何を選ぶべきか

•簡単にやりたい!!!• Wercker, Travis.CI

•オンプレミスで簡単にやりたい!!!• TeamCity

•とにかく柔軟にやりたい!!!

Page 90: JenkinsとGitで実装するGatewayCheckIn Pattern #AsianAA

おまけ 現状のCIで何を選ぶべきか

•簡単にやりたい!!!• Wercker, Travis.CI

•オンプレミスで簡単にやりたい!!!• TeamCity

•とにかく柔軟にやりたい!!!• Jenkins

Page 91: JenkinsとGitで実装するGatewayCheckIn Pattern #AsianAA

おまけ 現状のCIで何を選ぶべきか

•簡単にやりたい!!!• Wercker, Travis.CI

•オンプレミスで簡単にやりたい!!!• TeamCity

•とにかく柔軟にやりたい!!!• Jenkins

Page 92: JenkinsとGitで実装するGatewayCheckIn Pattern #AsianAA

おまけ 現状のCIで何を選ぶべきか

•簡単にやりたい!!!• Wercker, Travis.CI

•オンプレミスで簡単にやりたい!!!• TeamCity

•とにかく柔軟にやりたい!!!• Jenkins

• Jenkinsよりいいものがほしい!!!

Page 93: JenkinsとGitで実装するGatewayCheckIn Pattern #AsianAA

おまけ 現状のCIで何を選ぶべきか

•簡単にやりたい!!!• Wercker, Travis.CI

•オンプレミスで簡単にやりたい!!!• TeamCity

•とにかく柔軟にやりたい!!!• Jenkins

• Jenkinsよりいいものがほしい!!!• Vert.x + Scala | Groovy

Page 94: JenkinsとGitで実装するGatewayCheckIn Pattern #AsianAA

おまけ 現状のCIで何を選ぶべきか

•簡単にやりたい!!!• Wercker, Travis.CI

•オンプレミスで簡単にやりたい!!!• TeamCity

•とにかく柔軟にやりたい!!!• Jenkins

• Jenkinsよりいいものがほしい!!!• Vert.x + Scala | Groovy•でつくるのが良いと思います。