This is abi back source code repository, build with Django1.11, PostgreSQL with a Multitenant architecture based on django-tenants-schemas.
To configure this project, please follow the next instructions:
- You already have python 3.6 installed in your local machine
- You already have git installed on your local machine
- You already have installed postgresql 9.6 installed on your local machine
docker run \
--name postgres \
-e POSTGRES_PASSWORD=<your_secret_password> \
-v ${PWD}/pgdata:/var/lib/postgresql/data \
-p 5432:5432 \
-d postgres:9.6.8-alpine
mkvirtualenv -p python3.6 abi
python -m venv abiveenv
git clone --recurse-submodules https://github.com/abi-medical/abi-back
cd abi-back
pip install -r requirements.txt
If you're having problems with psycopg on windows, check this page, download the right .exe file and try run
easy_install psycopg2-2.6.2.win-<windows_architecture>-py<python_version>-pg9.5.3-release.exe
If you're having problems installing psycopg on ubuntu
apt install libpq-dev
Use your favorite postgreSQL client and execute the following commands
CREATE role <your_user_name> noinherit login password '<your_password>';
CREATE DATABASE <database_name> owner <your_user_name>;
ALTER USER <your_user_name> CREATEDB;
-- To run <your_user_name> must be superuser and this is so dangerous
ALTER USER <your_user_name> superuser;
Before run the project for the first time you must execute the following commands
python manage.py makemigrations
python manage.py migrate_schemas --shared
python manage.py configure_public_tenant
Now as we does not want to leave database access information on our control version system
We're going to store credentials in a file local_variables.sh
(Mac and Linux) or local_variables.bat
(Windows) . You can get an idea of the content
looking at local_variables.sh.copy
or loca_variables.bat.copy
. Remeber that you must create your file and insert proper data
Then execute your server in this order
source local_variables.sh
ABI_DATABASE_DATABASE=${ABI_DATABASE_DATABASE} ABI_DATABASE_USERNAME=${ABI_DATABASE_USERNAME} ABI_DATABASE_PASSWORD=${ABI_DATABASE_PASSWORD} ./manage.py runserver 8000
On windows do
call local_variables.bat
./manage.py runserver 8000
You may also want to create a super user on main schema to create new schemas
source local_variables.sh
ABI_DATABASE_DATABASE=${ABI_DATABASE_DATABASE} ABI_DATABASE_USERNAME=${ABI_DATABASE_USERNAME} ABI_DATABASE_PASSWORD=${ABI_DATABASE_PASSWORD} ./manage.py createsuperuser
After a superuser is created, next step is to create a tenant, go to http://localhost:8000/tenant and create a first tenant.
Now we need to create a super user for this tenant, execute
python manage.py create_tenant_superuser
and go to http://<tenant_name>.localhost:8000
For the first time:
git submodule update --init --recursive
Then to update modules
git submodule update --recursive --remote
Before you push, make sure you git are configured to ignore all pyc files, you can configure a global gitignore
following this gist and in your current global gitignore file put this
*.pyc
We exposed an API, you can find documentation in /api/v1/docs/
This works on a tenant host.
Main endpoint is /api/v1/core/machineinput/
which receives a
machine_instance
: intprocedure
: intcontent
: text
First two parameters are foreign keys to instances on db, last one is the machine report on UTF-8 encoding
docker service update --label-add "traefik.frontend.rule=HostRegexp:abi.contraslash.com, {subdomain:[a-z0-9]+}.abi.contraslash.com" abi