Asiointitietovaranto Django REST API
Development with Docker
Prerequisites:
- Docker
- Docker Compose
-
Create a
docker-compose.env.yaml
file in the project folder:- Use
docker-compose.env.yaml.example
as a base, it does not need any changes for getting the project running. - Set entrypoint/startup variables according to taste.
DEBUG
, controls debug mode on/offAPPLY_MIGRATIONS
, applies migrations on startupCREATE_ADMIN_USER
, creates an admin user with credentialsadmin
:(password, see below) ([email protected])ADMIN_USER_PASSWORD
, the admin user's password. If this is not given, a random password is generated and written into stdout when an admin user is created automatically.
- Use
-
Run
docker-compose up
- The project is now running at localhost:8081
Optional steps
-
Run migrations:
- Taken care by the example env
docker exec atv-backend python manage.py migrate
-
Create superuser:
- Taken care by the example env
docker exec -it atv-backend python manage.py add_admin_user
Prerequisites:
- PostgreSQL 14
- Python 3.11
- Run
pip install -r requirements.txt
- Run
pip install -r requirements-dev.txt
(development requirements)
To setup a database compatible with default database settings:
Create user and database
sudo -u postgres createuser -P -R -S atv # use password `atv`
sudo -u postgres createdb -O atv atv
Allow user to create test database
sudo -u postgres psql -c "ALTER USER atv CREATEDB;"
- Create
.env
file:touch .env
DEBUG=1
DATABASE_URL=postgres://atv:atv@localhost:5437/atv
# Optionals (with a default value on settings.py)
FIELD_ENCRYPTION_KEYS=
- Set the
DEBUG
environment variable to1
. - Run
python manage.py migrate
- Run
python manage.py add_admin_user
- Run
python manage.py runserver 0:8000
The project is now running at localhost:8000
-
Install
pip-tools
:pip install pip-tools
-
Add new packages to
requirements.in
orrequirements-dev.in
-
Update
.txt
file for the changed requirements file:pip-compile requirements.in
pip-compile requirements-dev.in
-
If you want to update dependencies to their newest versions, run:
pip-compile --upgrade requirements.in
-
To install Python requirements run:
pip-sync requirements.txt
This project uses Ruff for code formatting and quality checking.
Basic ruff
commands:
- lint:
ruff check
- apply safe lint fixes:
ruff check --fix
- check formatting:
ruff format --check
- format:
ruff format
pre-commit
can be used to install and
run all the formatting tools as git hooks automatically before a
commit.
- Set the
DEBUG
environment variable to1
. - Run
pytest
.
Project includes a .git-blame-ignore-revs
file for ignoring certain commits from git blame
.
This can be useful for ignoring e.g. formatting commits, so that it is more clear from git blame
where the actual code change came from. Configure your git to use it for this project with the
following command:
git config blame.ignoreRevsFile .git-blame-ignore-revs