早くなるという噂を聞いたので試しにやってみたら、少しだけ早くなりました。(8min→6min)
.circleci/config.yml
version: 2
jobs:
build:
docker:
- image: ruby
environment:
- TZ: "/usr/share/zoneinfo/Asia/Tokyo"
- LANG: ja_JP.UTF-8
- LC_ALL: C.UTF-8
- LANGUAGE: ja_JP.UTF-8
- image: circleci/mysql
environment:
- MYSQL_ROOT_PASSWORD:
working_directory: ~/repo
steps:
- checkout
- type: cache-restore
key: phantomjs-2.1.1
- type: cache-restore
key: repo-{{ checksum "Gemfile.lock" }}
- run: apt-get update
- run: apt-get install -y fonts-migmix
- run: |
which phantomjs && exit
curl --location --silent https://bitbucket.org/ariya/phantomjs/downloads/phantomjs-2.1.1-linux-x86_64.tar.bz2 | tar xj -C /tmp --strip-components=1
mv /tmp/bin/phantomjs /usr/local/bin/phantomjs
- run: bundle install -j 4 --path vendor/bundle
- type: cache-save
key: phantomjs-2.1.1
paths:
- /usr/local/bin/phantomjs
- type: cache-save
key: repo-{{ checksum "Gemfile.lock" }}
paths:
- vendor/bundle
- run: bundle exec rake db:create
- run: bundle exec ridgepole -E test -c config/database.yml --apply -f db/Schemafile --enable-migration-comments
- type: shell
command: |
bundle exec rspec --profile 10 \
--format RspecJunitFormatter \
--out /tmp/test-results/rspec.xml \
--format progress \
$(circleci tests glob "spec/**/*_spec.rb" | circleci tests split --split-by=timings)
- run: bundle exec rubocop -D -R -c .rubocop.yml
- type: store_artifacts
path: tmp/capybara/
destination: capybara
- type: store_test_results
path: /tmp/test-results
基本的には公式のものを参考に作りましたが、気をつけた点を少し紹介させていただきます。
Language Guide: Ruby - CircleCIcircleci.com
rubyはcircleci/ruby
を使わず、docker公式のものを採用
https://hub.docker.com/r/circleci/ruby/
CircleCIが用意してくれているDockerイメージがあって、git
やssh
やDockerツールが最初からインストールされていてと便利なのですが、phantomjsインストールして使用する際に少し面倒だったので、公式のものを使うようにしました。
mysqlの方はcircleci/mysql
を使っています。
https://hub.docker.com/r/circleci/mysql/
phantomjsのインストール
個人 Rails アプリを CircleCI 2.0 で動くようにした - アジャイルSEの憂鬱sinsoku.hatenablog.com
こちらのブログを参考にさせていただきました。
ありがとうございました。
ArgumentError: invalid byte sequence in US-ASCII
が出る対策
ArgumentError: invalid byte sequence in US-ASCII on v2.2.0 in Docker · Issue #277 · ffaker/ffaker · GitHubgithub.com
上記URLを参考に下記設定をしています。
environment:
- LANG: ja_JP.UTF-8
- LC_ALL: C.UTF-8
- LANGUAGE: ja_JP.UTF-8
featureスペックエラー時に保存しているスクリーンショットを見れるように
- type: store_artifacts
path: tmp/capybara/
destination: capybara
tmp/capybara
に保存したスクリーンショットをCircleCIのArtifactsから見れるようにしています。
まとめ
CIが少しでも早くなることは嬉しいですね。
まだβ版ですが使って見る価値はあるのではないでしょうか。