Open source backend for abakus.no, frontend located at webkom/lego-webapp
LEGO Er Ganske Oppdelt
docker-compose. Services like Postgres, Redis, Thumbor and Minio run inside docker.
# Initial setup (only need to once) $ git clone firstname.lastname@example.org:webkom/lego.git && cd lego/ $ python3 -m venv venv $ echo "from .development import *" > lego/settings/local.py $ source venv/bin/activate $ pip install -r requirements/dev.txt $ python manage.py initialize_development # Activate and run (do every time) $ docker-compose up -d $ source venv/bin/activate $ python manage.py runserver
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
setup.cfg for more info):
Format the code with black & isort
$ make fixme
To check if it is formatted properly, run:
$ tox -e isort -e flake8 -e black
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
--keepdbthe next time it will go a lot faster to run the tests multiple times. By adding the
--parallelwill run multiple tests in parallel using multiple cores.
If you want to check your test coverage, you can do the following
# Install the packages needed $ pip install -r requirments/coverage.txt # Run a full test run with coverage. This will run all tests in LEGO. $ coverage run --source=lego ./manage.py test # 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
How to deploy:
- Make sure the changes is pushed to master and the test passes.
- Have you added some new settings in
settings/? If so make sure the
Ansible variablesreflects these changes.
- We run migrations automatically, make sure they work!
- Push to the
prodbranch. From master:
git push origin master:prod
- Wait for the
prodbuild to complete, last step will be
- Go to ci.webkom.dev and use the deployment feature to deploy the production build.
Ansible will run the playbook for deploying the new build to
Testing with elasticsearch
Testing with elasticsearch
By default, development uses postgres for search.
We use elasticsearch in production, so you might want to test things locally with elasticsearch. In order to do so, you need to run elasticsearch from
docker-compose.extra.yml by running
docker-compose -f docker-compose.extra.yml up -d. Then you need to run lego with the env variable
SEARCH_BACKEND=elasticsearch. You might need to run the migrate_search and rebuild_index commands to get elasticsearch up to date.
If you get an error while installing requirements, you might be missing some dependencies on your system.
$ apt-get install libpq-dev python3-dev
For MACOS you need to
brew install postgresql
If you get an error while running initialize_development mentioning
elasticsearch, you probably need run the following code, and then start over from
docker-compose up -d. Read why and how to make it permanent on Elasticsearch docs.
$ sysctl -w vm.max_map_count=262144
If you get ld: library not found for -lssl
When changing the user fixtures one must load new fixtures
./manage.py load_fixtures --generate
An overview of the available users for development can be found in this PR