install.rst 5.22 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

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

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

Ő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

  $ 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

Őry Máté committed
67 68 69 70 71 72 73 74
Configure RabbitMQ: remove the guest user, add virtual host and user with
proper permissions::

  $ sudo rabbitmqctl delete_user guest
  $ sudo rabbitmqctl add_vhost circle
  $ sudo rabbitmqctl add_user cloud password
  $ sudo rabbitmqctl set_permissions -p circle cloud '.*' '.*' '.*'

75 76 77 78 79
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
80
You should set these vars in your **local** profile::
81 82 83 84 85 86 87 88 89

  $ 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
90
Allow sending it in your **local** ssh configuration::
91

Őry Máté committed
92
  # Content of ~/.ssh/config:
93 94
  Host *
    SendEnv GIT_*
tarokkk committed
95 96


Őry Máté committed
97 98
Setting up Circle itself
------------------------
99 100 101 102 103

Clone the git repository::

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

Őry Máté committed
104 105
Set up *virtualenvwrapper* and the *virtual Python environment* for the
project::
106 107 108 109

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

Őry Máté committed
110
Set up default Circle configuration and activate the virtual environment::
111 112 113 114 115 116 117 118

  $ 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"}'
Őry Máté committed
119
  export AMQP_URI='amqp://cloud:password@localhost:5672/circle'
120
  export CACHE_URI='pylibmc://127.0.0.1:11211/'
121 122 123 124
  END
  $ workon circle
  $ cd ~/circle

Őry Máté committed
125
Install the required Python libraries to the virtual environment::
126 127 128 129 130 131 132 133 134 135 136 137

  $ 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
138 139 140 141 142 143 144 145 146 147
You will also need to run a local Celery worker::

  $ circle/manage.py celery worker -A manager.mancelery

.. note::
  You might run the Celery worker (and also the development server) in GNU
  Screen, or use Upstart::
    $ sudo cp miscellaneous/mancelery.conf /etc/init/
    $ sudo start mancelery

Őry Máté committed
148 149 150 151 152
Building documentation
----------------------

To build the *docs*, install *make*, go to the docs folder, and run the building
process. ::
153 154 155 156

  $ sudo apt-get install make
  $ cd ~/circle/docs/
  $ make html
Őry Máté committed
157 158 159 160

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

Őry Máté committed
161
  $ (cd _build/html && python -m SimpleHTTPServer 8080)
Őry Máté committed
162 163 164 165 166 167 168 169 170

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 \
Őry Máté committed
171
        https://raw.github.com/tpope/vim-pathogen/master/autoload/pathogen.vim
Őry Máté committed
172
  $ cd ~/.vim; mkdir -p bundle; cd bundle && git clone \
Őry Máté committed
173
        git://github.com/klen/python-mode.git
Őry Máté committed
174 175 176 177 178 179 180 181
  $ 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