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

documentation for Windows complete #25

Merged
merged 2 commits into from
Jun 7, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
152 changes: 135 additions & 17 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,28 +7,146 @@ This repository contains code for the publicly accessible Sunbird AI APIs.

To get started using the API, [view the tutorial](tutorial.md).

## Getting started locally
## Getting started locally on Windows

#### Ensure virtualization is enabled on your computer

This is required because CPU virtualization is needed for Windows to emulate Linux. For more on enabling [virtualization](https://www.ninjaone.com/blog/enable-hyper-v-on-windows/).

#### Ensure your windows is fully updated.

Install [WSL](https://learn.microsoft.com/en-us/windows/wsl/install) (Windows Subsystem for Linux). This is required because redis is not officially supported on Windows.

### Downloading, Setting Up, and Configuring WSL on Windows
- Open PowerShell as an Administrator and run the following command to enable WSL:
```powershell
wsl --install
```
- Restart your computer if prompted.
- Once the system restarts, set up your Linux distribution (e.g., Ubuntu) from the Microsoft Store.

### After successfully installing `wsl`:

- Press windows button and in the search bar type `windows features on or off`
- Click on `Turn Windows features on or off` and a pop-up window will appear
![features2](features2.png)
- Ensure option `Windows Subsystem for Linux` is checked

![features](features.png)

- Restart your computer and launch Ubuntu

### Cloning the API Repository Locally on Your Windows Machine
- Open your WSL terminal (e.g., Ubuntu).
- Navigate to the directory where you want to clone the repository:
```bash
cd /mnt/c/your-directory
```
- Clone the Sunbird AI API repository:
```bash
git clone https://github.com/SunbirdAI/sunbird-ai-api.git
```

- Continue with `Getting started locally on Linux/macOS`

## Getting started locally on Linux/macOS
To run the app locally:
- Create and activate a local environment
- Install the requirements: `pip install -r requirements.txt`.

```bash
python3 -m venv .venv
source .venv/bin/activate
```
- Install the requirements:
```bash
pip install -r requirements.txt
```
- Set the environment variables in a `.env` file, the following variables are required:
```
SECRET_KEY
DATABASE_URL
RUNPOD_API_KEY
REDIS_URL
RUNPOD_ENDPOINT
AUDIO_CONTENT_BUCKET_NAME
```
**NB: Reach out to the engineering team to get these environment variables.**


### Install [Redis](https://redis.io/), this is required for the Rate Limiting functionality.
```bash
sudo apt update && sudo apt install redis-server
```
ENDPOINT_ID
PROJECT_ID
SECRET_KEY
DATABASE_URL
```
- Install [Redis](https://redis.io/), this is required for the Rate Limiting functionality.
- Start the Redis sever: `sudo service redis-server start` (see docs if you're on Windows without WSL).
- Also make sure the postgres service is running: `sudo service postgresql start`.
- Install [tailwind css](https://tailwindcss.com/docs/installation).
- Run tailwind in a separate terminal tab: `npx tailwindcss -i ./app/static/input.css -o ./app/static/output.css --watch`. This step is only necessary if you're going to make changes to the frontend code.
- Run the app: `uvicorn app.api:app --reload`.

Running the migrations with alembic:
- After making a change to the models, run the command `alembic revision --autogenerate -m 'message'` to make the migrations.
- Start the Redis sever:
```bash
sudo service redis-server start
```
- Verify that Redis is running:

```bash
redis-cli ping
```


### Setting Up and Configuring PostgreSQL Server
- Install PostgreSQL:
```bash
sudo apt-get install postgresql postgresql-contrib
```
- Start the PostgreSQL service:
```bash
sudo service postgresql start
```

- Switch to the PostgreSQL user:
```bash
sudo -i -u postgres
```

- Open the PostgreSQL interactive terminal:
```bash
psql
```

### Install [tailwind css](https://tailwindcss.com/docs/installation).
- Run tailwind in a separate terminal tab:

```bash
npx tailwindcss -i ./app/static/input.css -o ./app/static/output.css --watch
```
This step is only necessary if you're going to make changes to the frontend code.

### Creating PostgreSQL Database and Running Alembic Migrations
- Create a new database:
```sql
CREATE DATABASE sunbird_ai;
```
- Exit the PostgreSQL interactive terminal:
```sql
\q
```
- Navigate to the API repository directory and run Alembic migrations:
```bash
cd your-directory/sunbird-ai-api
alembic upgrade head
```
- Run the app:
```bash
uvicorn app.api:app --reload
```

### Running the migrations with alembic:
- After making a change to the models, run the command below to make the migrations:
```bash
alembic revision --autogenerate -m 'message'
```

- Check the created migration file in `app/alembic/versions` to ensure it does what's expected.
- Apply the migration with `alembic upgrade head`.
- Apply the migration with:
```bash
alembic upgrade head
```


## Deployment
The app is deployed on Google Cloud Run and is backed by PostgreSQL DB hosted in Google Cloud SQL.
Expand Down
Binary file added features.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added features2.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading