This is the updated version of Metabolitics API.
-
Clone metabolitics-api-v3 repository. Checkout to your branch.
https://github.com/itu-bioinformatics-database-lab/metabolitics-api-v3.git
-
Install Anaconda. Create a Conda environment.
conda config --append channels conda-forge
conda create --name menv python=3.5.2
conda activate menv
-
Install required Python packages.
pip install -r requirements.txt
-
Create a local PostgreSQL database. Set up connection in src/app/config.py file.
-
Create database schema under src directory.
python main.py migrate
-
Install Redis.
-
Generate secret.txt file under src directory.
python main.py generate-secret
-
Start the API under src directory.
python main.py run-api
-
Start Celery worker under src directory.
python main.py run-celery
-
Start Celery beat under src directory.
python main.py run-celery-beat
Developing Metabolitics API inside a Docker container built from Dockerfile ensures a fully compatible development environment with all of the features of Visual Studio Code.
-
Install and configure Docker for your operating system.
-
Install Visual Studio Code.
-
Install the Dev Containers extension from Visual Studio Code Extensions.
-
Clone metabolitics-api-v3 Git repository by running the below command in a terminal.
git clone https://github.com/itu-bioinformatics-database-lab/metabolitics-api-v3.git
-
Open Visual Studio Code and run Dev Containers: Open Folder in Container... command from View -> Command Palette.
-
Select metabolitics-api-v3 repository.
-
Select From 'Dockerfile' from Add Dev Container Configuration Files dialog.
-
Don't select any features and click Ok.
-
Wait for the container to install.
-
To generate secret.txt file, run the below command in a terminal under src directory.
python main.py generate-secret
-
To resolve Git line ending issues in the container (resulting in many modified files), see below link:
https://code.visualstudio.com/docs/devcontainers/tips-and-tricks
-
To create a local PostgreSQL database in Docker, run the below command in a terminal.
docker run --name postgres -p 5432:5432 -e POSTGRES_USER=postgres -e POSTGRES_PASSWORD=boss123 -e POSTGRES_DB=postgres -d postgres:9.4
-
To see the IP address of the database, run the below command in a terminal.
docker inspect postgres
-
Set connection details of the database using the IP address from the step 13 in src/app/config.py.
SQLALCHEMY_DATABASE_URI = 'postgresql://postgres:[email protected]/postgres'
-
To migrate data to the newly created database, run the below command in a terminal under src directory.
python main.py migrate
-
To install Redis server in Docker, run the below command in a terminal.
docker run --name redis -p 6379:6379 -d redis
-
To connect Metabolitics Api and Redis, run below commands in a terminal one by one.
docker network create metabolitics
docker network connect metabolitics <metabolitics-api>
docker network connect metabolitics redis
-
To run metabolitics-api-v3, run the below command under src directory and open localhost:5000.
gunicorn --bind 0.0.0.0:5000 --workers=2 app:app --reload
-
To run Celery, run the below command under src directory
celery -A app.celery worker
Visit following links for more information:
https://code.visualstudio.com/docs/devcontainers/containers
https://code4it.dev/blog/run-postgresql-with-docker/
https://medium.com/idomongodb/installing-redis-server-using-docker-container-453c3cfffbdf
https://saggu.medium.com/how-to-connect-nultiple-docker-conatiners-17f7ca72e67f
If CORS error is encountered during development, visit following link:
https://medium.com/@dtkatz/3-ways-to-fix-the-cors-error-and-how-access-control-allow-origin-works-d97d55946d9