{"id":26214753,"url":"https://github.com/webkom/lego","last_synced_at":"2025-04-10T04:56:02.838Z","repository":{"id":21119380,"uuid":"24420075","full_name":"webkom/lego","owner":"webkom","description":"Backend for abakus.no","archived":false,"fork":false,"pushed_at":"2024-10-29T11:32:42.000Z","size":11641,"stargazers_count":55,"open_issues_count":144,"forks_count":20,"subscribers_count":14,"default_branch":"master","last_synced_at":"2024-10-29T13:23:55.486Z","etag":null,"topics":["backend","django","django-rest-framework","hacktoberfest","mypy","python","rest-api"],"latest_commit_sha":null,"homepage":"https://lego.abakus.no","language":"Python","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/webkom.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2014-09-24T15:13:29.000Z","updated_at":"2024-10-29T11:30:53.000Z","dependencies_parsed_at":"2023-12-26T08:26:12.958Z","dependency_job_id":"c127c7dd-601b-4e2f-947c-527af11d06d6","html_url":"https://github.com/webkom/lego","commit_stats":null,"previous_names":[],"tags_count":5,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/webkom%2Flego","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/webkom%2Flego/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/webkom%2Flego/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/webkom%2Flego/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/webkom","download_url":"https://codeload.github.com/webkom/lego/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248161260,"owners_count":21057554,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["backend","django","django-rest-framework","hacktoberfest","mypy","python","rest-api"],"created_at":"2025-03-12T10:18:20.893Z","updated_at":"2025-04-10T04:56:02.820Z","avatar_url":"https://github.com/webkom.png","language":"Python","funding_links":[],"categories":[],"sub_categories":[],"readme":"# LEGO\n\n\u003e Open source backend for abakus.no, frontend located at [webkom/lego-webapp](https://github.com/webkom/lego-webapp)\n\n[![MIT](https://badgen.net/badge/license/MIT/blue)](https://en.wikipedia.org/wiki/MIT_License)\n[![last commit](https://badgen.net/github/last-commit/webkom/lego/)](https://github.com/webkom/lego/commits/master)\n[![contributors](https://badgen.net/github/contributors/webkom/lego)](https://github.com/webkom/lego/graphs/contributors)\n[![Build Status](https://ci.webkom.dev/api/badges/webkom/lego/status.svg)](https://ci.webkom.dev/webkom/lego)\n[![codecov](https://codecov.io/gh/webkom/lego/branch/master/graph/badge.svg?token=4JI1CMu58M)](https://codecov.io/gh/webkom/lego)\n\n\u003e LEGO Er Ganske Oppdelt\n\n## Getting started\n\nLEGO requires `python3.11`, `python3.11-venv`, `docker` and `poetry`. Services like Postgres, Redis, Thumbor and Minio run inside docker.\n\n### Initial setup (only needed once)\n\n```bash\n$ git clone git@github.com:webkom/lego.git \u0026\u0026 cd lego/\n$ python3.11 -m venv .venv\n$ echo \"from .development import *\" \u003e lego/settings/local.py\n$ source .venv/bin/activate\n$ poetry install\n$ docker compose up -d\n$ python manage.py initialize_development\n```\n\n### Activate and run (every time)\n\n```bash\n$ source .venv/bin/activate\n$ docker compose up -d\n$ python manage.py runserver\n```\n\n#### Notes\n\n```bash\n# Note 1: Whenever you switch branches you might need to make minor changes\n\n$ poetry install # If the branch has changes in the dependencies\n$ python manage.py migrate # If the branch has a database in another state than yours\n\n# Note 2: When you make changes to models, or constants used by models, you need to create new migrations\n\n$ python manage.py makemigrations # Creates one or more new files that must be commited\n\n# Remember to format generated migrations! (using e.g. `make fixme`)\n```\n\n**`poetry.lock` conflicts**\n\nIf you have updated dependencies it's likely you might get conflicts in the Poetry lock file.\nThis solution should resolve most conflicts quite well:\n\n```bash\n$ git rebase origin/master\n\n# If conflicts\n$ git checkout --theirs poetry.lock\n\n$ poetry lock --no-update\n\n# The conflicts should be resolved\n```\n\n\u003e If you get problems it can be a solution to delete the `.venv`, and do a fresh setup\n\n## Code Style\n\nThis codebase uses the PEP 8 code style. We enforce this with `isort`, `black` \u0026 `flake8`. In addition to the standards outlined in PEP 8, we have a few guidelines (see `pyproject.toml` for more info):\n\nFormat the code with `isort` \u0026 `black`\n\n```bash\n$ make fixme\n```\n\nTo check if it is formatted properly, run:\n\n```bash\n$ tox -e isort -e black -e flake8\n```\n\nTo check if it is typed properly, run:\n\n```bash\n$ tox -e mypy\n```\n\n## Tests\n\nIf you want to run a specific test class you can run\n\n```bash\n$ ./manage.py test lego.apps.[APP]\n```\n\nYou can add flags to speed up the tests\n\n\u003e By adding the `--keepdb` the next time it will go a lot faster to run the tests multiple times.\n\n\u003e By adding the `--parallel` will run multiple tests in parallel using multiple cores.\n\nIf you want to check your test coverage, you can do the following\n\n```bash\n# Run all tests in LEGO. Remember to add the recommended flags mentioned above\n$ tox -e tests --\n# or run without tox\n$ coverage run --source=lego ./manage.py test\n\n# If you now have multiple coverage files or a .coverage.* file, you'll have to combine it in order to output report\n$ coverage combine\n\n# Then you can output the full coverage report\n$ coverage report\n# or a small one that only contains the things you are interested in\n$ coverage report | grep [some string]\n```\n\n## Deployment\n\nLEGO runs in `Docker Swarm` and deploys are managed by `Drone` and `Ansible`.\n\nHow to deploy:\n\n1.  Make sure the changes are pushed to master and the test passes.\n2.  Have you added some new settings in `settings/`? If so, make sure the `Ansible variables` reflects these changes.\n3.  We run migrations automatically, make sure they work!\n4.  Push to the `build` branch. From master: `git push origin master:build`\n5.  Wait for the `build` build to complete. The last step will be `docker build`\n6.  Go to [ci.webkom.dev](https://ci.webkom.dev/webkom/lego/) and use the promote feature to deploy the staging/production build.\n\nAnsible will automatically run the playbook for deploying the new build to `staging` or `production` based on the target selected in step 6.\n\n\u003cdetails\u003e\u003csummary\u003e\u003ccode\u003eTesting with elasticsearch\u003c/code\u003e\u003c/summary\u003e\n\n### Testing with elasticsearch\n\nBy default, development and production uses postgres for search. We can still enable elasticsearch backend in prod, so you can 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.\n\n\u003c/details\u003e\n\n\u003cdetails\u003e\u003csummary\u003e\u003ccode\u003eDebugging\u003c/code\u003e\u003c/summary\u003e\n\n### Debugging\n\nIf you get an error while installing project dependencies, you might be missing some on your system.\n\n```bash\n$ apt-get install libpq-dev python3-dev\n```\n\n\u003e For MACOS you need to `brew install postgresql`\n\nIf you get an error while running initialize_development mentioning `elasticsearch`, you probably need to run the following code, and then start over from `docker-compose up -d`. [Read why and how to make it permanent on Elasticsearch docs](https://www.elastic.co/guide/en/elasticsearch/reference/current/vm-max-map-count.html).\n\n```bash\n$ sysctl -w vm.max_map_count=262144\n```\n\nIf you get ld: library not found for -lssl\n\n```\nexport LDFLAGS=\"-L/usr/local/opt/openssl/lib\"\n```\n\nWhen changing the user fixtures one must load new fixtures\n\n```\n./manage.py load_fixtures --generate\n```\n\nAn overview of the available users for development can be found in [this PR](https://github.com/webkom/lego/pull/1913)\n\n\u003c/details\u003e\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fwebkom%2Flego","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fwebkom%2Flego","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fwebkom%2Flego/lists"}