LoginSignup
2
4

More than 3 years have passed since last update.

cloud9でgit cloneしrailsチュートリアルを再開する流れ

Posted at

railsチュートリアルをcloud9で順調に進めるも、容量不足で先に進めなくなりました。
AWS Cloud9 の容量不足を解決する
上記記事を参考にするも、hello_appやtoy_appを作成していなかった私は消せるファイルがありません(笑)

$ sudo growpart /dev/xvda 1

上記コマンドがどうしても実行できなかったため、新しいenvironmentを作成してgit cloneをすることにしました。

参照 : Railsチュートリアル

AWSで新しいワークスペースを作成する

1.Cloud9の管理ページに行く。
2.Create environmentをクリック。
3.(AmazonLinuxではなく)UbuntuServerを選択し、Next stepをクリック。

ボリュームを拡張する

忘れないうちにやってしまいましょう!

1.AmazonEC2コンソールを開く。
2.「ボリューム」を選択し、変更するボリュームを選択。
3.上部にある「アクション」ボタンから「ボリュームの変更」を選択し、サイズを AWS が定める最大無料枠に設定(10→30)
4.「インスタンス」で、該当のインスタンスを選択後、画面上部にある「アクション」ボタンから「再起動」をする。
5.Cloud9に戻り、ターミナルからボリュームを拡張する。
6.lsblkコマンドで、現在のインスタンスに割り当てられているブロックデバイスの情報を確認する。(ルートボリュームである/dev/xvdaは拡張されているが、/dev/xvda1は10のままになっている。)
7."$ sudo growpart /dev/xvda 1" コマンドの実行
8."$ sudo resize2fs /dev/xvda1" コマンドの実行
9.lsblkコマンドで、/dev/xvda1が30になっているか確認する。

Railsをインストールする

下記コマンドを順に実行していく。

$ echo "gem: --no-document" >> ~/.gemrc
$ gem install rails -v 6.0.3
$ source <(curl -sL https://cdn.learnenough.com/yarn_install)

※RubyやRailsのバージョンを、GitHubの「README.md」から確認し揃えましょう。

$ ruby -v
$ rails -v

git cloneを実行

※herokuを使われている場合、git cloneではなく、heroku git:clone --appをされた方が早いかもしれません。

$ git clone [クローンするソースコードのURL]
$ bundle install --without production
$ rails db:create
$ rails db:migrate
$ rails test

ちなみにrails testを実行したらこんなエラーが出ました。

FATAL: Listen error: unable to monitor directories for changes.

下記の記事通りにコマンドを実行し解決。
Rails testで「 FATAL: Listen error: unable to monitor directories for changes.」のエラー

heorokuのセットアップ

既存のherokuのアプリにつなげる方法がよく分かりませんでした。
そのため1から作ります。

まずはherokuのインストールから

$ source <(curl -sL https://cdn.learnenough.com/heroku_install)

一応インストールされているか確認

$ heroku --version
$ heroku login
$ heroku create

herokuへデプロイ

$ git push heroku main
$ heroku run rails db:migrate

これで終わりです!
無事できたか確認...

$ heroku open

お疲れ様でした!

2
4
0

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
  3. You can use dark theme
What you can do with signing up
2
4