The DPNK django application was developed to power the Do Práce na Kole bike to work competition run by the non-profit Auto*mat organization in the Czech Republic. With some work, you can modify it to run your own bike to work competition in your home country.
This readme file is intended to document how to develop and deploy the code.
Do práce na kole is designed to use Python 3.4+ and Django 2.1
- Docker Engine
- Docker Compose
Check docker documentation for installation instructions
Click thumbnail for video instructions.
$ git clone https://github.com/auto-mat/do-prace-na-kole.git
$ cd do-prace-na-kole
$ cp docker.env.sample docker.env
$ $EDITOR docker.env
$ make docker-compose
In a separate terminal window:
$ ./develop.sh
$ ./setup.sh
$ ./develop.sh
$ python3 manage.py runserver 0.0.0.0:8000
Clone and launch the front end server according to its own docs: https://github.com/auto-mat/do-prace-na-kole-frontend
Running tests can be done with the command
pytest apps
In order to get a fast test loop, start out by running pytest apps
then edit your local version of the django migrate command (found in ./pyenv/.cache/pypoetry/virtualenvs/do-prace-na-kole-bQ0wwWJR-py3.9/lib/python3.9/site-packages/django/core/management/commands/migrate.py
) so that the handle
method starts with return
.
Finally run
./single-pytest.sh apps/dpnk/test/pytest/test_py_results.py
Replacing test_py_results.py
with the specific test file you want to run.
Go to http://test.lvh.me:8021/
.
Once you have your test environment working, it's a good idea to back up your database.
First stop docker compose
$ docker-compose down
Then copy db folder
$ cp -r ./db ./db-bk
Every time you push changes to github, new builds will be built. In this case, a build is a docker image.
In order to deploy to production you should first deploy to test, then, after testing a bit, look at the build number on test. Deployment is done by updating build numbers in the kubernetes config. The build number can be found at the bottom of the menu. It is in a format like 2021.1212 . 2021.24
which stands for <backend-build-number> . <frontend-build-number>
.
Deploying the frontend is similar. There is a script.
./scripts/deploy_frontend --help
Which helps you deploy frontend builds. This script is self documenting. To see it's documentation simply run the script with the --help
flag.
Use kubectl
.
$ kubectl get pods | grep dpnk
Get a bash shell with
$ kubectl exec -it <pod-id> -- bash
Once you connect you can get a python shell with
# poetry shell
# python3 manage.py shell_plus