install.rst 5.42 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 8 9 10
This tutorial describes the installation of a development environment. To
have a fully working environment, you have to set up the other components
as well. The full procedure is included in the :doc:`Puppet recipes
<puppet>` available for CIRCLE Cloud.

Őry Máté committed
11 12
Preparation
-----------
13

Őry Máté committed
14 15
To get the project running on a development machine, launch a new Ubuntu
12.04 or 14.04 machine, and log in to it over SSH.
16 17


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

Őry Máté committed
25 26
If it is not running, you can configure your dektop environment to
automatically launch it.
27

Őry Máté committed
28
Add your private key to the agent (if it is not added by your desktop
29 30
environment)::

Őry Máté committed
31
  ssh-add [~/.ssh/path_to_id_rsa]
32 33 34

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

Őry Máté committed
35
  ssh -A cloud@host
36 37 38

You can check agent forwarding on the vm::

Őry Máté committed
39
  $ if [ -S "$SSH_AUTH_SOCK" ]; then echo "Agent forwarding works!"; fi
40 41
  Agent forwarding works!

Őry Máté committed
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. ::
 
Őry Máté committed
46 47 48 49 50
    old=$(hostname)
    new=c-${old}
    sudo tee /etc/hostname <<<$new
    sudo hostname $new
    sudo sed -i /etc/hosts -e "s/$old/$new/g"
51

Őry Máté committed
52 53
Setting up required software
----------------------------
54 55 56

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

Őry Máté committed
57 58 59 60
  sudo apt-get update
  sudo apt-get install --yes virtualenvwrapper postgresql git \
    python-pip rabbitmq-server libpq-dev python-dev ntp memcached \
    libmemcached-dev
61

Őry Máté committed
62
Set up *PostgreSQL* to listen on localhost and restart it::
63

Őry Máté committed
64 65
  sudo sed -i /etc/postgresql/9.1/main/postgresql.conf -e '/#listen_addresses/ s/^#//'
  sudo /etc/init.d/postgresql restart
66 67 68

Also, create a new database and user::

Őry Máté committed
69 70 71
  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
72

Őry Máté committed
73 74 75
Configure RabbitMQ: remove the guest user, add virtual host and user with
proper permissions::

Őry Máté committed
76 77 78 79
  sudo rabbitmqctl delete_user guest
  sudo rabbitmqctl add_vhost circle
  sudo rabbitmqctl add_user cloud password
  sudo rabbitmqctl set_permissions -p circle cloud '.*' '.*' '.*'
Őry Máté committed
80

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

Őry Máté committed
83 84
  sudo sed -i /etc/ssh/sshd_config -e '$ a AcceptEnv GIT_*'
  sudo /etc/init.d/ssh reload
85

Őry Máté committed
86
You should set these vars in your **local** profile::
87

Őry Máté committed
88
  cat >>~/.profile <<'END'
89 90 91 92 93
  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
Őry Máté committed
94
  source ~/.profile
95

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

Őry Máté committed
98
  # Content of ~/.ssh/config:
99 100
  Host *
    SendEnv GIT_*
tarokkk committed
101 102


Őry Máté committed
103 104
Setting up Circle itself
------------------------
105 106 107

Clone the git repository::

Őry Máté committed
108
  git clone git@git.cloud.ik.bme.hu:circle/cloud.git circle
109

Őry Máté committed
110 111
Set up *virtualenvwrapper* and the *virtual Python environment* for the
project::
112

Őry Máté committed
113 114
  source /etc/bash_completion.d/virtualenvwrapper
  mkvirtualenv circle
115

Őry Máté committed
116
Set up default Circle configuration and activate the virtual environment::
117

Őry Máté committed
118
  cat >>/home/cloud/.virtualenvs/circle/bin/postactivate <<END
119 120 121 122 123 124
  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
125
  export AMQP_URI='amqp://cloud:password@localhost:5672/circle'
126
  export CACHE_URI='pylibmc://127.0.0.1:11211/'
127
  END
Őry Máté committed
128 129
  workon circle
  cd ~/circle
130

Őry Máté committed
131
Install the required Python libraries to the virtual environment::
132

Őry Máté committed
133
  pip install -r requirements/local.txt
134 135 136

Sync the database and create a superuser::

Őry Máté committed
137 138 139
  circle/manage.py syncdb --all --noinput
  circle/manage.py migrate --fake
  circle/manage.py createsuperuser --username=test --email=test@example.org 
140 141 142

You can now start the development server::

Őry Máté committed
143
  circle/manage.py runserver '[::]:8080'
144

Őry Máté committed
145 146
You will also need to run a local Celery worker::

Őry Máté committed
147
  circle/manage.py celery worker -A manager.mancelery
Őry Máté committed
148 149 150 151

.. note::
  You might run the Celery worker (and also the development server) in GNU
  Screen, or use Upstart::
Őry Máté committed
152 153
    sudo cp miscellaneous/mancelery.conf /etc/init/
    sudo start mancelery
Őry Máté committed
154

Őry Máté committed
155 156 157 158 159
Building documentation
----------------------

To build the *docs*, install *make*, go to the docs folder, and run the building
process. ::
160

Őry Máté committed
161 162 163
  sudo apt-get install make
  cd ~/circle/docs/
  make html
Őry Máté committed
164 165 166 167

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

Őry Máté committed
168
  (cd _build/html && python -m SimpleHTTPServer 8080)
Őry Máté committed
169 170 171 172 173 174 175

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

To follow the coding style of the project more easily, you might want to
configure vim like we do::
  
Őry Máté committed
176 177 178 179 180 181
  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
Őry Máté committed
182 183 184 185 186 187
      filetype off
      call pathogen#infect()
      call pathogen#helptags()
      filetype plugin indent on
      syntax on
  END
Őry Máté committed
188
  sudo pip install pyflakes rope pep8 mccabe