Skip to content

Commit

Permalink
Merge branch 'dev' into SN-826
Browse files Browse the repository at this point in the history
  • Loading branch information
ishvindersethi22 authored Sep 5, 2023
2 parents d35b2e8 + 501b3bf commit 2ff35cb
Showing 1 changed file with 59 additions and 17 deletions.
76 changes: 59 additions & 17 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,24 +4,20 @@ Repository for Shoonya's backend.

## Pre-requisites

The project was created using [Python 3.7](https://www.python.org/downloads/). All major dependencies are listed below; the rest are in the `backend/deploy/requirements.txt` file.

- django
- djangorestframework
- django-cors-headers
- djoser
- drf-yasg
- psycopg2
- python-dotenv

The project was created using [Python 3.7](https://www.python.org/downloads/). All major dependencies along with the versions are listed in the `backend/deploy/requirements.txt` file.

## Installation

The installation and setup instructions have been tested on the following platforms:

It can be done in 2 ways:-
1) using docker by running all services in containers or
2) directly running the services on local one by one (like, celery and redis).

If your preference is 1 over 2 please be fixed to this environment and follow the steps below it:

- Docker
- Docker-Compose
- Ubuntu 20.04
- Ubuntu 20.04 OR macOs

If you are using a different operating system, you will have to look at external resources (eg. StackOverflow) to correct any errors.

Expand Down Expand Up @@ -65,7 +61,7 @@ If Google Cloud Logging is being used, please follow these additional steps:
```bash
pip install google-cloud-logging
```
2. Follow the steps to create a Service Account from the following [Google Cloud Documentation Page](https://cloud.google.com/docs/authentication/production#create_service_account). This will create a Service Account and generate a JSON Key for the Service Account.
2. Follow the steps to create a Service Account from the following [Google Cloud Documentation Page](https://cloud.google.com/docs/authentication/production#create_service_account). This will create a Service Account and generate a JSON Key for the Service Account.
3. Ensure that atleast the Project Logs Writer role (`roles/logging.logWriter`) is assigned to the created Service Account.
4. Add the `GOOGLE_APPLICATION_CREDENTIALS` variable to the `.env` file. This value of this variable should be the path to the JSON Key generated in Step 2. For example,

Expand All @@ -78,13 +74,13 @@ GOOGLE_APPLICATION_CREDENTIALS="/path/to/gcloud-key.json"
`cd` back to the root folder .Once inside, build the docker containers:

```bash
docker-compose build
docker-compose -f docker-compose-local.yml build
```

To run the containers:

```bash
docker-compose up -d
docker-compose -f docker-compose-local.yml up -d
```

To share the database with others, just share the postgres_data and the media folder with others.
Expand All @@ -105,12 +101,56 @@ docker-compose exec web python manage.py createsuperuser

If there were no errors, congratulations! The project is up and running.

If your preference is 2 over 1 please be fixed to this environment and follow the steps below it:

- Ubuntu 20.04 OR macOs

You can run the following script and each and every step for setting the codebase will be done directly. Please move to a folder in your local where you would like to store the code and run the script given below there:
```bash
os=$(uname)

if [ "$os" = "Linux" ] || [ "$os" = "Darwin" ]; then

git clone https://github.com/AI4Bharat/Shoonya-Backend.git
cd Shoonya-Backend
git checkout dev
git pull origin dev
cp .env.example ./backend/.env
cd backend
python3 -m venv venv
source venv/bin/activate

pip install -r ./deploy/requirements.txt

new_secret_key=$(python3 -c "from django.core.management.utils import get_random_secret_key; print(get_random_secret_key())")

env_file=".env"
if sed --version 2>&1 | grep -q 'GNU sed'; then
sed -i "/^SECRET_KEY=/d" "$env_file"
else
sed -i.bak "/^SECRET_KEY=/d" "$env_file"
rm -f "$env_file.bak"
fi

echo "SECRET_KEY='$new_secret_key'" >> "$env_file"

echo "New secret key has been generated and updated in $env_file"

else
echo "Cannot run this script on: $os"
fi
```

### Running background tasks
Please install and run redis from https://redis.io/download/ on port 6379 before starting celery.

To run background tasks for project creation, we need to run the following command in the terminal. This has also been added into the `docker-compose.yml` file.
```bash
celery command - celery -A shoonya_backend.celery worker -l info
celery command - celery -A shoonya_backend.celery beat --loglevel=info
```
```

You can set use the celery to local by modifying CELERY_BROKER_URL = "redis://localhost:6379/0" in ./backend/shoonya_backend/settings.py.

We can set the concurrency and autoscale in the process as well to manage the number of worker processes in the background. Read more [here](https://stackoverflow.com/a/72366865/9757174).

Expand All @@ -122,9 +162,11 @@ celery -A shoonya_backend.celery worker --autoscale=10,3 --loglevel=info

### Running Linters

Installing the dev requirements file would have also installed the linter. For project Shoonya, we use `black`
In case you want to raise a PR, kindly run linters as specified below. You can install black by running pip install black and use `black`
To run `black` do:

```bash
black ./backend/
```

Happy Coding!!

0 comments on commit 2ff35cb

Please sign in to comment.