Multi-user (Host setup)
Follow the steps below to setup multiuser mode.
Clone the Repository
In your hosting server, clone the OptiNiSt repository.
git clone git@github.com:oist/optinist.git -b main
setup application config files
cp -i studio/config/.env.example studio/config/.env cp -i studio/config/auth/firebase_config.example.json studio/config/auth/firebase_config.json
Setup Firebase Authentication
Create your Firebase Project
Click “Add project”.
Enter your project name, and click “Continue”.
Google Analytics is optional. You can choose “Enable Google Analytics for this project” or not.
After your project is ready, click “Continue”.
Setup Firebase Authentication
Select “Build > Authentication” from the left menu.
Select “Get started”.
Select “Sign-in method” tab.
Select “Add new provider” in “Sign-in providers” section.
Click “Email/Password” and enable it.
Click “Save”.
Create Admin User for the Project
Select “Authentication” from the left menu.
Select “Users” tab.
Click “Add user” button.
Fill the form and click “Add user”.
Email address: your email address
Password: your password
Created user’s “User UID” is required later.
Get Firebase Tokens
Click setting icon(besides Project Overview), then select “Project settings” from the left menu.
Select “General” tab.
Select “web app” in “Your apps” section.
Enter your app name, and click “Register app”.
“Also set up Firebase Hosting for this app” is not required.
Click continue to console.
Set the following values to
studio/config/auth/firebase_config.json.apiKey
authDomain
projectId
storageBucket
messagingSenderId
appId
(keep databaseURL blank)
Select “Service accounts” tab.
Click “Generate new private key” in “Firebase Admin SDK” section.
Save the downloaded file to
studio/config/auth/firebase_private.json.
Setup Database
Set up your own mysql (or mariadb) server or use docker compose mysql
Below are the instructions for using mysql with docker compose.
Edit configs.
Edit studio/config/.env
Set
MYSQL_SERVERto db server host or ipFormat:
{DB_HOST}:{DB_PORT}*For docker platform, the fixed value
db:3306is fine.
Set
MYSQL_ROOT_PASSWORDto database root password, which you have decided.Set
MYSQL_DATABASEto{YOUR_DATABASE_NAME}, which you have decided.Set
MYSQL_USERto{DB_USER_NAME}, which you have decided.Set
MYSQL_PASSWORDto{DB_USER_PASSWORD}, which you have decided.
Install & run mysql server.
docker compose -f docker-compose.dev.multiuser.yml up db -d
The database and db_user are automatically generated based on the .env settings.
Check connection to mysql server.
Connecting via docker command
docker exec -it {DB_CONTAINER_NAME} mysql -u {DB_USER_NAME} -p {YOUR_DATABASE_NAME} mysql> exit
Note:
{DB_CONTAINER_NAME}is the container name or container ID of the database docker container. (Can be confirmed withdocker ps)
Connect via mysql command (requires mysql-client)
mysql -h {DB_HOST} --port={DB_PORT} -u {DB_USER_NAME} -p {YOUR_DATABASE_NAME} mysql> exit
If a connection to the database server is available, the setup was successful.
Setup & Run OptiNiSt
For Docker Platform
To use multiuser mode with Docker, perform the following steps.
Setup Backend
Set OptiNiSt Config
Edit
studio/config/.envChange
SECRET_KEYto any random string.Change
USE_FIREBASE_TOKENtoTrue.Change
IS_STANDALONEtoFalse
Start Backend (Database is set up on startup)
docker compose -f docker-compose.dev.multiuser.yml up studio-dev-be -d
Insert Initial Data
docker exec -it {DB_CONTAINER_NAME} mysql -u {DB_USER_NAME} -p {YOUR_DATABASE_NAME}
Make an initial sql entry
INSERT INTO organization (name) VALUES ('{YOUR_ORGANIZATION_NAME}');
INSERT INTO roles (id, role) VALUES (1, 'admin'), (20, 'operator');
INSERT INTO users (uid, organization_id, name, email, active) VALUES ('{FIREBASE_USER_UID}', 1, '{YOUR_NAME}', '{YOUR_EMAIL}', true);
INSERT INTO user_roles (user_id, role_id) VALUES (1, 1);
Note on Variables
{FIREBASE_USER_UID}… The user uid you created in the previous step (Create admin user for the project).{YOUR_ORGANIZATION_NAME}… Display name on system (Any text){YOUR_NAME}… Display name on system (Any text){YOUR_EMAIL}… Email address corresponding to{FIREBASE_USER_UID}
About Roles
Only 2 roles, “admin” and “operator” are supported for now.
“admin”
can manage other users
“operator”
general user
More information is here.
Run OptiNiSt
docker compose -f docker-compose.dev.multiuser.yml up -d
Access to
http://{YOUR_HOST}:8000from your browser.Confirm that you can SingIn with your Firebase Authentication account.
For Non-Docker Platforms
Below are the steps for a case using Non-Docker platforms (Windows, Mac, Linux).
Setup Backend
See OptiNiSt installation guide for installing conda and optinist for installing conda and optinist.
After creating and activating a conda environment for the project, run following commands
Set OptiNiSt Config
Follow the steps to change the
.envfile to multi-user mode, see Set OptiNiSt config.
Setup Database
cd {OPTINIST_ROOT_PATH} # root path of repository cloned
alembic upgrade head
Insert Initial Data
To setup the database we need to insert some initial data. Follow the procedure in Insert Initial Data, but remove the initial command
docker exec -it {DB_CONTAINER_NAME}, as not using Docker. Instead to add initial data and setup database, use:
mysql -u {DB_USER_NAME} -p {YOUR_DATABASE_NAME}
Run OptiNiSt
python main.py
Access to
http://{YOUR_HOST}:8000from your browser (most likelyhttp://localhost:8000).Confirm that you can SingIn with your Firebase Authentication account.