AWS Recipe
Seems Im not the only one who has had problems with ruby 1.9.2 and rvm on my Ubuntu servers. This recipe so far has worked great for every project running on it so far. Im not taking credit for all of it. Its a compilation of things that I have found on other blogs (too many to credit).
Use this AMI
ami-a403f7cd
Then add ssh, http and https to the default security group. Now you can shell in
-
sudo apt-get update
-
sudo apt-get build-essential
-
sudo apt-get install curl git-core gitk git-gui
-
sudo apt-get install libcurl4-openssl-dev
-
sudo apt-get install vim
-
sudo apt-get install rake
-
sudo apt-get install apache2 apache2-mpm-prefork apache2-prefork-dev
-
sudo apt-get install mysql-server mysql-client
-
sudo apt-get install libmysql-ruby libmysqlclient-dev
Now for the RVM stuff
-
sudo apt-get install ruby
-
bash < <( curl https://rvm.beginrescueend.com/releases/rvm-install-head )
EDIT:: RVM has changed the install address. Check their website to get the latest bash install command
Open .bashrc and replace
-
[ -z "$PS1" ] && return
with
-
if [[ -n "$PS1" ]]; then
Then at the end of the file
-
if [[ -s $HOME/.rvm/scripts/rvm ]] ; then source $HOME/.rvm/scripts/rvm ; fi
-
fi
You should close the terminal and open a new one then enter
-
rvm notes
You should see a bunch of options.
Now we need to add a bunch of stuff
-
sudo aptitude install build-essential bison openssl libreadline5 libreadline-dev curl git-core zlib1g zlib1g-dev libssl-dev vim libsqlite3-0 libsqlite3-dev sqlite3 libreadline-dev libxml2-dev git-core subversion autoconf
Now we can run rvm list known and we should see a list of rubies
Time to upgrade our ruby
-
rvm install 1.9.2-head
-
rvm –default 1.9.2-head
EDIT:: RVM has changed a bit since I wrote this. Be sure to read their instructions to be familiar with the differences. Setting default has now changed to
-
rvm use 1.9.2-head –default
Don’t forget the –default or your git hooks will never work
Lets get rails in there to test it out
-
gem install rails
Try it out
-
rails new testing
Should have created a new rails app.
Now we need to get our project from the git repo. But we need to give them a pub key
-
cd ~/
-
ssh-keygen -t rsa
(defaults, no passphrase)
-
cat .ssh/id_rsa.pub
copy and paste that into the repo keys on your repo
Now set up the site
-
cd /var
-
sudo chgrp -R ubuntu www
-
sudo chown -R ubuntu www
-
cd www
-
git clone [clone address] [dir name you want]
-
cd [new dir name]
-
bundle install
cool, now lets set up the webserver
-
gem install passenger
-
passenger-install-apache2-module
follow the instructions
Now we need to set up our git hooks for a heroku like deployment
shell into the server then cd to /var/www/[your app]/.git/hooks
copy the post-receive.sample to just post-receive
chmod it to 777
then edit it like so
-
#!/bin/bash
-
APP_PATH=/var/www/myapp
-
# Production environment
-
export RAILS_ENV="production"
-
# This loads RVM into a shell session. Uncomment if you’re using RVM system wide.
-
# [[ -s "/usr/local/lib/rvm" ]] && . "/usr/local/lib/rvm"
-
[[ -s "/home/ubuntu/.rvm/scripts/rvm" ]] && source "/home/ubuntu/.rvm/scripts/rvm" # Load RVM into a shell session *as a function*
-
-
echo "*******************************************"
-
echo " Deploying [APP NAME] to live server "
-
echo "*******************************************"
-
-
exit_with_error() {
-
echo "[DEPLOY] !!!!!!!!!!!!!!!!!!!! An error has occurred !!!!!!!!!!!!!!!!!!!!!!!"
-
exit 1
-
}
-
-
cd ${APP_PATH}
-
env -i git add .
-
env -i git reset –hard || exit_with_error
-
env -i git pull origin master
-
-
echo "[DEPLOY] – * Running bundle"
-
bundle install –deployment –without development test || exit_with_error
-
-
echo "[DEPLOY] – * Migrating database"
-
bundle exec rake db:migrate || exit_with_error
-
-
-
echo "[DEPLOY] – * Successfully deployed application to live server"
-
-
echo "[DEPLOY] – * Restarting application"
-
mkdir -p tmp/
-
touch tmp/restart.txt
-
-
-
echo "*******************************************"
-
echo " Successfully deployed [APP NAME] "
-
echo "*******************************************"
-
Then, in the .git/config file add this to stop all those pesky warnings
-
[receive] denyCurrentBranch = false
Now we need to create a DB
-
mysql -u root -p
create database [whatever you need here];
-
exit
Lets add the new server as a remote for your git
-
git remote add live ubuntu@[some ip]:/var/www/[app name]
I think were ready for a push. In your project update the config/database.yml and change the production creds to what you just created.
commit that change and push it to origin
-
git push origin master
And now push it to live
-
git push live master
tada.. git push deployment with gem updates and migrations
Just one thing left… database backups to S3. Thats for another post.