LoginSignup
4
1

More than 5 years have passed since last update.

wercker classic to workflows 乗り換え備忘録 Railsアプリ編

Posted at

概要

かなり前からwerckerさんはDockerベースの環境を出していたようなんだけど、移行を後回しにしていたらとうとう通知が画面に出てきた。すみませんやります。

Classic apps are being deprecated. You need to migrate ASAP. For more information see our devcenter article

devcenter articleはこちら↓
http://devcenter.wercker.com/docs/migrating-to-workflows-from-classic

紹介されている"The migration process"のうち、1番の手段を実施することにしました。

  1. Migrate your application via the migration wizard and update your wercker.yml as directed here.

参考URL

まず、言われたとおりにmigrationする

Migrate your application via the migration wizard

werckerが準備してくれているClassic app migratorページで、対象にチェックをつけてMigrateボタンをポチりました。
https://app.wercker.com/applications/migrate

かなりデザインが変わって驚き :exclamation:
とりあえずこれは何事もなく完了しました。

次に、wercker.yml を修正する

... and update your wercker.yml as directed here.

wercker.yml は昔のままだと使えないので、新しい設定に書き換えました。
wercker.ymlの修正 > commit > push > werckerでの失敗内容を確認してまたwercker.ymlを修正...をしばらく繰り返します。
gitのcommitログが汚れるので、branch切って最後に動くのが確認できてから git rebase -i で1つにまとめるのが常套手段ですね。
書き換えていく道中で詰まったところについてまとめていきます。
(また、できるだけ現状維持したいという目標があったので、gemバージョンが古いなどの部分がありますがご容赦ください :bow:

gem install json -v 1.8.3 で失敗

bundle install の時点でエラー。

An error occurred while installing json (1.8.3), and Bundler cannot continue.
Make sure that `gem install json -v '1.8.3'` succeeds before bundling.

wercker.ymlでcmakeを入れて、jsonのgemのバージョンを1.8.6にあげたところ解決した。
(cmakeはもしかしたら本当はjsonのgemとは関係なくて、RSpecの実行とかに影響したかも...)

$ bundle update json

$ vim Gemfile.lock
> json (1.8.6)
wercker.yml
build:
    steps:
        - wercker/install-packages@1.0.0
        - install-packages:
            packages: cmake
        - bundle-install

xmlrpc/client が無いと怒られる

rake aborted!
LoadError: cannot load such file -- xmlrpc/client

Gemfileに追加記入でなおった。
参考: https://rcmdnk.com/blog/2017/01/19/computer-wercker/

Gemfile
if Gem::Version.new(RUBY_VERSION) >= Gem::Version.new('2.4.0')
  gem 'xmlrpc', '~> 0.2'
end

coffee-rails入れる時に失敗

rake aborted!
Bundler::GemRequireError: There was an error while trying to load the gem 'coffee-rails'.
Gem Load Error is: Could not find a JavaScript runtime. See https://github.com/rails/execjs for a list of available runtimes.

gem 'therubyracer' を導入することでなおった。
でもwerckerさんのためだけに適用するのもちょっと嫌だったので、test環境だけに絞った。

Gemfile
group :test do
  gem 'therubyracer' # for wercker
end

Could not load database configuration. No such file - ["config/database.yml"]

すみませんでした。
リポジトリ内に.gitignoreしていた設定ファイル類があった。
ファイルはコピーしてあげよう。

wercker.yml
- script:
    name: set initializer
    code: |
        cp config/twitter_api_keys.yml.example config/twitter_api_keys.yml
        cp config/fb_api_keys.yml.example config/fb_api_keys.yml
        cp config/database.yml.example config/database.yml

.s.PGSQL.5432 がありませんと怒られる

rake aborted!
PG::ConnectionBad: could not connect to server: No such file or directory
    Is the server running locally and accepting
    connections on Unix domain socket "/var/run/postgresql/.s.PGSQL.5432"?

postgresqlのsocketについて怒られている様子。
- 参考: http://devcenter.wercker.com/docs/services/postgresql
- 参考: connections on Unix domain socket "/var/pgsql_socket/.s.PGSQL.5432"? - Qiita

wercker.ymlのstepsでpostgresql-dockerを指定することで解決した。

wercker.yml
- rails-database-yml:
    service: postgresql-docker

Redisにつながらないと怒られる

RSpec実行中にエラー。

Error connecting to Redis on 127.0.0.1:6379 (Errno::ECONNREFUSED)

とか

Checking if service redis is reachable at 10.2.71.35:6379.
..........
Could not connect to service redis 

とか。

wercker側から提供される環境変数の名前が変わったのが原因だった。
configなどに記入されている ENV["WERCKER_REDIS_HOST"]ENV["REDIS_PORT_6379_TCP_ADDR"] に差し替えた。

config/initializers/redis.rb
require 'redis'
Redis.current =
  Redis.new(host: ENV["REDIS_PORT_6379_TCP_ADDR"] || '127.0.0.1', port: 6379)

おまけ env一覧をチェック

なにか環境変数周りで上手くいかない場合はチェックすると幸せになれそう。

wercker.yml
build:
  steps:
    - script:
        name: env
        code: env

wercker_env.png

最終的なwercker.yml

wercker.yml
box: ruby:2.3.1
services:
    - postgres
    - redis

build:
    steps:
        - wercker/install-packages@1.0.0
        - install-packages:
            packages: cmake
        - bundle-install
        - script:
            name: set initializer
            code: |
                cp config/twitter_api_keys.yml.example config/twitter_api_keys.yml
                cp config/fb_api_keys.yml.example config/fb_api_keys.yml
                cp config/database.yml.example config/database.yml
        - script:
            name: echo ruby information
            code: |
                echo "ruby version $(ruby --version) running"
                echo "from location $(which ruby)"
                echo -p "gem list: $(gem list)"
        - rails-database-yml:
            service: postgresql-docker
        - script:
            name: Set up db
            code: bundle exec rake db:schema:load RAILS_ENV=test
        - script:
            name: env
            code: env
        - script:
            name: rspec
            code: bundle exec rspec --fail-fast
    after-steps:
        - install-packages:
            packages: ruby
        - wantedly/pretty-slack-notify:
            webhook_url: $SLACK_WEBHOOK_URL

:thought_balloon: 本当はpipelineを付け足して自動デプロイとかまでやらないと美味しさが少ない感じがするんですが、一旦ここまで...。

4
1
0

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
4
1