install.rst 5.1 KB
Newer Older
Őry Máté committed
1 2
Installation of a development machine
=====================================
3

4
.. highlight:: bash
Őry Máté committed
5

Őry Máté committed
6 7
Preparation
-----------
8 9 10 11 12

To get the project running on a development machine, create a new Ubuntu 12.04
instance, and log in to it over SSH.


Őry Máté committed
13 14
To use *git* over *SSH*, we advise enabling SSH *agent forwarding*.
On your personal computer check if *ssh-agent* is running (the command should
15 16 17 18 19 20 21 22
print a process id)::
  
  $ echo $SSH_AGENT_PID
  1234

If it is not running, you should set up your login manager or some other
solution to automatically launch it.

Őry Máté committed
23
Add your private key to the agent (if it is not added by your desktop
24 25 26 27 28 29 30 31 32 33
environment)::

  $ ssh-add [~/.ssh/path_to_id_rsa]

Log in to the new vm. The :kbd:`-A` switch enables agent forwarding::

  $ ssh -A cloud@host

You can check agent forwarding on the vm::

Őry Máté committed
34
  $ if [ -S "$SSH_AUTH_SOCK" ]; then echo "Agent forwarding works!"; fi
35 36
  Agent forwarding works!

Őry Máté committed
37 38 39 40 41 42 43 44 45
.. warning::
  If the first character of the hostname of the vm is a digit, you have to
  change it, because RabbitMQ won't work with it. ::
 
    $ old=$(hostname)
    $ new=c-${old}
    $ sudo tee /etc/hostname <<<$new
    $ sudo hostname $new
    $ sudo sed -i /etc/hosts -e "s/$old/$new/g"
46

Őry Máté committed
47 48
Setting up required software
----------------------------
49 50 51 52 53 54 55

Update the package lists, and install the required system software::

  $ sudo apt-get update
  $ sudo apt-get install --yes virtualenvwrapper postgresql git \
      python-pip rabbitmq-server libpq-dev python-dev

Őry Máté committed
56
Set up *PostgreSQL* to listen on localhost and restart it::
57 58 59 60 61 62 63 64 65 66 67 68 69 70 71

  $ sudo sed -i /etc/postgresql/9.1/main/postgresql.conf -e '/#listen_addresses/ s/^#//'
  $ sudo /etc/init.d/postgresql restart

Also, create a new database and user::

  $ sudo -u postgres createuser -S -D -R circle
  $ sudo -u postgres psql <<<"ALTER USER circle WITH PASSWORD 'circle';"
  $ sudo -u postgres createdb circle -O circle

Enable SSH server to accept your name and address from your environment::

  $ sudo sed -i /etc/ssh/sshd_config -e '$ a AcceptEnv GIT_*'
  $ sudo /etc/init.d/ssh reload

Őry Máté committed
72
You should set these vars in your **local** profile::
73 74 75 76 77 78 79 80 81

  $ cat >>~/.profile <<'END'
  export GIT_AUTHOR_NAME="Your Name"
  export GIT_AUTHOR_EMAIL="your.address@example.org"
  export GIT_COMMITTER_NAME="$GIT_AUTHOR_NAME"
  export GIT_COMMITTER_EMAIL="$GIT_AUTHOR_EMAIL"
  END
  $ source ~/.profile

Őry Máté committed
82
Allow sending it in your **local** ssh configuration::
83

Őry Máté committed
84
  # Content of ~/.ssh/config:
85 86
  Host *
    SendEnv GIT_*
tarokkk committed
87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106

Conigure RabbitMQ
-----------------
Delete guest user::

  $ sudo rabbitmqctl delete_user guest

Make a new virtual host to the AMQP server::

  $ sudo rabbitmqctl add_vhost circle

Create new user with a password::

  $ sudo rabbitmqctl add_user cloud password

Set permission of the new user on the virtual host::

  $ rabbitmqctl set_permissions -p circle cloud '.*' '.*' '.*'

.. note:: 
Guba Sándor committed
107 108 109 110 111 112 113 114 115
  You can check the result with this command::

    $ rabbitmqctl list_permissions -p django

  Sample result::

    $ Listing permissions in vhost "circle" ...
      cloud .* .* .*
      ...done.
tarokkk committed
116 117


Őry Máté committed
118 119
Setting up Circle itself
------------------------
120 121 122 123 124

Clone the git repository::

  $ git clone git@git.cloud.ik.bme.hu:circle/cloud.git circle

Őry Máté committed
125 126
Set up *virtualenvwrapper* and the *virtual Python environment* for the
project::
127 128 129 130

  $ source /etc/bash_completion.d/virtualenvwrapper
  $ mkvirtualenv circle

Őry Máté committed
131
Set up default Circle configuration and activate the virtual environment::
132 133 134 135 136 137 138 139 140 141 142 143

  $ cat >>/home/cloud/.virtualenvs/circle/bin/postactivate <<END
  export DJANGO_SETTINGS_MODULE=circle.settings.local
  export DJANGO_DB_HOST=localhost
  export DJANGO_DB_PASSWORD=circle
  export DJANGO_FIREWALL_SETTINGS='{"dns_ip": "152.66.243.60", "dns_hostname":
              "localhost", "dns_ttl": "300", "reload_sleep": "10",
              "rdns_ip": "152.66.243.60", "default_vlangroup": "publikus"}'
  END
  $ workon circle
  $ cd ~/circle

Őry Máté committed
144
Install the required Python libraries to the virtual environment::
145 146 147 148 149 150 151 152 153 154 155 156

  $ pip install -r requirements/local.txt

Sync the database and create a superuser::

  $ circle/manage.py syncdb --migrate --noinput
  $ circle/manage.py createsuperuser --username=test --email=test@example.org 

You can now start the development server::

  $ circle/manage.py runserver '[::]:8080'

Őry Máté committed
157 158 159 160 161
Building documentation
----------------------

To build the *docs*, install *make*, go to the docs folder, and run the building
process. ::
162 163 164 165

  $ sudo apt-get install make
  $ cd ~/circle/docs/
  $ make html
Őry Máté committed
166 167 168 169

You might also want to serve the generated docs with Python's development
server::

170 171
  $ cd _build/html
  $ python -m SimpleHTTPServer 8080
Őry Máté committed
172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191

Configuring vim
---------------

To follow the coding style of the project more easily, you might want to
configure vim like we do::
  
  $ mkdir -p ~/.vim/autoload ~/.vim/bundle
  $ curl -Sso ~/.vim/autoload/pathogen.vim \
  $     https://raw.github.com/tpope/vim-pathogen/master/autoload/pathogen.vim
  $ cd ~/.vim; mkdir -p bundle; cd bundle && git clone \
  $     git://github.com/klen/python-mode.git
  $ cat >>~/.vimrc <<END
      filetype off
      call pathogen#infect()
      call pathogen#helptags()
      filetype plugin indent on
      syntax on
  END
  $ sudo pip install pyflakes rope pep8 mccabe