LoginSignup
8

More than 1 year has passed since last update.

posted at

Ruby on Rails 6のbundle installが重すぎる

Ruby on Rails 6にしてから、bundle installにかなり時間がかかるようになってしまった。
Dockerを使って開発・デプロイをしているのだが、新規作成したばかりのプロジェクトでもCloud Build上でのビルドに10分以上かかってしまう状況だ。

原因: sasscのインストールが遅い

調べてみるとbundle installで発生する時間のうち、ほとんどの時間はsasscのインストールで発生している。同様の報告は多数上がっている。

sass/sassc-ruby - sassc is very slow to compile and install #189

Up to version 2.1.0, sassc shipped precompiled Linux binaries, but as of 2.2.0, the only precompiled versions are for mingw32.
...
In the meantime, a workaround might be to pin sassc-ruby to version 2.1.0.

Rails: Why is bundle install frozen up by sassc 2.4.0

Using an older version of sass solves the issue. I advise changing 6 to 5.1.0 in the Gemfile. This file will be located in your rails folder (the name you used when creating a new rails)

sassc 2.2.0以降でmigw32用以外のコンパイル済みバイナリが含まれなくなり、linux系の環境ではbundle install時にネイティブビルドが発生することが直接的な原因のようだ。どうやら不具合ではなく、意図的にLinux系のコンパイル済みバイナリを含めるのをやめたようだ。

対策: 古いバージョンのsasscを指定するか、sass-railsのバージョンを下げる

ワークアラウンドとして、sasscの2.1系を使うかsasscに依存しているsass-railsのバージョンを下げる方法が紹介されている。
基本的にはsasscのバージョンを下げる方が影響範囲が小さくて良さそうだ。
sass-rails(が参照しているsassc-rails)の最新版のdependencyをみると、必要なsasscのバージョンは「2.0以上」となっているので、2.1に下げることは可能だ。

# Use SCSS for stylesheets
gem 'sassc', '2.1.0'
gem 'sass-rails', '6'

結果: Cloud Buildでのビルド時間は10分から4分に短縮

sasscのバージョンを2.1に下げたことで、bundle installにかかる時間が大幅に短くなった。Cloud Buildでのビルドでも、10分かかっていたものが4分まで短縮され、大分開発・デプロイが快適になった。

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
What you can do with signing up
8