Skip to content

Latest commit

 

History

History
59 lines (41 loc) · 1.75 KB

localdev.md

File metadata and controls

59 lines (41 loc) · 1.75 KB

How-to run API locally

Steps to run django server in a virtualenv, without needing a k8s cluster. For now only isolated mode is supported: without assert registration or task computation.

Quickstart

Start postgres instance

make db

Activate a virtualenv, then run the commands:

make install  # install python dependencies
make quickstart  # wait for db, run migrations, create a user, start the server
make fixtures  # generate assets fixtures

Alternatively, you can run it inside a container by using dev target (adapt to mount volumes you need).

docker build -f docker/substra-backend/Dockerfile --target dev -t substra-backend .
docker run -it --name substra-backend --rm -p 8000:8000 \
  -v ${PWD}/backend/substrapp:/usr/src/app/substrapp \
  -e DJANGO_SETTINGS_MODULE=backend.settings.localdev \
  -e ISOLATED=1 \
  -e BACKEND_DB_HOST=$(docker inspect -f '{{range.NetworkSettings.Networks}}{{.IPAddress}}{{end}}' postgres) \
  substra-backend sh dev-startup.sh
docker exec substra-backend python manage.py generate_fixtures

(Optional) Restore a dump

Warning: it will erase the database content (user, fixtures, etc).

cat dump-file.sql | docker exec -it postgres psql postgresql://backend:backend@localhost:5432/backend_default

(Optional) Use another DB

Install postgres on macOS

You can use edb bundle (version >= 11). This comes with pgAdmin 4.

brew install postgres  # install the psql client

Create a database

Create a backend_default database. To use another name, set the BACKEND_DB_NAME env var accordingly.

psql postgresql://backend:backend@localhost:5432/backend_default -c "CREATE DATABASE backend_default;"