install.rst 5.81 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
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
9
</puppet>` available for CIRCLE Cloud.
Őry Máté committed
10

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

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


18 19 20 21
.. info::
    To use *git* over *SSH*, we advise enabling SSH *agent forwarding*.
    On your terminal computer check if *ssh-agent* is running (the command
    should print a process id)::
22

23 24
      $ echo $SSH_AGENT_PID
      1234
25

26 27
    If it is not running, you can configure your dektop environment to
    automatically launch it.
28

29 30
    Add your private key to the agent (if it is not added by your desktop
    environment)::
31

32 33 34 35
      ssh-add [~/.ssh/path_to_id_rsa]

    You can read and write all repositories over https, but you will have to
    provide username and password for every push command.
36 37 38

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

Őry Máté committed
39
  ssh -A cloud@host
40 41 42

You can check agent forwarding on the vm::

Őry Máté committed
43
  $ if [ -S "$SSH_AUTH_SOCK" ]; then echo "Agent forwarding works!"; fi
44 45
  Agent forwarding works!

Őry Máté committed
46 47 48
.. 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. ::
49

Őry Máté committed
50 51 52 53 54
    old=$(hostname)
    new=c-${old}
    sudo tee /etc/hostname <<<$new
    sudo hostname $new
    sudo sed -i /etc/hosts -e "s/$old/$new/g"
55

Őry Máté committed
56 57
Setting up required software
----------------------------
58 59 60

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

Őry Máté committed
61 62 63
  sudo apt-get update
  sudo apt-get install --yes virtualenvwrapper postgresql git \
    python-pip rabbitmq-server libpq-dev python-dev ntp memcached \
64
    libmemcached-dev npm nodejs-legacy
65
  sudo npm -g install bower less yuglify
66

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

Őry Máté committed
69 70
  sudo sed -i /etc/postgresql/9.1/main/postgresql.conf -e '/#listen_addresses/ s/^#//'
  sudo /etc/init.d/postgresql restart
71 72 73

Also, create a new database and user::

Őry Máté committed
74 75 76
  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
77

Őry Máté committed
78 79 80
Configure RabbitMQ: remove the guest user, add virtual host and user with
proper permissions::

Őry Máté committed
81 82 83 84
  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
85

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

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

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

Őry Máté committed
93
  cat >>~/.profile <<'END'
94 95 96 97 98
  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
99
  source ~/.profile
100

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

Őry Máté committed
103
  # Content of ~/.ssh/config:
104 105
  Host *
    SendEnv GIT_*
tarokkk committed
106 107


Őry Máté committed
108 109
Setting up Circle itself
------------------------
110 111 112

Clone the git repository::

113 114 115 116 117 118 119
  git clone https://git.ik.bme.hu/circle/cloud.git circle

If you want to push back any modifications, it is possible to set SSH as the
push protocol::

  cd circle
  git remote set-url --push origin git@git.ik.bme.hu:circle/cloud.git
120

Őry Máté committed
121 122
Set up *virtualenvwrapper* and the *virtual Python environment* for the
project::
123

Őry Máté committed
124 125
  source /etc/bash_completion.d/virtualenvwrapper
  mkvirtualenv circle
126

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

Őry Máté committed
129
  cat >>/home/cloud/.virtualenvs/circle/bin/postactivate <<END
130 131 132 133 134 135
  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
136
  export AMQP_URI='amqp://cloud:password@localhost:5672/circle'
137
  export CACHE_URI='pylibmc://127.0.0.1:11211/'
138
  END
Őry Máté committed
139 140
  workon circle
  cd ~/circle
141

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

Őry Máté committed
144
  pip install -r requirements/local.txt
145 146 147

Sync the database and create a superuser::

Őry Máté committed
148 149
  circle/manage.py syncdb --all --noinput
  circle/manage.py migrate --fake
150
  circle/manage.py createsuperuser --username=test --email=test@example.org
151 152 153

You can now start the development server::

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

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

Őry Máté committed
158
  circle/manage.py celery worker -A manager.mancelery
Őry Máté committed
159 160 161 162

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

Őry Máté committed
166 167 168 169 170
Building documentation
----------------------

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

Őry Máté committed
172 173 174
  sudo apt-get install make
  cd ~/circle/docs/
  make html
Őry Máté committed
175 176 177 178

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

Őry Máté committed
179
  (cd _build/html && python -m SimpleHTTPServer 8080)
Őry Máté committed
180 181 182 183 184 185

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

To follow the coding style of the project more easily, you might want to
configure vim like we do::
186

Őry Máté committed
187 188 189 190 191 192
  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
193 194 195 196 197 198
      filetype off
      call pathogen#infect()
      call pathogen#helptags()
      filetype plugin indent on
      syntax on
  END
Őry Máté committed
199
  sudo pip install pyflakes rope pep8 mccabe