Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Include multi-tenancy in SortingHat #755

Merged
merged 1 commit into from
Apr 18, 2023
Merged

Conversation

jjmerchante
Copy link
Contributor

@jjmerchante jjmerchante commented Apr 5, 2023

This PR allows hosting multiple instances with a single service having each instance's data isolated in different databases.

To configure it you need to:

  • Set MULTI_TENANT setting to True.
  • Define the databases in a JSON file, you can use the default file provided at sortinghat/config/tenants.json
{
  "tenants": ["sh1", "sh2"]
}
  • Run the configuration script and run SortintgHat
  • Assign users to tenants with set-user-tenant command.
sortinghat-admin set-user-tenant admin localhost:8001 sh1
sortinghat-admin set-user-tenant admin localhost:8002 sh2
  • Run a nginx to host multiple instances of SortingHat. docker-compose.yml and nginx.conf example files:
version: '2.2'
services:
    nginx:
      image: nginx:latest
      volumes:
        - ./nginx.conf:/etc/nginx/conf.d/default.conf
      network_mode: "host"
server {
  listen 8001;

  server_name localhost 127.0.0.1;

  location / {
     proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
     proxy_set_header Host $http_host;
     proxy_redirect off;
     proxy_pass http://127.0.0.1:8000;
  }
}

server {
  listen 8002;

  server_name localhost 127.0.0.1;

  location / {
     proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
     proxy_set_header Host $http_host;
     proxy_redirect off;
     proxy_pass http://127.0.0.1:8000;
  }
}
  • Run 2 instances of the UI (it can be deployed serving static files with NGINX):
yarn serve --api_url=http://localhost:8001/api/
yarn serve --api_url=http://localhost:8002/api/

In this case, if you login into both instances with the user admin, the changes in one of them won't be shown in the other and the other way around.

@jjmerchante jjmerchante force-pushed the multi-tenant branch 2 times, most recently from 608938b to 7c43b14 Compare April 5, 2023 15:03
Copy link
Member

@sduenas sduenas left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In overall, it looks good but we should add some tests to check if the multitenancy works. Problably just something like to have two tenants, write individuals to them, and check data is correctly inserted.

Also, we should also check that the tenant name is correctly stored on the logs entries on the database.

sortinghat/core/middleware.py Show resolved Hide resolved
sortinghat/core/middleware.py Show resolved Hide resolved
sortinghat/core/tenant.py Outdated Show resolved Hide resolved
@jjmerchante jjmerchante force-pushed the multi-tenant branch 5 times, most recently from e652c2b to 9ba7466 Compare April 17, 2023 15:04
sortinghat/config/settings.py Outdated Show resolved Hide resolved
This commit allows to have multiple databases and use each
of them depending on data available in the request.

To configure it you need to set MULTI_TENANT_ENABLED setting
to True, define multiple tenants in `sortinghat/config/tenants.json`
file and assign users to tenants using 'sortinghat-admin set-user-tenant'
command.

Users and tenants relationships will be stored in 'default'
database and other data will be stored in each tenant.

Signed-off-by: Jose Javier Merchante <jjmerchante@bitergia.com>
Copy link
Member

@sduenas sduenas left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@sduenas sduenas merged commit c6029ee into chaoss:master Apr 18, 2023
10 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants