Open source backend for abakus.no, frontend located at webkom/lego-webapp
LEGO Er Ganske Oppdelt
LEGO requires python3.11
, python3.11-venv
, docker
and poetry
. Services like Postgres, Redis, Thumbor and Minio run inside docker.
$ git clone git@github.com:webkom/lego.git && cd lego/
$ python3.11 -m venv venv
$ echo "from .development import *" > lego/settings/local.py
$ source venv/bin/activate
$ poetry install
$ docker compose up -d
$ python manage.py initialize_development
$ source venv/bin/activate
$ docker compose up -d
$ python manage.py runserver
# Note 1: Whenever you switch branches you might need to make minor changes
$ poetry install # If the branch has changes in the dependencies
$ python manage.py migrate # If the branch has a database in another state than yours
# Note 2: When you make changes to models, or constants used by models, you need to create new migrations
$ python manage.py makemigrations # Creates one or more new files that must be commited
# Remember to format generated migrations! (using e.g. `make fixme`)
poetry.lock
conflicts
If you have updated dependencies it's likely you might get conflicts in the Poetry lock file. This solution should resolve most conflicts quite well:
$ git rebase origin/master
# If conflicts
$ git checkout --theirs poetry.lock
$ poetry lock --no-update
# The conflicts should be resolved
If you get problems it can be a solution to delete the
venv
, and do a fresh setup
This codebase uses the PEP 8 code style. We enforce this with isort
, black
& flake8
. In addition to the standards outlined in PEP 8, we have a few guidelines (see pyproject.toml
for more info):
Format the code with isort
& black
$ make fixme
To check if it is formatted properly, run:
$ tox -e isort -e black -e flake8
To check if it is typed properly, run:
$ tox -e mypy
If you want to run a specific test class you can run
$ ./manage.py test lego.apps.[APP]
You can add flags to speed up the tests
By adding the
--keepdb
the next time it will go a lot faster to run the tests multiple times.By adding the
--parallel
will run multiple tests in parallel using multiple cores.
If you want to check your test coverage, you can do the following
# Run all tests in LEGO. Remember to add the recommended flags mentioned above
$ tox -e tests --
# or run without tox
$ coverage run --source=lego ./manage.py test
# If you now have multiple coverage files or a .coverage.* file, you'll have to combine it in order to output report
$ coverage combine
# Then you can output the full coverage report
$ coverage report
# or a small one that only contains the things you are interested in
$ coverage report | grep [some string]
LEGO runs in Docker Swarm
and deploys are managed by Drone
and Ansible
.
How to deploy:
settings/
? If so, make sure the Ansible variables
reflects these changes.build
branch. From master: git push origin master:build
build
build to complete. The last step will be docker build
Ansible will automatically run the playbook for deploying the new build to staging
or production
based on the target selected in step 6.
Testing with elasticsearch
Debugging