CircleCI 2.0 が使えるようになっていたので、アップグレードしておいた。
CircleCI の設定
今まで circle.yml だったけど、 .circleci/config.yml に変わっている。
Ruby の設定例は Language Guide: Ruby があるので、これを参考にすると良い。
version: 2 jobs: build: docker: - image: ruby:2.4.0 - image: postgres - image: redis environment: PHANTOMJS_URL: https://bitbucket.org/ariya/phantomjs/downloads/phantomjs-2.1.1-linux-x86_64.tar.bz2 working_directory: ~/workspace steps: - checkout - type: cache-restore key: phantomjs-2.1.1 - type: cache-restore key: gemfile-{{ checksum "Gemfile.lock" }} - run: | which phantomjs && exit curl --location --silent $PHANTOMJS_URL | tar xj -C /tmp --strip-components=1 mv /tmp/bin/phantomjs /bin - run: apt-get update -qq && apt-get install -y build-essential nodejs - run: bin/setup - run: rake - run: yard -o doc - store_artifacts: path: doc destination: doc - type: cache-save key: phantomjs-2.1.1 paths: - /bin/phantomjs - type: cache-save key: gemfile-{{ checksum "Gemfile.lock" }} paths: - /usr/local/bundle
注意点は デフォルトだと bundler の cache が効かない とか、 PhantomJS が入っていない とかくらい?
bin/setup の実行
Language Guide: Ruby の例に合わせて db:create db:schema:load を実行して db:migrate を実行しない方が少し速くなると思う。
ただ、 bin/setup が動作するのをチェックしたくて CI で毎回動かすようにしている。
Rakefile
Rakefile に下記のような定義をしていて、 rake を実行すると rubucop + parallel:spec が動くようにしている。
# frozen_string_literal: true
# Add your own tasks in files placed in lib/tasks ending in .rake,
# for example lib/tasks/capistrano.rake, and they will automatically be available to Rake.
require File.expand_path('../config/application', __FILE__)
Rails.application.load_tasks
unless Rails.env.production?
require 'rubocop/rake_task'
RuboCop::RakeTask.new
task(:default).clear
task default: [:rubocop, 'parallel:spec']
end
改善できそうなところ
Using docker-compose や background を使えば、もうちょい改善とか実行速度アップとかできるかも?
まぁ、そのあたりは時間あるときに試す。時間あるときに。