Thursday, December 28, 2017

CI 用 Docker イメージ作成におけるベストプラクティス

H2O の CI では長らく、秘伝のタレ的な .travis.yml を使い続けてきたのですが、なにぶん依存関係が多いもので、だいぶメンテナンスが辛い感じになってきていました。また、CI テストで発生したエラーの調査の度に、時間のかかる CI を回さなければならないことが、開発者のストレスとなっていました。

そこで一念発起して、Docker イメージを使った CI に切り替えることにしました(実行環境としては引き続き Travis を使います)。

その際に、要件として以下のようなことを考えました。
  • CI以外に、コミット前のテストにも使えるようなイメージにすること
  • コマンド一発でビルドとテストが動作すること
  • 無駄な処理をしないこと

その結果、以下のような実装になりました。
  • テストに必要なソフトウェア群をインストールしたイメージを Docker Hub にアップロードしておく
  • テストには、1. テスト用コンテナにコードのあるディレクトリをマウントし、2. アウトオブトリービルド注1とテストを実行するスクリプトを書く
  • CI環境では、そのスクリプトを実行する
  • 開発者がローカルでそのスクリプトを実行してテストしてもよい

Dockerfile および CI 実行用のスクリプトは、H2O のレポジトリにある以下のファイルです。

結果、Docker 導入前に90行あった .travis.yml は23行にまで短くなり、また、CI に必要な時間も2割ほど減少しました(CI を実行するたびに、必要なソフトウェアをビルドする手間が不要になったため)。

また、開発者が各個人の環境において make -f misc/docker-ci/check.mkmake を実行するだけで、いつでも(コミット前でも)CI 環境と同様のテストが実行できるようになりました。テストが失敗したら、コンテナを立ち上げっぱなしにして、ローカルでコード修正&特定のテスト再実行を繰り返すことも可能なので、バグ修正が捗ります。

まとめ:CI 用の Docker イメージを作るのではなく、テスト用の CI イメージを作り、それを CI に展開すべき

言わずもがなかもしれませんが、備忘録としてまとめておきます。


注1: ソースディレクトリ以外の場所に生成物を配置するビルド手法のこと。アウトオブトリービルドができない場合はaufsを使っても良いのかもしれない

24 comments:

  1. f you are also looking for funny WhatsApp DP collection of any WhatsApp profile pictures then you are at the best place on the internet.

    ReplyDelete
  2. I like your topic of selection for blog but want to suggest you for sharing some more information regarding your subject so that we can understand your thought more clearly
    abcya | brainpop| hooda

    ReplyDelete
  3. Blog entry is quite good but the comments are the different from the blog.

    But yeah, it can be useful for everyone to share their sites.

    Free Movies

    ReplyDelete
  4. UFC Fight Night where fans can get the latest Mixed Martial Arts (MMA) news, watch live streaming video, learn about upcoming events, view fighter profiles, and more.

    UFC Fight Night
    UFC Fight Pass
    Watch UFC Fight Night
    UFC Fight Night Live
    UFC Fight Night Live Stream

    The Cleveland Cavaliers, often referred to as the Cavs, are an American professional basketball team based in Cleveland, Ohio. The Cavs compete in the National Basketball Association as a member of the league's Eastern Conference Central Division.

    Cavs Game
    Watch Cavs Game
    Cavs Game Live
    Cavs Game Live Stream
    Cavs Game Online

    The National Basketball Association is a men's professional basketball league in North America; composed of 30 teams. It is widely considered to be the premier men's professional basketball league in the world.

    NBA Games Today
    NBA Games Reddit
    NBA Games Tonight
    NBA Games Online
    NBA Games Live
    NBA Games Live Stream

    ReplyDelete
  5. This comment has been removed by the author.

    ReplyDelete
  6. Uploaded by ufcespanol
    tmb I know another one called Bellator and Pancrase (the latter from Japan I think) but if it's jerky to see the fights of
    UFC Fight Night online
    Watch UFC Fight Night Live Stream
    ufc fights free online
    Werdum vs Volkov live
    UFC Fight Night live stream
    Werdum vs Volkov live stream
    free ufc live stream
    watch ufc fight night free
    ufc fight tonight live for free
    UFC Fight Pass
    Watch UFC Fight Night
    UFC Fight Night Live Stream
    UFC (Ultimate Fighting Championship): Miesha Tate, from living in a
    elconfidential miesha tate ufc martial arts

    ReplyDelete

  7. Hmm is anyone else encountering problems with the pictures on this blog loading? I'm trying to determine if its a problem on my end or if it's the blog. Any responses would be greatly appreciated. gmail email login

    ReplyDelete
  8. This comment has been removed by the author.

    ReplyDelete
  9. I like to read your article because it really helps me. Thank you for sharing this post with us.

    Togel Online

    Agen Togel

    ReplyDelete
  10. Hi, I am Anirudh. I am a Fitness trainer by profession. Are you looking forward to loose you weight. Check here to check few of program penurunan berat badan that would be helpful for you.

    ReplyDelete
  11. Techgara with a thoughtful, human-centred take on technology and the web. Discover purpose-driven people, products, and ideas that shape the digital world.

    ReplyDelete
  12. Want to download your own Facebook videos or those posted by your friends? Video downloader for Facebook by FB2Mate is provided for you to download public and even private videos.

    ReplyDelete
  13. aostv and redboxtv is one of the best app to watch live tv channels.
    You can use both aos tv windows and redbox tv windows on your windows pc/laptop.

    ReplyDelete

Note: Only a member of this blog may post a comment.