Starting an Existing Ruby on Rails Project From GitHub and Heroku
About
Git is the preferred version control package for the Ruby on Rails community. Installing Git is a prerequisite for deploying your application to Heroku and storing the source code on GitHub.
Prerequisites
Ruby on Rails and Git need to be properly installed in Linux. The Rails version should be 3.0.9. You also need an existing project already saved in GitHub and Heroku.
Set Up Git
-
Enter the following commands (with the appropriate substitutions) to configure Git:
git config --global user.name "Your Name"
git config --global user.email youremail@example.com
Set Up GitHub
-
If you haven't already done so, create an account for yourself on GitHub.
-
Enter the commands "mkdir ~/.ssh" and then "mkdir ~/.ssh/github". You'll need the ~/.ssh/github directory for saving your GitHub SSH keys, which MUST be separate from your Heroku SSH keys.
-
Go to the GitHub Help Page and follow the instructions on how to set up GitHub (starting with adding your SSH keys).
-
IMPORTANT: You need to move your GitHub keys OUT of their default location, because they'll be overwritten later when you add your Heroku keys. After you save your keys in the default location (/home/(username)/.ssh), create the directory /home/(username)/.ssh/github and move your id_rsa and id_rsa.pub files into this directory.
-
IMPORTANT: After you enter your SSH key, you MUST enter the command "ssh-add ~/.ssh/github/id_rsa". This is necessary for SSH to recognize your special GitHub SSH key.
-
IMPORTANT: Every time you boot up, you MUST enter the command "ssh-add ~/.ssh/github/id_rsa". This is necessary for SSH to recognize your special GitHub SSH key. You can automatically execute the "ssh-add ~/.ssh/github/id_rsa" command every time you open a terminal window by adding it to the ~/.bashrc file. (If this file does not exist, you need to create it.)
-
Use the "cd" command to go to the directory where you wish to locate the applications. Given an application in account https://github.com/(account name)/(repository name), enter the command "git clone git@github.com:(account name)/(repository name).git". The application is now downloaded onto your computer.
-
To implement the new setup indicated by the Gemfile, enter the command "bundle install".
-
From your application's root directory, enter the command "rails server -d" to start your local web server.
SIDE NOTE: To stop the web server without rebooting, enter the command "pgrep ruby" to see its process ID number. Then enter the command "kill -9 (process ID number)" to stop the process.
-
After starting up your local web server, wait a few seconds and then open your web browser to the URL http://localhost:3000 . You should see the Ruby on Rails "Welcome aboard!" page.
-
When it's time to save and upload your source code changes to GitHub, the commands are:
git add .
git commit -m "(Insert comments here.)"
git push origin master
Set Up Heroku
-
From the root directory of your application, enter the command "sudo gem install heroku" to install Heroku.
-
Once you have installed Heroku, enter "heroku keys:add" to store your Heroku login information so you can access your account.
-
To link to your existing application on Heroku, enter "git remote add heroku git@heroku.com:(application).git"
-
To upload your application to Heroku, enter "git push heroku master".
If you get the error message "If you get the error message "rake aborted! no such file to load -- sqlite3", open the Gemfile in the root directory of your application and replace the line beginning with "gem 'sqlite3'" with "gem 'sqlite3', '1.3.3', :group => :development".
-
To view your application on Heroku, enter the command "heroku open". Your browser should display the Ruby on Rails "Welcome aboard!" page.
Updating Heroku and GitHub
-
When it's time to save and upload your source code changes to GitHub, the commands are:
git add .
git commit -m "(Insert comments here.)"
git push origin master
-
Make sure the deployment server uses the same version of Ruby as you are in your local environment. The default stack on Heroku is bamboo-mri-1.9.2, which uses Ruby 1.9.2. To see the list of available stacks on Heroku, enter "heroku stack". To switch to the bamboo-ree-1.8.7 stack (which uses Ruby 1.8.7), enter the command "heroku stack:migrate bamboo-ree-1.8.7".
-
Every rake function you performed locally to make the application work must be repeated on the deployment server. Enter "heroku (rake command)" to do this. Examples include "heroku rake db:migrate" and "heroku rake db:seed".