Ruby と Bitbucket Pipelines
このガイドでは、Bitbucket Pipelines を使用して、Docker コンテナで Ruby ソフトウェア プロジェクトをビルドおよびテストする方法について説明します。
実際に動作するパイプラインを持つデモ リポジトリをインポートしたい場合、デモ用の ruby リポジトリをご参照ください。
If you'd like to set it up by hand, here's how you can configure the bitbucket-pipelines.yml
file to build and test a Ruby project.
Docker で Ruby のバージョンを指定する
Bitbucket Pipelines は、構成ファイルの最初に指定したイメージを使用し、すべてのビルドを Docker コンテナで実行します。Docker Hub にあるいずれかの公式 Ruby Docker イメージを使用して、Bitbucket Pipelines で簡単に Ruby を使用できます。デフォルトの Ruby イメージを使用する場合、依存関係の解決に役立つ pip がデフォルトでインストールされています。
For instance, you can use Ruby 2.4.0 by specifying it at the beginning of your bitbucket-pipelines.yml
file:
image: ruby:2.4.0
pipelines:
default:
- step:
script:
- ruby -v
Ruby の異なるバージョンを使用したい場合、Ruby Docker イメージのタグを変更します。次の例は、Ruby 2.3.3 のコンテナを開始します。
image: ruby:2.3.3
サポートされる Ruby バージョンと対応する image タグの一覧については、https://hub.docker.com/r/library/ruby/ をご参照ください。
前述の標準 Ruby イメージのため、Rails Docker イメージは更新が停止されています。
You can check your bitbucket-pipelines.yml
file with our online validator.
依存関係をインストールする
Gemfile を使用している場合、スクリプトの最初で bundle install
を実行することで、すべての依存関係を簡単にインストールできます。
image: ruby:2.4.0
pipelines:
default:
- step:
script:
- bundle install
gem install
コマンドで依存関係を明示的にインストールすることもできます。
image: ruby:2.4.0
pipelines:
default:
- step:
script:
- gem install rails
データベース
Bitbucket Pipelines では、サービスを定義して適切な段階でインスタンス化することで、パイプラインの実行中に追加のサービスを起動できます。
We've created a list of examples of how to configure your bitbucket-pipeline.yml
file for your favourite database.
テスト
You simply need to add to your bitbucket-pipelines.yml
file the same commands that you would run locally to test your application. For instance, if you are using RSpec the following configuration would install your dependencies and then run your tests:
image: ruby:2.4.0
pipelines:
default:
- step:
script:
- bundle install
- rspec
If you are building a Rails application it is highly likely that you will require a database to run your tests. We've created a list of examples of how to configure your bitbucket-pipeline.yml
.
たとえば、パイプラインの一部として PostgreSQL データベースを構成する方法は次のようになります。
bitbucket-pipelines.yml
image: ruby:2.3.1
pipelines:
default:
- step:
script: # Modify the commands below to build your repository.
- export DATABASE_URL=postgresql://test_user:test_user_password@localhost/pipelines
- bundle install
- rake db:setup
- rake db:test:prepare
- rspec
services:
- postgres
definitions:
services:
postgres:
image: postgres
environment:
POSTGRES_DB: pipelines
POSTGRES_USER: test_user
POSTGRES_PASSWORD: test_user_password
Remember, you can check your bitbucket-pipelines.yml
file with our online validator.
この内容はお役に立ちましたか?