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を使っても良いのかもしれない

31 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. شركة نقل عفش
    اهم شركات مكافحة حشرات بالخبر كذلك معرض اهم شركة مكافحة حشرات بالدمام والخبر والجبيل والخبر والاحساء والقطيف كذلك شركة رش حشرات بالدمام ومكافحة الحشرات بالخبر
    شركة مكافحة حشرات بالدمام
    شركة تنظيف خزانات بجدة الجوهرة من افضل شركات تنظيف الخزانات بجدة حيث ان تنظيف خزانات بجدة يحتاج الى مهارة فى كيفية غسيل وتنظيف الخزانات الكبيرة والصغيرة بجدة على ايدى متخصصين فى تنظيف الخزانات بجدة
    شركة تنظيف خزانات بجدة
    شركة كشف تسربات المياه بالدمام
    شركة نقل عفش واثاث

    ReplyDelete
  4. 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
  5. 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
  6. This comment has been removed by the author.

    ReplyDelete
  7. 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

  8. 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
  9. This comment has been removed by the author.

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

    Togel Online

    Agen Togel

    ReplyDelete
  11. Webroot.com/safe is a protection software solution that communicates with the cloud avoiding the hassle to manage the signature updates to deploy. for office setup visit office.com/setup

    ReplyDelete
  12. 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
  13. 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
  14. 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
  15. Cartoon HD has its own features like it gives you trending videos,
    featured videos and Download Cartoon HD Apk section.
    You can tap on it to open and choose the video right away.
    No need for television or big screen it works in your devices in very good quality. It's easy to attempt all the videos any time when you want to do.

    ReplyDelete
  16. 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.