To run it, it's necessary to have Poetry installed. Then run,
poetry install
To configure the database connection, the Backend uses a DB_DEFAULT
variable
that must have a JSON string such as:
export DB_DEFAULT="{
\"ENGINE\": \"${DB_DEFAULT_ENGINE:=django.db.backends.postgresql}\",
\"NAME\": \"${DB_DEFAULT_NAME:=playground_kcidb}\",
\"USER\": \"${DB_DEFAULT_USER:=<DB-USER>}\",
\"PASSWORD\": \"<DB-PASSWORD>\",
\"HOST\": \"${DB_DEFAULT_HOST:=127.0.0.1}\",
\"PORT\": \"${DB_DEFAULT_PORT:=5432}\",
\"CONN_MAX_AGE\": ${DB_DEAFULT_CONN_MAX_AGE:=null},
\"OPTIONS\": {
\"connect_timeout\": ${DB_DEFAULT_TIMEOUT:=2}
}
}"
Attention to and placeholders
After connecting to Google Cloud, execute the server with:
poetry run python3 manage.py runserver
The backend includes unit tests covering some parts of the source code. To run the tests, use the following command:
# run this for each test file in kernelCI_app/unitTests/
poetry run python kernelCI_app/unitTests/<file-name.test.py>
Currently you must run this command for each test file in the kernelCI_app/unitTests/
directory.
To check if it is ready for a deploy you can run
poetry run python3 manage.py check --deploy
To generate a DJANGO_SECRET_KEY
you can use
openssl rand -base64 22
or
export DJANGO_SECRET_KEY=$(openssl rand -base64 22)
We are not using sessions or anything like that right now, so changing the secret key won't be a big deal.
In the /requests
directory we have scripts that execute requests to endpoints using httpie
For debugging we have two env variables
DEBUG
and DEBUG_SQL_QUERY
that can be set to True
to enable debugging. The reason DEBUG_SQL_QUERY
is separated is that it can be very verbose.
You can update the OpenAPI schema by running the generate-schema.sh
script
You are free to use whichever tool you would like, but here are tips for specific IDEs
In order to debug backend in PyCharm, just follow these steps:
- open contents of
backend
in PyCharm - click over Python version at the bottom right window corner, then
Add New Interpreter
->Add Local Interpreter...
- click on
Poetry Environment
, selectExisting Interpreter
and then findpython
executable on correspondent folder. - at the top bar, on the bug icon, create a configuration with the following parameters:
- in
Run
session of the dialog, selectscript
, then find the scriptmanage.py
at thebackend
folder - at
script
name input, just enterrunserver
- at
Environment Variables
, enter the following values:DB_DEFAULT
:{"ENGINE": "django.db.backends.postgresql", "NAME": "playground_kcidb", "USER": "<youremail>@profusion.mobi", "PASSWORD": "<yourpassword>", "HOST": "127.0.0.1", "PORT": "5432", "CONN_MAX_AGE": null, "OPTIONS": {"connect_timeout": 2, "sslmode": "disable"}}
DEBUG
:True
- in
Quote character in password field is escaped normally with \"
.