Sunday 9 June 2013

Project initiation - a recipe

Like with my cooking blogs this starts out in the future, ends up as what actually happened. I hope this is not too confusing. It is intended as a recipe to make life easy next time I come to use it.

This recipe steals from Hackers gonna Hack.

Choose short name

Ensure this is available on heroku.

Choose stack

I challenge your horse/cart analogy: this is going to be a Django project.

Create Repo

The only decision is public or private. It will be a git repo: here.

Create the README

Do it now!

Choose deployment platform

Heroku.

Choose CI

My Jenkins.

Setup dev machine

Follow Ubuntu Setup recipe.

Use a virtualenv, it is best practice and Heroku needs it.


sudo pip install virtualenv

sudo apt-get install sqlite3
sudo apt-get install ruby-dev
sudo apt-get install libsqlite3-dev


sudo apt-get install postgresql-server-dev-all
sudo apt-get install python-dev

There is a nasty issue with deployment to Heroku: ruby and or ruby gems versions. The problem occurs during heroku db:push with a message about date serialization. This is due to a change in the serialisation of dates. If you have a more recent version of ruby than heroku, and/or you have an inconsistent set of ruby gems. This is made worse by being able to both install Heruku from the Ruby repositories and directly. The recipe below uses RVM and worked.


# setup ruby for heroku pg:push
# this can go wrong if ALL versions are not alligned

\curl -L https://get.rvm.io | bash
source /home/timp/.rvm/scripts/rvm
rvm install ruby-1.9.2-p318
rvm use --default ruby-1.9.2-p290
gem install sqlite3
gem install pg
gem install taps
gem install heroku
gem install launchy
gem install addressable
gem install taps

TODO: pgbackups

Setup project

mkdir ucl
git init ucl
cd ucl
git remote add origin https://github.com/timp21337/ucl.git
git pull origin master
virtualenv venv --distribute
echo venv >> .gitignore
git commit -m "Add virtual env" .gitignore

source  ./venv/bin/activate 
pip install django
pip install dj_database_url
pip install django_jenkins
pip install psycopg2 gunicorn 
pip install django-floppyforms

pip freeze > requirements.txt

heroku login
heroku plugins:install git://github.com/ddollar/heroku-config.git
./manage.py collectstatic 
foreman start
git clone git@heroku.com:ucll.git -o heroku

dropdb --user postgres ucll
createdb --user postgres ucll

./manage.py syncdb;
git push heroku master

heroku db:push --confirm ucll postgres://postgres:*@127.0.0.1:5432/ucll

Results in http://ucll.herokuapp.com/.

No comments:

Post a Comment