Tuesday, March 20, 2012

Jenkins + git + Heroku on mac

To automate the deployment and testing of my brand new Heroku backed Django app, I wanted to setup a Jenkings CI system on my home macmini.

That was not wuite as easy as I has thought it was.

Getting it running was easy, just use the installer. And there is a git plugin, sweet. But getting that to work was a pain.

When ever I tried to fetch the project for heroku git repo, I would end up with weird errors. For some reason Jenkins wanted to read .ssh keys from /etc/root, write Heroku credentials to my own home directory etc.

After poking around a bit I found out that the default installation of Jenkins runs it on user 'daemon'. This user does not have it's own home directory. Instead is uses root's home. Which is baaad, m'kay.

So, first step wast to reinstall Jenkins so that it would NOT run it with daemon user. Key to it is to select "Customize" during the installation process and select the option to create jenkins user. This seems to fix the problem, the jenkins is now running with it's own account. Awsum.

But still no luck.

Even though I created the ssh keys, the Jenkins does not seem to find them, and git keeps giving "status code 128: Host key verification failed." error. Hmm.

What I was missing was that the keys had to be added to heroku. For some reason I thought that "heroku login" owuld add them there, but obviously not (why would it). To make it work I did this as jenkins user:

heroku keys:add

But still nothing, same error. Wtf.

It turned out that actually the error was not about the ssh keys at all, but the missing server RSA fingerprint from known hosts. So, after I tried to clone the repository from shell (as jenkings user) the error went away!

...and was replaced with another one:

"fatal: empty ident not allowed"

It seems that Heroku requires that you set email and username for git (although it did not require that from commandline..)

But still nothing!

It seems that the jenkings for some unknown reason does not use the correct home path (/Users/Shared/Jenkins/Home), instead is leaves the /Home out. Then I created a symlink to .gitconfig on /Users/Shared/Jenkings...

sudo -s -u jenkins
cd /Users/Shared/Jenkings
ln -s Home/.gitconfig

And it worked! Yatzy!

Wednesday, January 11, 2012

Django static files on Heroku

After completing Django-Heroku Hello World, I realized that the static files were not served properly. I found this and after modifying urls.py like this it started working. Great!