Configure for Local Debugging and Development
This document describes how to set up the project for local debugging and development.
Prerequisites
Setup
Clone the repository and cd into the project directory.
Create a pixi environment live_data_server, containing all the dependencies
pixi install
pixi shell
To deploy this application locally, you will need to set a number of environment variables, for example (bash):
export DATABASE_NAME=livedatadb
export DATABASE_USER=livedatauser
export DATABASE_PASS=livedatapass
export DATABASE_HOST=db
export DATABASE_PORT=5432
export LIVE_PLOT_SECRET_KEY="secretKey"
# These need to be set for `pytest`,
# but are not used in the docker compose
export DJANGO_SUPERUSER_USERNAME=$DATABASE_USER
export DJANGO_SUPERUSER_PASSWORD=$DATABASE_PASS
NOTES:
The
DATABASE_PORTmust be set to5432, as Postgres is configured to listen on that port by default. If you need to change the port, you will need to modify thedocker-compose.ymlfile accordingly.It is recommended to save these variables into an
.envrcfile which can be managed by direnv. direnv will automatically load the variables when youcdinto the project directory.
After the secrets are set, you can start the server with:
make docker/compose/local
This command will copy deploy/docker-compose.envlocal.yml into ./docker-compose.yml before composing all the services.
make help to learn about other macros available as make targets.make docker/pruneall will stop all containers, then remove all containers, images, networks, and volumes.Testing
After the setup, with the server running, you can test your setup with pytest:
# run all tests
pytest
# or run a specific test
pytest tests/test_post_get.py
NOTE:
The environment variables DJANGO_SUPERUSER_USERNAME and DJANGO_SUPERUSER_PASSWORD are defined in the docker-compose.envlocal.yml file, but pytest does not read this file.
You must either have them exported to the shell where pytest is to be run, as described above, or modify the pytest command to include them, e.g.:
DJANGO_SUPERUSER_USERNAME=***** DJANGO_SUPERUSER_PASSWORD=***** pytest
API
I personally recommend using Postman when interacting with the api.
If you do, set the request body to form-data!
Some relevant form-data field keys:
file
username
password
data_id