TIL Deploying Takahē

, Jochen

Setting up Takahē for Local Development

Clone the repository from GitHub:

git clone git@github.com:jointakahe/takahe.git && cd takahe

Create the Postgres database, and add it to ProcfileDev:

mkdir databases && pg_ctl initdb -D databases/postgres

echo "postgres: postgres -D databases/postgres" > ProcfileDev

Copy the environment variables from the test environment via cp test.env .env and change the database URL in .env to TAKAHE_DATABASE_SERVER="postgres://takahe@localhost/takahe". Also add ProcfileDev to the .env file, because Procfile is already used for deployment stuff 😕 (isn't heroku dead already?):

echo "PROCFILE=ProcfileDev" >> .env

Now it should be possible to start up the database server with:

honcho start

Create the database and database user used by the Django application:

createdb takahe && createuser takahe

Create a virtualenv and activate it. This step is probably different for you but for me it is:

vf new takahe && vf connect

First Caveat

On my M1 mac, the lxml wheel seems to be broken, when I just install the requirements via python -m pip install -r requirements-dev.txt. Trying to import etree after installing the dependencies like this yields this traceback:

>>> from lxml import etree

Traceback (most recent call last):

File "<stdin>", line 1, in <module>

ImportError: dlopen(/Users/jochen/.virtualenvs/takahe/lib/python3.11/site-packages/lxml/etree.cpython-311-darwin.so, 0x0002): symbol not found in flat namespace '_exsltDateXpathCtxtRegister'

>>>

But installing lxml with python -m pip install lxml works as expected. Really weird. Anyway installing lxml before installing the other dependencies without using a binary worked for me:

python -m pip install lxml --no-binary :all:

Installing the Development Dependencies

Install the development dependencies:

python -m pip install -r requirements-dev.txt

Now it's time to run the Django migrations: python manage.py migrate

Add the Django application and stator to the Procfile:

echo "django: PYTHONUNBUFFERED=true python manage.py runserver 0.0.0.0:8000" >> ProcfileDev

echo "worker: python manage.py runstator" >> ProcfileDev

If you now stop your running honcho and restart it, you should be able to see the takahē webinterface.

Running Tests

If you want to be able to run the tests, you have to add the CREATEDB privilege to the takahe database user:

psql -c "ALTER USER takahe CREATEDB;" -d takahe

Now it should by possible to run the tests:

pytest

Production Deployment

This is a little bit more complicated. To see an example for ansible, have a look at the deploy directory in my takahē fork (without_docker branch). You have to replace the hosts in the inventory but then this should work:

ansible-playbook deploy.yml --limit production

Return to blog