Skip to content

Commit

Permalink
Merge pull request #88 from qase-tms/docs/how-to-start-project-local
Browse files Browse the repository at this point in the history
DOCS: created README.md and docker-compose.yml for local running the project
  • Loading branch information
serikovlearning committed May 4, 2024
2 parents a84c836 + 4807ea3 commit 2220c8e
Show file tree
Hide file tree
Showing 2 changed files with 91 additions and 0 deletions.
73 changes: 73 additions & 0 deletions backend/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
### How to run the project

#### Installing dependencies

1. **Required python version:** 3.11.6+ (To avoid installing many versions on your OS and changing PATH you can use [pyenv](https://github.com/pyenv/pyenv))
2. Open the `backend` directory.
3. Create and activate a virtual environment following these commands (may don't on Windows):
* To create a virtual environment, only needed for the first time
```bash
python -m venv ./.venv
```
* To activate the virtual environment
```bash
source .venv/bin/activate
```
4. Install dependencies using [poetry](https://python-poetry.org/):
* To install poetry in the virtual environment
```bash
pip install poetry
```
* To check if the installation was successful
```bash
pip list
```
* To install all needed dependencies
```bash
poetry install
```
---
#### Run project
1. Ensure your local database is migrated and ready for use.
2. Go back to the `shelterpaws` directory
3. Configure PYTHONPATH:
```bash
export PYTHONPATH=":shelterpaws/backend"
```
4. Start the application
```bash
python backend/main.py
```

---
#### How to prepare local database for the first time
1. You should [docker](https://www.docker.com/) have installed
2. Check if your `shelterpaws/backend/docker-compose.db.yml` credentials match those in `shelterpaws/backend/settings/local.py.`
2. Run docker compose file in `shelterpaws\backend` directory:
```bash
docker compose -f docker-compose.db.yml up
```
3. Check connection to local db using [dbeaver](https://dbeaver.io/) or another tool
4. Complete the database migrations.
---
#### How to make or run migrations
1. Ensure `PYTHONPATH` is configured
2. To create new migration:
```bash
python backend/database/manage.py alembic makemigrations "${YOUR_MESSAGE}"
```
3. To run existing migration:
```bash
python backend/database/manage.py alembic upgrade
```
4. To downgrade database:
```bash
python backend/database/manage.py alembic downgrade
```
---
### Another way to run the project
1. You should [docker](https://www.docker.com/) have installed
2. Run docker compose file in `shelterpaws` directory (you should have `shelterpaws/backend/.env` file):
```bash
docker compose up
```
18 changes: 18 additions & 0 deletions backend/docker-compose.db.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
version: '3.3'

services:
psql:
image: postgres
environment:
POSTGRES_DB: "shelterpaws-testing-db"
POSTGRES_USER: "postgres"
POSTGRES_PASSWORD: "postgres"
volumes:
- './docker/database:/var/lib/psql'
ports:
- "5432:5432"
networks:
- secret-local

networks:
secret-local:

0 comments on commit 2220c8e

Please sign in to comment.