Skip to content

Instantly share code, notes, and snippets.

@firmanm
Forked from MyklClason/rails_guide.md
Created January 16, 2020 08:26
Show Gist options
  • Save firmanm/571b4d6266685cced75acb5a30b73b9f to your computer and use it in GitHub Desktop.
Save firmanm/571b4d6266685cced75acb5a30b73b9f to your computer and use it in GitHub Desktop.
AWS Cloud9 Rails Setup (and migration from c9.io) for Rails 5.2

Overview

Warning: This guide intended for Rails 5.2, and may be incompletefor Rails 6 setup. This guide will be updated once Rails 6.1 comes out.

This is direction for Migration from c9.io to AWS Cloud9, after you follow the cloud9 migration directions and created a workspace, keeping in mind the Workspace settings Section below.

Be sure you are using the right version of rails. You may need to remove rails and rail-ties and install rails 5.2. Check online for how (search how to reinstall rails with a specific version)

To create a new app in AWS Cloud9, the directions are basically the same, but you need to use rails new (see note below first) first and move all code out of the new folder and into the workspace (root) folder, so you don't need to CD into your project.

Note: When using Rails new it useful to review the rails new -h to see what flags you can use. Since this guide uses postgres, you'll want to use: rails new app_name --database postgresql

Workspace settings

When creating a Cloud9 Environment, use Ubuntu not Amazon Linux

Cloud9 Editor Settings

  • Strip Whitespace
  • Soft tabs (2)

Postgres

First run

wget --quiet -O - https://www.postgresql.org/media/keys/ACCC4CF8.asc | sudo apt-key add -
sudo apt-get update
sudo apt install postgresql postgresql-contrib libpq-dev

(The above can cause odd issues with the Y/N if it isn't ran by itself)

Then

# ubuntu User setup
sudo service postgresql start
sudo sudo -u postgres psql
CREATE USER ubuntu SUPERUSER PASSWORD 'password'; # You may want to use something more secure
\q

Then

https://gist.github.com/MyklClason/338536e05dcb09e093fca3f562d50bbc

Close and reopen any open terminals after the above is ran to use the aliases.

Be sure you have replaced the sqlite gem with the pg gem. Depending on your version of rails, you may need to use a specific version of the pg gem. Research online for which version of the gem for which version of rails.

Redis

sudo apt-get install redis-server

Bashrc + Git + Bash Aliases + Env Vars

Bash Alises: https://gist.github.com/MyklClason/d71a39ace28b9ec9f0ad

Be sure to update the name and email for git.

# Add to bottom of .bashrc file
if [ -f ~/.bash_aliases ]; then
  . ~/.bash_aliases
fi

# Handle issue with nano not being found during git merges and such via using vim.
# Has to be set here as it isn't being saved between terminal windows
git config --global core.editor "vim"

# General git config, be sure to update the name + email
git config --global user.name "<user name>"
git config --global user.email <user email>


# Then add profile env vars and project specific aliases and alias overrides

Close and reopen any open terminals after the above is ran to use the aliases.

Heroku

huf

If bash aliases are setup, else see bash aliases gist for what the alias is currently mapped to, as it has changed in the past depending on heroku CLI version).

Ruby on Rails (if needed)

First install the correct version of ruby. Remove the default version if a downgrade is needed.

rvm list

Remove via:

rvm remove <not required version>

install and use default version

rvm use --default --install <required version>

Add Setup Rails if needed (if not migrating)

https://guides.rubyonrails.org/getting_started.html

Setup bundler and rails

gem install bundler
bundle install
# Do the postgres setup for cloud9
rake db:create
rake db:migrate

Rails Console

Solves FATAL: Listen error: unable to monitor directories for changes. error if it comes up.

echo fs.inotify.max_user_watches=524288 | sudo tee -a /etc/sysctl.conf && sudo sysctl -p

Gitignore

# See https://help.github.com/articles/ignoring-files for more about ignoring files.
#
# If you find yourself ignoring temporary files generated by your text editor
# or operating system, you probably want to add a global ignore instead:
#   git config --global core.excludesfile '~/.gitignore_global'

# Ignore bundler config.
/.bundle

# Ignore all logfiles and tempfiles.
/log/*
/tmp/*
!/log/.keep
!/tmp/.keep

# Ignore uploaded files in development
/storage/*
!/storage/.keep

/node_modules
/yarn-error.log

/public/assets
.byebug_history

# Ignore master key for decrypting credentials and more.
/config/master.key

/public/packs
/public/packs-test
/node_modules
/yarn-error.log
yarn-debug.log*
.yarn-integrity

.c9/

StimulusJS (if needed)

https://gist.github.com/MyklClason/09c6f58b9e6d21340582cbd6fbd3b8b8

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment