bundle updateしようとしたら、メモリが足りません。ってなったので、ディスクを拡張して、解決した流れ
やりたいこと
railsで作ったアプリをunicorn+nginx+MySQLでAWSでデプロイしたい。
起きている問題
bundle updateができない。
エラーまでの流れ
$ bundle update
[ryoji@ip-10-0-0-225 tempo]$ bundle update
Ignoring bootsnap-1.7.2 because its extensions are not built. Try: gem pristine bootsnap --version 1.7.2
・・・(略)
Using ffi 1.15.0
Fetching sassc 2.4.0
Installing sassc 2.4.0 with native extensions
Gem::Ext::BuildError: ERROR: Failed to build gem native extension.
current directory: /var/www/rails/tempo/vendor/bundle/ruby/2.6.0/gems/sassc-2.4.0/ext
/home/ryoji/.rbenv/versions/2.6.2/bin/ruby -I /home/ryoji/.rbenv/versions/2.6.2/lib/ruby/2.6.0 -r ./siteconf20210506-4298-1jp1qyu.rb extconf.rb
creating Makefile
current directory: /var/www/rails/tempo/vendor/bundle/ruby/2.6.0/gems/sassc-2.4.0/ext
make "DESTDIR=" clean
current directory: /var/www/rails/tempo/vendor/bundle/ruby/2.6.0/gems/sassc-2.4.0/ext
make "DESTDIR="
compiling ./libsass/src/ast.cpp
・・・(略)
compiling ./libsass/src/extender.cpp
virtual memory exhausted: Cannot allocate memory
make: *** [extender.o] Error 1
make failed, exit code 2
Gem files will remain installed in /var/www/rails/tempo/vendor/bundle/ruby/2.6.0/gems/sassc-2.4.0 for inspection.
Results logged to /var/www/rails/tempo/vendor/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.
In Gemfile:
bootstrap was resolved to 5.0.0, which depends on
sassc-rails was resolved to 2.1.2, which depends on
sassc
virtual memory exhausted: Cannot allocate memory
make: *** [color_maps.o] Error 1
とある。
これ、もしやメモリー不足?と思い、
https://qiita.com/HrsUed/items/c156ed69e927b6165717
の記事を参考に
[ryoji@ip-10-0-0-225 tempo]$ sudo dd if=/dev/zero of=/swap bs=1M count=2048
dd: error writing ‘/swap’: No space left on device
1396+0 records in
1395+0 records out
1462829056 bytes (1.5 GB) copied, 21.8857 s, 66.8 MB/s
No space left on deviceとあって、
そもそも、容量不足。
EC2インスタンスをt2.microからt2.smallに変更。
で、
[ryoji@ip-10-0-0-225 ~]$ sudo dd if=/dev/zero of=/swap bs=1M count=1024
[sudo] password for ryoji:
1024+0 records in
1024+0 records out
1073741824 bytes (1.1 GB) copied, 11.3893 s, 94.3 MB/s
[ryoji@ip-10-0-0-225 ~]$ sudo mkswap /swap
mkswap: /swap: insecure permissions 0644, 0600 suggested.
Setting up swapspace version 1, size = 1024 MiB (1073737728 bytes)
no label, UUID=715e25e0-06a3-4fd3-8142-8eb6183955ea
[ryoji@ip-10-0-0-225 ~]$ sudo swapon /swap
swapon: /swap: insecure permissions 0644, 0600 suggested.
[ryoji@ip-10-0-0-225 ~]$ sudo chmod 600 /swap
[ryoji@ip-10-0-0-225 ~]$ sudo swapon -s
Filename Type Size Used Priority
/swap file 1048572 0 -2
[ryoji@ip-10-0-0-225 ~]$ sudo vi /etc/fstab
で
/swap swap swap defaults 0 0
を追記
bundle updateしてみる
・・・
Bundler cannot continue installing libv8-node (15.14.0.1).
The checksum for the downloaded `libv8-node-15.14.0.1-x86_64-linux.gem` does not match the checksum given by the server. This means the
contents of the downloaded gem is different from what was uploaded to the server, and could be a potential security issue.
To resolve this issue:
1. delete the downloaded gem located at:
`/var/www/rails/tempo/vendor/bundle/ruby/2.6.0/gems/libv8-node-15.14.0.1-x86_64-linux/libv8-node-15.14.0.1-x86_64-linux.gem`
2. run `bundle install`
If you wish to continue installing the downloaded gem, and are certain it does not pose a security issue despite the mismatching checksum, do
the following:
1. run `bundle config set --local disable_checksum_validation true` to turn off checksum verification
2. run `bundle install`
(More info: The expected SHA256 checksum was "0c60592e11f23daaa9d0aa2f1ea9b94201e7d79216b0be6de9fc6d098cc18e13", but the checksum for the
downloaded gem was "b7a1df689493cfbaf85aa716dd5a2b57d7bc92ab848eb059e25d23fda48cd1e2".)
またしてもエラー
書いてある/var/www/rails/tempo/vendor/bundle/ruby/2.6.0/gems/libv8-node-15.14.0.1-x86_64-linux/libv8-node-15.14.0.1-x86_64-linux.gemを消そうとしても、その場所に存在しない。。
ので、
$ bundle config set --local disable_checksum_validation true
$ bundle install
Gem::Ext::BuildError: ERROR: Failed to build gem native extension.
current directory: /var/www/rails/tempo/vendor/bundle/ruby/2.6.0/gems/mini_racer-0.4.0/ext/mini_racer_extension
/home/ryoji/.rbenv/versions/2.6.2/bin/ruby -I /home/ryoji/.rbenv/versions/2.6.2/lib/ruby/2.6.0 -r ./siteconf20210506-4214-hxjszz.rb extconf.rb
Ignoring bootsnap-1.7.2 because its extensions are not built. Try: gem pristine bootsnap --version 1.7.2
・・・(略)
Ignoring unicorn-5.4.1 because its extensions are not built. Try: gem pristine unicorn --version 5.4.1
checking for -lpthread... yes
creating Makefile
current directory: /var/www/rails/tempo/vendor/bundle/ruby/2.6.0/gems/mini_racer-0.4.0/ext/mini_racer_extension
make "DESTDIR=" clean
current directory: /var/www/rails/tempo/vendor/bundle/ruby/2.6.0/gems/mini_racer-0.4.0/ext/mini_racer_extension
make "DESTDIR="
compiling mini_racer_extension.cc
cc1plus: warning: command line option ‘-Wimplicit-int’ is valid for C/ObjC but not for C++
・・・(略)
^
In file included from mini_racer_extension.cc:5:0:
/var/www/rails/tempo/vendor/bundle/ruby/2.6.0/gems/libv8-node-15.14.0.1-x86_64-linux/vendor/v8/include/v8.h:3719:37: note: declared here
V8_WARN_UNUSED_RESULT Maybe<bool> Set(Local<Context> context, uint32_t index,
mini_racer_extension.cc:556:78: warning: ignoring return value of ‘v8::Maybe<bool> v8::Object::Set(v8::Local<v8::Context>,
v8::Local<v8::Value>, v8::Local<v8::Value>)’, declared with attribute warn_unused_result [-Wunused-result]
convert_ruby_to_v8(isolate, context, rb_ary_entry(pair, 1)));
^
In file included from mini_racer_extension.cc:5:0:
/var/www/rails/tempo/vendor/bundle/ruby/2.6.0/gems/libv8-node-15.14.0.1-x86_64-linux/vendor/v8/include/v8.h:3716:37: note: declared here
V8_WARN_UNUSED_RESULT Maybe<bool> Set(Local<Context> context,
^~~
mini_racer_extension.cc: In function ‘VALUE rb_external_function_notify_v8(VALUE)’:
mini_racer_extension.cc:1165:46: warning: ignoring return value of ‘v8::Maybe<bool> v8::Object::Set(v8::Local<v8::Context>,
v8::Local<v8::Value>, v8::Local<v8::Value>)’, declared with attribute warn_unused_result [-Wunused-result]
.ToLocalChecked());
^
In file included from mini_racer_extension.cc:5:0:
/var/www/rails/tempo/vendor/bundle/ruby/2.6.0/gems/libv8-node-15.14.0.1-x86_64-linux/vendor/v8/include/v8.h:3716:37: note: declared here
V8_WARN_UNUSED_RESULT Maybe<bool> Set(Local<Context> context,
^~~
mini_racer_extension.cc:1190:58: warning: ignoring return value of ‘v8::Maybe<bool> v8::Object::Set(v8::Local<v8::Context>,
v8::Local<v8::Value>, v8::Local<v8::Value>)’, declared with attribute warn_unused_result [-Wunused-result]
.ToLocalChecked());
^
In file included from mini_racer_extension.cc:5:0:
/var/www/rails/tempo/vendor/bundle/ruby/2.6.0/gems/libv8-node-15.14.0.1-x86_64-linux/vendor/v8/include/v8.h:3716:37: note: declared here
V8_WARN_UNUSED_RESULT Maybe<bool> Set(Local<Context> context,
^~~
At global scope:
cc1plus: warning: unrecognized command line option ‘-Wno-self-assign’
cc1plus: warning: unrecognized command line option ‘-Wno-parentheses-equality’
cc1plus: warning: unrecognized command line option ‘-Wno-constant-logical-operand’
cc1plus: warning: unrecognized command line option ‘-Wno-cast-function-type’
linking shared-object mini_racer_extension.so
current directory: /var/www/rails/tempo/vendor/bundle/ruby/2.6.0/gems/mini_racer-0.4.0/ext/mini_racer_extension
make "DESTDIR=" install
/usr/bin/install -c -m 0755 mini_racer_extension.so ./.gem.20210506-4214-12d0wd6
/usr/bin/install: error writing ‘./.gem.20210506-4214-12d0wd6/mini_racer_extension.so’: No space left on device
/usr/bin/install: failed to extend ‘./.gem.20210506-4214-12d0wd6/mini_racer_extension.so’: No space left on device
make: *** [install-so] Error 1
make install failed, exit code 2
Gem files will remain installed in /var/www/rails/tempo/vendor/bundle/ruby/2.6.0/gems/mini_racer-0.4.0 for inspection.
Results logged to /var/www/rails/tempo/vendor/bundle/ruby/2.6.0/extensions/x86_64-linux/2.6.0/mini_racer-0.4.0/gem_make.out
An error occurred while installing mini_racer (0.4.0), and Bundler cannot continue.
Make sure that `gem install mini_racer -v '0.4.0' --source 'https://rubygems.org/'` succeeds before bundling.
In Gemfile:
mini_racer
[ryoji@ip-10-0-0-225 node]$ gem install mini_racer -v '0.4.0' --source 'https://rubygems.org/'
Fetching libv8-node-15.14.0.1-x86_64-linux.gem
Fetching mini_racer-0.4.0.gem
#<Thread:0x0000000001a430c0@/home/ryoji/.rbenv/versions/2.6.2/lib/ruby/2.6.0/rubygems/request_set.rb:168 run> terminated with exception (report_on_exception is true):
Traceback (most recent call last):
8: from /home/ryoji/.rbenv/versions/2.6.2/lib/ruby/2.6.0/rubygems/request_set.rb:174:in `block (2 levels) in install'
7: from /home/ryoji/.rbenv/versions/2.6.2/lib/ruby/2.6.0/rubygems/resolver/specification.rb:101:in `download'
6: from /home/ryoji/.rbenv/versions/2.6.2/lib/ruby/2.6.0/rubygems/source.rb:206:in `download'
5: from /home/ryoji/.rbenv/versions/2.6.2/lib/ruby/2.6.0/rubygems/remote_fetcher.rb:158:in `download'
4: from /home/ryoji/.rbenv/versions/2.6.2/lib/ruby/2.6.0/rubygems/remote_fetcher.rb:305:in `cache_update_path'
3: from /home/ryoji/.rbenv/versions/2.6.2/lib/ruby/2.6.0/rubygems.rb:876:in `write_binary'
2: from /home/ryoji/.rbenv/versions/2.6.2/lib/ruby/2.6.0/rubygems.rb:876:in `open'
1: from /home/ryoji/.rbenv/versions/2.6.2/lib/ruby/2.6.0/rubygems.rb:881:in `block in write_binary'
/home/ryoji/.rbenv/versions/2.6.2/lib/ruby/2.6.0/rubygems.rb:881:in `write': No space left on device @ io_write - /home/ryoji/.rbenv/versions/2.6.2/lib/ruby/gems/2.6.0/cache/libv8-node-15.14.0.1-x86_64-linux.gem (Errno::ENOSPC)
ERROR: While executing gem ... (Errno::ENOSPC)
No space left on device @ io_write - /home/ryoji/.rbenv/versions/2.6.2/lib/ruby/gems/2.6.0/cache/libv8-node-15.14.0.1-x86_64-linux.gem
結局、デバイス容量足りないからできない!
って言われた(泣)
ちなみに $ df で見てみてると
$ df
[ryoji@ip-10-0-0-225 ~]$ df
Filesystem 1K-blocks Used Available Use% Mounted on
devtmpfs 1008776 0 1008776 0% /dev
tmpfs 1019544 0 1019544 0% /dev/shm
tmpfs 1019544 412 1019132 1% /run
tmpfs 1019544 0 1019544 0% /sys/fs/cgroup
/dev/xvda1 8376300 8374968 1332 100% /
tmpfs 203912 0 203912 0% /run/user/1000
解決策
結論、単純にAWSのコンソールにログインして、ディスク容量を拡張して解決。
自分の知識不足で
「EBSを追加でアタッチ→マウント」
とかしないとダメかと思ってAWSのドキュメントを読みあさったのですが、別にEBS追加しなくとも、今アタッチしているボリュームのディスク容量を拡張することで解決しました。
ディスク容量拡張の手順
まず、AWSのコンソールにログイン。
該当インスタンスの停止
↓
該当インスタンスの「ストレージ」選択
↓
「ブロックデバイス」の「ボリュームID」選択
↓
「アクション」→「スナップショットの作成」(念のため)→「ボリュームの変更」
↓
インスタンス再起動
で、再び
$ df
[ec2-user@ip-10-0-0-225 ~]$ df
ファイルシス 1K-ブロック 使用 使用可 使用% マウント位置
devtmpfs 479236 0 479236 0% /dev
tmpfs 490008 0 490008 0% /dev/shm
tmpfs 490008 612 489396 1% /run
tmpfs 490008 0 490008 0% /sys/fs/cgroup
/dev/nvme0n1p1 16764908 8587480 8177428 52% /
tmpfs 98004 0 98004 0% /run/user/1000
ちゃんと増えてる!
で、無事にbundle updateできました。