install.rst 5.76 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 64
  sudo apt-get update
  sudo apt-get install --yes virtualenvwrapper postgresql git \
    python-pip rabbitmq-server libpq-dev python-dev ntp memcached \
    libmemcached-dev
65

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

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

Also, create a new database and user::

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

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

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

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

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

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

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

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

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


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

Clone the git repository::

112 113 114 115 116 117 118
  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
119

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

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

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

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

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

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

Sync the database and create a superuser::

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

You can now start the development server::

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

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

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

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

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

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

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

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

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

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

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

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