2011年4月20日星期三

rails + rubber + github + amazon ec2 free tier step by step

Reference:
Rubber wiki : https://github.com/wr0ngway/rubber/wiki/

How to deploy a Rails app to EC2 in less than an hour using Rubber
http://ginzametrics.com/deploy-rails-app-to-ec2-with-rubber.html


Step 1: Amazon Registration
http://www.amazon.com/gp/aws/registration/registration-form.html

  • reference: http://www.inside.com.tw/2010/11/02/amazon-aws-1


Step 2: Check
You could check your amazon account status here, your billing
https://aws-portal.amazon.com/gp/aws/developer/account/index.html

Amazon service console
https://console.aws.amazon.com/ec2/home

Amazon Security Credentials, you could get your keys here
https://aws-portal.amazon.com/gp/aws/developer/account/index.html?ie=UTF8&action=access-key


Step 3: Get your key pair
https://console.aws.amazon.com/ec2/home?region=us-east-1#s=KeyPairs
You will download a private key here like : keyname.pem


Step 4: Install rubber in your project
sudo gem install rubber
rails generate vulcanize complete_passenger_mysql


Step 5: Generate your public key in ~/.ec2
Change keyname.pem to keyname
chmod 400 keyname
ssh-keygen -y -f keyname > exviewkey.pub



Step 6: Edit your config/rubber/rubber.yml

1)
cloud_providers → aws → access_key
cloud_providers → aws → secret_access_key
cloud_providers → aws → account
cloud_providers → aws → keyname
cloud_providers → aws → keyname_file_location

access_key: ABCDEFGHIJKLMNOPQRST
secret_access_key: ABCDEFGHIJKLMNOPQRSTUVWXY1234567890+zabc
account: 123456789012 #account original would show like 1234-5678-9012
key_name: exviewkey #the name of private key you download
key_file: "#{Dir[(File.expand_path('~') rescue '/root') + '/.ec2/*' + cloud_providers.aws.key_name].first}"


2) Change the server timezone, and domain
timezone: US/Pacific
domain: webiste.com


3) Change your image type
image_type: t1.micro
image_id: 'ami-3e02f257'


It is my image type, you could find more in
  • http://uec-images.ubuntu.com/releases/10.10/release/
  • http://uec-images.ubuntu.com/releases/10.04/release/
  • http://aws.amazon.com/amis/Linux?browse=1
  • http://cloud.ubuntu.com/ami/
Reference:
  • http://groups.google.com/group/rubber-ec2/browse_thread/thread/dfff07e016a28896

4) Change the app_user, app_name
app_user: www-data
app_name: websitename


Step 7: Edit deploy.rb
ssh_options[:forward_agent] = true #optional : for deploy from github
set :repository, "git@github.com:yourname/projectname.git"
set :scm, "git"
set :deploy_via, :remote_cache
set :branch, 'master'


Reference:
  • http://groups.google.com/group/rubber-ec2/browse_thread/thread/bdf75bebb38eec2a/23fac77708767390?lnk=gst&q=github#23fac77708767390


Step 8: set ssh-agent (optional : for deploy from github)
eval `ssh-agent -s`
ssh-add


Reference:
  • http://groups.google.com/group/rubber-ec2/browse_thread/thread/73e50e32264768f6/ee1b4f497d621797?lnk=gst&q=github#ee1b4f497d621797
  • http://www.josephj.com/article/understand-ssh-key/


Step 9: deploy (Finally Gook Luck :p )
cap rubber:create_staging






沒有留言: