kobo (some) docker
fighting complexity with simplicity by making humans do more work
goal
As a developer, I would like to run things I don't change inside Docker (PostgreSQL, Redis, MongoDB, and—for now—Enketo Express). I would like full, manual control over running code that I do change (kpi Python, kpi JS, kobocat Python). I would like simplicity in configuration with sensible defaults and a minimum of mandatory customization.
to do
-
celery always eagerdone! - enketo bad news
Parse Error: Expected HTTP/
- should be fixed by kobotoolbox/kpi#3828
- apparently not completely? try opening offline form in a new tab
oh no 😱
- some changes are currently needed to the kpi and kobocat codebases.
kpi.patch
andkobocat.patch
in this repository contain those changes. apply them withgit apply
; e.g. in yourkpi
source directory, rungit apply < /path/to/kobo-no-docker/kpi.patch
. sorry. - you have to manually create the directory
jsapp/compiled
inside yourkpi
source directory, otherwisenpm run watch
will fail onExtractTranslationKeysPlugin
with aENOENT
getting started
- clone https://github.com/kobotoolbox/kpi and https://github.com/kobotoolbox/kobocat if you haven't already
docker-compose up
, which should yield:- enketo running on 10.6.6.1:9002
- postgres, on 10.6.6.1:60666
- redis, on 10.6.6.1:60667
- mongo, on 10.6.6.1:60668
virtualenv kpienv && virtualenv kcenv
- tested with
CPython3.8.10.final.0-64
- tested with
- install os-level dependencies (sorry):
sudo apt install python3-virtualenv gcc python3-dev gdal-bin libsqlite3-mod-spatialite
- more about GDAL here (it's required during migrations. and it's only required then?)
libsqlite3-mod-spatialite
is needed to run kobocat tests, or perhaps you could setTEST_DATABASE_URL
and run them against a real Postgres database instead- you'll also need docker and docker-compose; tested with docker 20.10.12, docker-compose 1.25.0
- set up a kpi (python) development environment!
- open a new terminal
. kpienv/bin/activate
. envfile
pip install pip-tools
cd
into your kpi source directorypip-sync dependencies/pip/dev_requirements.txt
./manage.py migrate
./manage.py runserver 10.6.6.1:9000
⚠️ not just any ol'runserver
, okay?
- set up a kpi (javascript) development environment!
- open a new terminal
cd
into your kpi source directorynvm use 16
, or whatever you cool kids likenpm install --legacy-peer-deps
npm install eslint eslint-plugin-react prettier --legacy-peer-deps
- i'm sorry.
- also, installing prettier this way doesn't seem to solve
ERROR in Failed to load config "prettier" to extend from.
- terrible workaround: edit
node_modules/kobo-common/src/configs/.eslintrc.js
and remove, 'prettier'
fromextends: ['eslint:recommended', 'prettier'],
npm run watch
- are you lucky today? i am!
webpack 5.72.0 compiled successfully in 30238 ms
- are you lucky today? i am!
- set up a kobocat development environment!
- open a new terminal
. kcenv/bin/activate
. envfile
pip install pip-tools
cd
into your kobocat source directorypip-sync dependencies/pip/dev.txt
- HEY! how about we make that consistent with kpi, eh?
./manage.py migrate
./manage.py runserver 10.6.6.1:9001
- 🤓 didja see the
1
in9001
?
- 🤓 didja see the
🥧 "don't forget to manage your pie"
hints
- django is set to use the console email backend, so you can do things like
create user accounts and read the activation email details right from the
output of
./manage.py runserver 10.6.6.1:9000
- it might also be helpful to have a superuser account:
- go to the terminal where kpi
./manage.py runserver 10.6.6.1:9000
is running - press ctrl+z to suspend
runserver
./manage.py createsuperuser
- once you're done, type
fg
and press enter to bringrunserver
back to the foreground
- go to the terminal where kpi
- help! i want to switch branches!
- you're generally responsible for knowing how to use
./manage.py migrate
to apply database migrations (or revert them, by migrating backwards) - let's say you'd like to back up your databases and start
from scratch to avoid migration hassles:
- stop
⚠️ the database servers withdocker-compose stop
- rename the
storage
directory to something else - restart the database servers with
docker-compose up
- check out the new branch you'd like to use
- for both kpi and kobocat, as described above, re-run
./manage.py migrate
- since you're starting from a completely empty database, you have to migrate both applications even if you only changed the branch for one of them
- you'll also have to recreate user accounts
- stop
- you're generally responsible for knowing how to use
nasties
- some things just don't work without nginx (like serving attachments? need to confirm)
- periodic tasks (
celery beat
) are completely ignored for the sake of simplicity apt install gdal-bin
on the host unavoidable?- "
pyuwsgi
is the exact same code asuwsgi
but" actually has binary wheels?- it'd sure be nice not to compile uwsgi from source
- then we could remove
gcc
andpython3-dev
requirements
- then we could remove
- unbit/uwsgi#1218 (comment)
- it'd sure be nice not to compile uwsgi from source
- kpi copy fonts calls
python
notpython3
(fails; i have onlypython2
andpython3
) - the wizard has not included a full inventory of his workshop
- eslint not installed by
npm install
in kpi npm install --legacy-peer-deps eslint-plugin-react
npm install
requires--legacy-peer-deps
??? (v16)- try installing prettier manually? (it didn't fix the issue)
ERROR in Failed to load config "prettier" to extend from. Referenced from: /home/john/Local/kobo-dev/kpi/node_modules/kobo-common/src/configs/.eslintrc.js
- eslint not installed by
can you use python 3.10?!
sure.
sudo add-apt-repository ppa:deadsnakes/ppa
sudo apt install python3.10-full python3.10-dev
sudo apt install libpq-dev
, because psycopg2 >= 2.9 breaks everything and nopsycopg2-binary
exists for < 2.9 and Python 3.10- having
psycopg2-binary==2.8.6
in the requirements, as the.patch
files do, should not cause a problem:pip
will automatically fall back to building from source
- having
- create your virtualenv with
python3.10 -m venv kpienv3.10
instead ofvirtualenv kpienv