The idea here is to be able to fetch from a herokuapp to our webfaction server so we can have a nice development process
like this:
We work on our local repo, this is the dev server.
We push to heroku, this is our staging area, we try and test new features here.
Then we go to webfaction and fetch from heroku and it will automatically update our production server.
Ok lets get started.
Open your ssh session to webfaction
mkdir ~/gems
Open the file .bashrc located at your home
nano ~/.bashrc
Paste this lines on the end of the file
export GEM_HOME=~/gems
export GEM_PATH=~/gems
Save the file with ctrl+o and hit ctrl+x to exit nano
Paste again these lines on your ssh session
export GEM_HOME=~/gems
export GEM_PATH=~/gems
Now install heroku
gem install heroku
Now you'll need to generate ssh keys for heroku we'll use this article,
Please visit the original article, i'll do the copy pasta because i really don't want to lose this information and the internets can be faulty.
In quite a few situations its preferred to have ssh keys dedicated for a service or a specific role. Eg. a key to use for home / fun stuff and another one to use for Work things, and another one for Version Control access etc. Creating the keys is simple, just use:
Use different file names for each key. Lets assume that there are 2 keys, ~/.ssh/id_rsa.work and ~/.ssh/id_rsa.misc . The simple way of making sure each of the keys works all the time is to now create config file for ssh:ssh-keygen -t rsa -f ~/.ssh/id_rsa.heroku -C "Key for Word stuff"
touch ~/.ssh/configThis would make sure that both the keys are always used whenever ssh makes a connection. However, ssh config lets you get down to a much finer level of control on keys and other per-connection setups. And I recommend, if you are able to, to use a key selection based on the Hostname. My ~/.ssh/config looks like this :
chmod 600 ~/.ssh/config
echo "IdentityFile ~/.ssh/id_rsa.heroku" >> ~/.ssh/config
echo "IdentityFile ~/.ssh/id_rsa" >> ~/.ssh/config
Ofcourse, if I am connecting to a remote host that does not match any of these selections, ssh will default back to checking for and using the 'usual' key, ~/.ssh/id_dsa or ~/.ssh/id_rsaHost *.heroku.com IdentityFile ~/.ssh/id_rsa.heroku User nombre.falso@gmail.com
Again, thanks to Karanbir Singh for this article, i've customized the code for our purposes.
Now, to make our life easier we will create an alias to the heroku bin
Open .bashrc again
nano .bashrc
Paste at the end of the file
alias heroku=~/gems/bin/heroku
Now you can follow the heroku tutorial to configure your account(register one if you don't have it) here are the steps
heroku config
Answer the questions, finish the wizard
Now go to where you want to keep your git repo fetched from heroku
cd ~/webapps/git/repos/
Initialize a new git repo i named mine heroku
git init heroku
cd heroku
Now add the remote heroku
git remote add heroku git@heroku.com:nameofyouraccount.git
Coincidentally my remote is named heroku, but you can name yours whatever you want, substitute nameofyouraccount with the name of your heroku account.
Now do,
git fetch heroku
And tada! you now have an easy way to pull changes from heroku to webfaction.
Hey,
ResponderEliminarnice article. I am hesitating between heroku and webfaction for hosting my django powered web app (which requires celery). Which one would you recommend ? I need fast CPU and I do not want to pay much as the app is not mature yet :)
Thanks !
Go with webfaction, you'll pay $20 a month only. You'll have to do the setup your self but is not that much. For celery in webfaction go with redis.
ResponderEliminarIf you choose heroku you'll have to pay a worker to run celery.
As far as cpu i don't think heroku is cpu bound, ram will be your problem with heroku :) and webfaction does not oversell their shared hosts so you'll be fine with them.
Once your app is mature enough i would use all memcache all over the place before moving to heroku, it can take you a looong way.