install.rst 5.29 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 \
Guba Sándor committed
54 55
      python-pip rabbitmq-server libpq-dev python-dev ntp memcached \
      libmemcached-dev
56

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

  $ 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
68 69 70 71 72 73 74 75
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 '.*' '.*' '.*'

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

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

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


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

Clone the git repository::

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

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

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

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

  $ 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
120
  export AMQP_URI='amqp://cloud:password@localhost:5672/circle'
121
  export CACHE_URI='pylibmc://127.0.0.1:11211/'
122 123 124 125
  END
  $ workon circle
  $ cd ~/circle

Őry Máté committed
126
Install the required Python libraries to the virtual environment::
127 128 129 130 131

  $ pip install -r requirements/local.txt

Sync the database and create a superuser::

132 133
  $ circle/manage.py syncdb --all --noinput
  $ circle/manage.py migrate --fake
134 135 136 137 138 139
  $ 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
140 141 142 143 144 145 146 147 148 149
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
150 151 152 153 154
Building documentation
----------------------

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

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

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

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

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 \
173
          https://raw.githubusercontent.com/tpope/vim-pathogen/master/autoload/pathogen.vim
Őry Máté committed
174
  $ cd ~/.vim; mkdir -p bundle; cd bundle && git clone \
Őry Máté committed
175
        git://github.com/klen/python-mode.git
Őry Máté committed
176 177 178 179 180 181 182
  $ cat >>~/.vimrc <<END
      filetype off
      call pathogen#infect()
      call pathogen#helptags()
      filetype plugin indent on
      syntax on
  END
183
  $ sudo pip install pyflakes rope pep8 mccabe