2019年7月31日水曜日

[Codefresh] Parallel 実行してみた

Codefresh で並列実行が使えるようになっていたので試してみました。
Use parallel steps in your Codefresh pipelines - Codefresh
無料プランでももちろん並列実行できます。
試してみた結果
iutest で試してみた結果がこちら。
もともとしていた、「benchmark test」に加えて、gcc の複数バージョンの docker コンテナでテストを実行しています。


YAML はこちらです。
version: '1.0'
stages:
  - checkout
  - build
  - test

steps:
  main_clone:
    title: Cloning main repository...
    type: git-clone
    stage: checkout
    repo: '${{CF_REPO_OWNER}}/${{CF_REPO_NAME}}'
    revision: '${{CF_REVISION}}'
  BuildingDockerImage:
    title: Building Docker Image
    stage: build
    type: build
    image_name: srz-zumix/iutest
    working_directory: ./
    tag: '${{CF_BRANCH_TAG_NORMALIZED}}'
    dockerfile: ./tools/docker/Dockerfile
  RunningUnitTests:
    type: parallel
    stage: test
    steps:
      BasicTest-gcc9: &basic_test
        title: Running Basic Tests - gcc9
        image: gcc:9
        environment:
          - OUTDIR=gcc9
        commands:
          - mkdir test/${OUTDIR} || true
          - make -C test clean
          - make -C test test
      BasicTest-gcc8:
        <<: *basic_test
        title: Running Basic Tests - gcc8
        image: gcc:8
        environment:
          - OUTDIR=gcc8
      BasicTest-gcc7:
        <<: *basic_test
        title: Running Basic Tests - gcc7
        image: gcc:7
        environment:
          - OUTDIR=gcc7
      BenchmarkTest:
        title: Running Benchmark Tests
        image: '${{BuildingDockerImage}}'
        working_directory: IMAGE_WORK_DIR
        entry_point:
          - /bin/sh
          - /codefresh/volume/cf-generated/unit_test_script
        create_file:
          path: /codefresh/volume/cf-generated
          name: unit_test_script
          content: |-
            cd /codefresh/volume/iutest
            cd test
            make -C benchmark
            make bench
    on_success:
      metadata:
        set:
          - '${{BuildingDockerImage.imageId}}':
              - CF_QUALITY: true
    on_fail:
      metadata:
        set:
          - '${{BuildingDockerImage.imageId}}':
              - CF_QUALITY: false

※執筆時現在は構成が異なってます。
※さらに使ってみてどうだったのかは別途書きたいと思ってます。

やり方
上記の YAML を例に説明していきます。
詳細は公式のヘルプを見てもらったほうが良いと思います。
といっても基本的には type を parallel にするだけなんですけどね。

下記のように、type: parallel にしたら steps: 以下に並列実行するステップを書くだけです。
RunningUnitTests:
    type: parallel
    stage: test
    steps:
      BasicTest-gcc9: &basic_test


ハマったこと・感想など
以下は、導入してみて躓いたところと感想を書いていきます。
git-clone したパスは共有
並列コンテナで同じ場所を使います。
なので、作業が競合するような場合は注意が必要です。

iutest でも、ビルド結果の出力先が同じだったため問題になりました。
各並列コンテナごとにワークスペースを用意するなどしたほうが良さそうです。

キャッシュ
キャッシュがあるので、クリーンビルドを想定しているとハマるかもしれません。
https://codefresh.io/codefresh-news/parallel-pipelines/
Codefresh runs a git reset and a git clean in your project repository everytime a pipeline starts. This means that all artifacts that you wish to be cached should be in your .gitignore file. A common example would be the node_modules folder. If you don’t place it in .gitignore, it will be deleted at the start of each build making it much slower.
git reset; git clean を行うので、.gitignore で無視指定されているものは残ったままになります。

iutest ではたまたまテストのビルド結果が .gitignore にかかれていたため、キャッシュされていました。
これのおかげで爆速でテストできてました。
ただ、今は clean ビルドするようにしてます。
(※現在はどの程度のテストが並列でできるか検証しているので、ゆくゆくはキャッシュ使っていきたい)


明示的にクリーンビルドをしてあげる、またはキャッシュを利用してビルド速度を上げるなど、使いみちに合わせた運用が必要です。

Join ができる

まだ使ってないんですが、Join ができるのはかなり嬉しい
wercker で join ができないのがつらくてな・・・


最後に
(なぜか)、フリートライアル中なので今のうちにいろいろ試してみたいと思います。
また、Free Plan になったときのことも考えて検証していく予定。
(すでに、SMALL RESOURCE キツイ・・・となってるので頑張る予定・・・)

0 件のコメント:

コメントを投稿