Rubyパイプラインの例

Updated 2 years ago by Admin

このガイドでは、Rubyプロジェクトの継続的インテグレーションパイプラインの構成について説明します。Droneを初めて使用する場合は、最初にチュートリアルとビルド構成ガイドをお読みください。


ビルドとテスト

以下の例では、bundle installrakeコマンドを実行するパイプラインを示しています。これらのコマンドは、実行時にDockerHubからダウンロードされたruby Dockerコンテナ内で実行されます。

kind: pipeline
name: default

steps:
- name: test
image: ruby
commands:
- bundle install --jobs=3 --retry=3
- rake

パイプラインでは、任意のDockerレジストリから任意のDockerイメージを使用できることに注意してください。公式のruby画像を使用することも、自分で持参することもできます。


依存関係

パイプラインを複数のステップに分割する場合は、各ステップがプロジェクトの依存関係にアクセスできることを確認する必要があります。依存関係は、共有ワークスペースの外部にある/usr/local/bundleにダウンロードされます。名前付きボリュームを作成して、このディレクトリをすべてのパイプラインステップと共有します。

kind: pipeline
name: default

steps:
- name: install
image: ruby
volumes:
- name: bundle
path: /usr/local/bundle
commands:
- bundle install --jobs=3 --retry=3

- name: test
image: ruby
volumes:
- name: bundle
path: /usr/local/bundle
commands:
- rake

volumes:
- name: bundle
temp: {}


複数のバージョンをテストする

Droneのマルチパイプライン機能を使用して、Rubyの複数のバージョンに対して同時にテストできます。これは、他の継続的インテグレーションシステムに見られるマトリックス機能と同等です。

---
kind: pipeline
name: ruby-2-4

steps:
- name: test
image: ruby:2.4
commands:
- bundle install --jobs=3 --retry=3
- rake

---
kind: pipeline
name: ruby-2-3

steps:
- name: test
image: ruby:2.3
commands:
- bundle install --jobs=3 --retry=3
- rake

...

この構文が冗長すぎる場合は、jsonnetを使用することをお勧めします。 jsonnetに慣れていない場合は、ガイドをお読みください。

local Pipeline(name, image) = {
kind: "pipeline",
name: name,
steps: [
{
name: "test",
image: image,
commands: [
"bundle install --jobs=3 --retry=3",
"rake"
]
}
]
};

[
Pipeline("ruby23", "ruby:2.3"),
Pipeline("ruby24", "ruby:2.4"),
]


複数のアーキテクチャをテストする

Droneのマルチパイプライン機能を使用して、複数のアーキテクチャとオペレーティングシステムでコードを同時にテストできます。

---
kind: pipeline
name: test-on-amd64

platform:
arch: amd64

steps:
- name: test
image: ruby
commands:
- bundle install --jobs=3 --retry=3
- rake

---
kind: pipeline
name: test-on-arm64

platform:
arch: arm64

steps:
- name: test
image: ruby
commands:
- bundle install --jobs=3 --retry=3
- rake

...

この構文が冗長すぎる場合は、jsonnetを使用することをお勧めします。 jsonnetに慣れていない場合は、ガイドをお読みください。


How did we do?