rails 技術ブログ

rails 技術ブログ

勉強したことをアウトプットしていきます

AWSデプロイ時にAn error occurred while installing sassc (2.4.0), and Bundler cannot continue. Make sure that `gem install sassc -v '2.4.0' --source 'https://rubygems.org/'` succeeds before bundling.というエラーが出てきたら

capistranoを使ってAWSへのデプロイをしようと$ bundle exec cap production deploy を実行したところ、以下のエラーと遭遇しました。

cc1plus: out of memory allocating 1085312 bytes after a total of 18100224 bytes
make: *** [parser.o] エラー 1
make failed, exit code 2
Gem files will remain installed in
/var/www/Date_me/shared/bundle/ruby/2.6.0/gems/sassc-2.4.0 for inspection.
Results logged to
/var/www/Date_me/shared/bundle/ruby/2.6.0/extensions/x86_64-linux/2.6.0/sassc-2.4.0/gem_make.out
An error occurred while installing sassc (2.4.0), and Bundler cannot continue.
Make sure that `gem install sassc -v '2.4.0' --source 'https://rubygems.org/'`
succeeds before bundling.

検索しても解決方法が見つけられなかったため、備忘録として残しておきます。

①まず試したこと
エラメッセージの中に「 gem install sassc -v '2.4.0' --source 'https://rubygems.org/'を試してみてください」と書かれているので、まずはそれを実行

$ gem install sassc -v '2.4.0' --source 'https://rubygems.org/'

インストールが成功していることを確認し、再度$ bundle exec cap production deployを実行。

cc1plus: out of memory allocating 1085312 bytes after a total of 18100224 bytes
make: *** [parser.o] エラー 1
make failed, exit code 2
Gem files will remain installed in
/var/www/Date_me/shared/bundle/ruby/2.6.0/gems/sassc-2.4.0 for inspection.
Results logged to
/var/www/Date_me/shared/bundle/ruby/2.6.0/extensions/x86_64-linux/2.6.0/sassc-2.4.0/gem_make.out
An error occurred while installing sassc (2.4.0), and Bundler cannot continue.
Make sure that `gem install sassc -v '2.4.0' --source 'https://rubygems.org/'`
succeeds before bundling.

結果は変わらず…


考えられる原因としては「デプロイ時のsassコンパイルのタイミングでメモリが足りなくなり、落ちてしまっている」ことらしい。


②そこで次に実行したこと
足りないメモリの量を増やすためにインスタンスタイプを増やす

AWSにログインし、EC2のインスタンスをクリックする

f:id:terakura-aina:20210227154341p:plain

該当のインスタンスにチェックを入れ、「インスタンスの状態」をクリックし「インスタンスを停止」に変更

f:id:terakura-aina:20210227154515p:plain

停止したのが確認できたら、「インスタンスの状態」の隣にある「アクション」をクリックし、「インスタンスの設定」→「インスタンスタイプを変更」をクリックする
(インスタンスを停止していないとインスタンスタイプの変更ができないようになっています)

f:id:terakura-aina:20210227154704p:plain

そこで2段階ほど上のメモリを選択し、変更。
私の場合はmicroだったので、smallに変更しました。
インスタンスの状態」→「インスタンスを開始」ボタンを押し、インスタンスを起動させる。

ターミナルで$ bundle exec cap production deployを実行

これで出ていたエラーは消えました!