Ruby と Bitbucket Pipelines
このガイドでは、Bitbucket Pipelines を使用して、Docker コンテナで Ruby ソフトウェア プロジェクトをビルドおよびテストする方法について説明します。
If you'd prefer to quickly import a demo repository with a working pipeline to experiment with, have a look at our demo ruby repo.
プロジェクトを手動でセットアップしたい場合に、bitbucket-pipelines.yml ファイルを構成して Ruby プロジェクトをビルドおよびテストする方法を次に示します。
Docker で Ruby のバージョンを指定する
Bitbucket Pipelines runs all your builds in Docker containers using an image that you specify at the beginning of your configuration file. You can easily use Ruby with Bitbucket Pipelines by using one of the official Ruby Docker images on Docker Hub. If you use the default Ruby image it will come with the bundler installed by default to help you manage your dependencies.
たとえば、bitbucket-pipelines.yml ファイルの先頭で指定して、Ruby 2.4.0 を使用できます。
image: ruby:2.4.0
pipelines:
default:
- step:
script:
- ruby -vRuby の異なるバージョンを使用したい場合、Ruby Docker イメージのタグを変更します。次の例は、Ruby 2.3.3 のコンテナを開始します。
image: ruby:2.3.3You can find a list of all supported Ruby versions and corresponding image tags at https://hub.docker.com/r/library/ruby/.
Note that the Rails Docker images have been deprecated in favor of the standard Ruby images mentioned above.
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 installgem install コマンドで依存関係を明示的にインストールすることもできます。
image: ruby:2.4.0
pipelines:
default:
- step:
script:
- gem install railsデータベース
Bitbucket Pipelines allows you to launch extra services during the execution of your pipeline by defining the service, and instantiating it on the appropriate step.
We've created a list of examples of how to configure your bitbucket-pipeline.yml file for your favourite database.
テスト
ローカルでアプリケーションをテストするために使用したコマンドと同じものを、bitbucket-pipelines.yml ファイルに追加します。たとえば RSpec を使用している場合、次のように構成することで、依存関係をインストールしてテストを実行できます。
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_passwordRemember, you can check your bitbucket-pipelines.yml file with our online validator.
この内容はお役に立ちましたか?