Skip to content

auto-mat/do-prace-na-kole

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Do Prace na Kole (Ride to work by Bike) competion django app

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

Dependencies

  • Docker Engine
  • Docker Compose

Check docker documentation for installation instructions

Setting up the dev env

Click thumbnail for video instructions.

Alt text for your video

Check out and setup repo

$ git clone https://github.com/auto-mat/do-prace-na-kole.git
$ cd do-prace-na-kole

Create a docker.env file

$ cp docker.env.sample docker.env
$ $EDITOR docker.env

Building the docker images

$ make docker-compose

Setting up the database

In a separate terminal window:

$ ./develop.sh
$ ./setup.sh

Launching the development webserver

$ ./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

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.

Open the web app

Go to http://test.lvh.me:8021/.

Backing up your local development database

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

Deployment

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.

Connecting to test and production servers (bash and python shell)

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