miércoles, 30 de noviembre de 2011

Using heroku on webfaction

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:
ssh-keygen -t rsa -f ~/.ssh/id_rsa.heroku -C "Key for Word stuff"
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:
touch ~/.ssh/config
chmod 600 ~/.ssh/config
echo "IdentityFile ~/.ssh/id_rsa.heroku" >> ~/.ssh/config
echo "IdentityFile ~/.ssh/id_rsa" >> ~/.ssh/config
This 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 :
Host *.heroku.com
  IdentityFile ~/.ssh/id_rsa.heroku
  User nombre.falso@gmail.com
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_rsa

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.

martes, 29 de noviembre de 2011

installing psycopg2 in Webfaction

If you use webfaction and you'r machine name is Web300 and above(Web301, Web302, etc) and you want to install psycopg2 you'll need
nano ~/.bashrc
Paste this
export PATH=/usr/pgsql-9.1/bin/:$PATH
Now hit ctrl+o and then ctrl+x
Now on the terminal export the path again
export PATH=/usr/pgsql-9.1/bin/:$PATH
And when you do
easy_install psycopg2
or
pip install psycopg2
It won't complain about pg_config executable missing.

sábado, 26 de noviembre de 2011

why post

I just read an awesome tip when learning new stuff, from the article on motivation and learning something from the Freakonomics guys(read the original book it explains the internet as we know it from an economic point of view)
Wheeler recommended that, after we solve any problem, we think of one sentence that we could tell our earlier self that would have “cracked” the problem. This kind of thinking turns each problem and its solution into an opportunity for reflection and for developing transferable reasoning tools.
I would have loved saying to my self.
Writting a new django feature takes this steps:

  • Think of the feature.
  • Think how you would put the data needed to drive the feature in a 2d table.
  • Create a new django app .
  • Write the name of the columns in a model inside models.py.
  • Write the logic that uses that data in views.py
  • Make sure your processed data ends ups in the context that view returns.
  • Write the template that uses the processed data.
And make sure you have the django official docs with your all the time!