Wafer/DevInstall

From Wiki
Jump to: navigation, search

Contents

[edit] See also

Warning, the text on this page is not maintained and outdated. You should follow the README in the conference site repository, or the upstream Wafer documentation.

https://wafer.readthedocs.io/

[edit] Installing a local wafer instance for development

The following steps will hook you up with a local wafer instance you can use to help us beat it into shape for DebConf.

We'll be using Debian packages wherever possible, but some dependencies need to be obtained from other sources. Python virtual environments (virtualenv) shall come to the rescue to prevent the pollution of /usr/local.

[edit] Obtaining the sources, installing dependencies

echo "I have a Github account"   && git clone git@github.com:CTPUG/wafer.git \
                                 || git clone https://github.com/CTPUG/wafer.git
echo "I have DebConf Git access" && git clone username@git.debian.org/git/debconf-data/dc16.dc.o \
                                 || git clone git://anonscm.debian.org/debconf-data/dc16.dc.o.git

# Consider forking wafer on Github so you can push your branches and submit pull requests,
# but this can also be done later…

sudo apt-get install \
  build-essential \
  python-dev \
  libpq-dev \
  libjpeg-dev \
  npm

sudo apt-get install \
  virtualenv \
  python-django \
  python-django-doc \
  python-django-nose \
  python-django-crispy-forms \
  python-libravatar \
  python-pil \
  python-requests \
  python-tz \
  python-sqlparse \
  pyflakes \
  python-coverage

[edit] Creating a virtual environment for wafer (optional)

In case you see yourself hacking on pure wafer without any DC16 context, you can create a virtualenv just for this purpose, but you don't have to. Generally, you'll be working in the DC16 context when you hack the upstream wafer source code and prepare your pull requests.

cd wafer
virtualenv --system-site-packages ve-wafer
ve-wafer/bin/python ve-wafer/bin/pip install -r requirements.txt -r requirements-dev.txt

You can now enter and leave the virtualenv like this:

. ./ve-wafer/bin/activate
./manage syncdb
# hack
# […]
deactivate

[edit] Creating a DC16 wafer virtualenv

Now let's create a virtualenv for wafer in the DC16 context. We'll install the wafer requirements into the virtualenv, but tell Python we'd like to keep using the wafer source checkout (so we can quickly test changes/commits/branches). It's important to keep the order of pip vs. setup.py to avoid some silly Django/Python module loading insanity and related bugs. Thanks to Stefano for figuring this out.

cd ../dc16.dc.o || cd dc16.dc.o
virtualenv --system-site-packages ve-dc16
. ./ve-dc16/bin/activate
cd ../wafer
pip install -r requirements.txt
python setup.py develop
cd -

[edit] Running Django from source

If you want to run Django from source (or any other of the dependencies for that matter), do the following *before* the pip install call, but *after* entering the virtualenv in the above:

cd /path/to/django/source
python setup.py develop
cd -

[edit] Install NodeJS, Bower, Grunt

Wafer employs NodeJS and so we need to resort to yet another NIH-package-manager. Bonus points to anyone who wants to take the time to figure out what of the stuff being downloaded can be provided out of the Debian archive. sed is required since Debian calls the binary nodejs instead of just node. If nodejs-legacy is installed, there is no need to run the first sed:

sudo apt-get install \
  npm \
  node-findup-sync \
  node-resolve

npm install
npm install q mout bower-logger
# sed -i -e '1s/node$/&js/' node_modules/.bin/{bower,grunt} # only if nodejs-legacy is not installed
sed -i -e 's,\.\./lib,../bower/lib,' node_modules/.bin/bower
sed -i -e "s,'\.\./package.json,'../../package.json," node_modules/.bin/bower
./node_modules/.bin/bower install
sed -i -e 's,\.\./lib,../grunt-cli/lib,' node_modules/.bin/grunt
./node_modules/.bin/grunt

[edit] Set up Django and fire it up

Almost done. Now it's time to create the database and fire up the development server. Do not even think about putting this on a public IP.

./manage.py migrate
./manage.py runserver    # pass 0.0.0.0:8000 if you want to e.g. access the server on a vhost from your laptop

Hack away!

[edit] Next steps

[edit] Using a real database

The above installation uses SQlite3, which is probably fine for development. Setting up PostgreSQL instead is easy:

sudo apt-get install postgresql-9.4 python-psycopg2
# pg_createcluster 9.4 main --start   # postinst should do this
cd /etc/postgresql/9.4/main
sed -i -e '/^# TYPE/alocal   wafer           all                                     peer map=wafer' pg_hba.conf
# replace #LOGNAME with the username that will be running Django/wafer
echo "wafer           $LOGNAME                 wafer" >> pg_ident.conf
pg_ctlcluster 9.4 main reload
su postgres -c 'createuser -DIRS -l wafer'
su postgres -c 'createdb --owner=wafer wafer'
cd -

And then tell Django (DC16 context) to use it instead:

cat <<_eof >> localsettings.py
DATABASES['default'] = {
  'ENGINE': "django.db.backends.postgresql_psycopg2",
  'NAME': "wafer",
  'HOST': "",  # use socket for access
  'USER': "wafer"
}
_eof
./manage.py migrate

[edit] Using a real webserver

Please document WSGI integration with Apache2/lighttpd/nginx/whatever, if you set it up.

Personal tools