LoginSignup
28
28

More than 5 years have passed since last update.

Rails, Ruby 2.1.0, PostgreSQL, RSpec, Cucumber, PhaontomJS, HipChatの組み合わせでwerckerを使って気軽にCIする

Last updated at Posted at 2014-02-10

今年の頭にWantedlyのCIサーバはJenkinsからwerckerになりました。βテスト中ということもあってGitHubのprivateレポジトリに対しても無料で使えるのですが、僕らの規模だと十分実用的に使えて満足しています。

個人プロジェクトでカジュアルにCIしたい時などにもオススメ。

ちなみに、Herokuなどへのdeploymentも自動化できるのですが、そのあたりのContinuous Deploymentまわりの機能は使っていません。

基本的にはwercker.ymlをレポジトリ直下に作成するだけで設定できます。実際に使っているwercker.ymlが以下にあるので参照してください。

CircleCIだとレポジトリの内容から設定ファイルもある程度自動生成してくれたりして便利なのですが(例えば、RailsでRSpec使ってることを検出してそれ用の設定ファイルを自動生成してくれる)、そのあたりの初回の使い勝手に関してはwerckerはまだ成熟してない印象ですね。

box: fliplingo/ubuntu12.04-ruby2.1.0@0.0.1
# Build definition
# See the Rails section on the wercker devcenter:
# http://devcenter.wercker.com/articles/languages/ruby/rails-heroku.html
# You will want to define your database as follows:
services:
  - wercker/postgresql
# See more about services on our devcenter:
# http://devcenter.wercker.com/articles/services/
build:
    # The steps that will be executed on build
    steps:
        - script:
            name: set timezone
            code: |
                export TZ="Asia/Tokyo"
        # A step that executes `bundle install` command
        - bundle-install
        # A custom script step, name value is used in the UI
        # and the code value contains the command that get executed
        - script:
            name: echo ruby information
            code: |
                echo "ruby version $(ruby --version) running"
                echo "from location $(which ruby)"
                echo -p "gem list: $(gem list)"
        # Add more steps here:
        # A step that prepares the database.yml using the database in services
        - rails-database-yml
        # Install phantomjs
        - aussiegeek/install-phantomjs@0.0.3
        # Initialize test database
        - script:
            name: set up db
            code: |
                RAILS_ENV='test' bundle exec rake db:create
                RAILS_ENV='test' bundle exec rake db:schema:load
        # Run rspec
        - script:
            name: rspec
            code: bundle exec rspec
        # Run cucumber
        - script:
            name: cucumber
            code: bundle exec cucumber
    after-steps:
        # Send a message to a HipChat room
        - wercker/hipchat-notify@1.0.2:
            token: $HIPCHAT_TOKEN
            room-id: 64340

ポイント

  • 公式のBoxだとRuby 2.0.0なので、Ruby 2.1.0を使うためにコミュニティのBoxを使う。
  • HipChatへの通知はafter-stepsでやらないとfailしたときに通知されない。access tokenをwercker側で環境変数に設定する必要がある
28
28
2

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
28
28