Skip to content
Open
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
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ git clone https://github.com/uwblueprint/llsc.git
cd llsc
```

- Create a .env file in the root directory based on the .env.sample file. Update
- Create a .env file in `./backend` and `./frontend` based on the .env.sample file. Update
the environment variables as needed. Consult the [Secrets](#secrets) section
for detailed instructions.

Expand Down
13 changes: 13 additions & 0 deletions backend/Dockerfile.db
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
FROM postgres:16-alpine

# Set environment variables for PostgreSQL
ENV POSTGRES_USER=${POSTGRES_USER}
ENV POSTGRES_PASSWORD=${POSTGRES_PASSWORD}
ENV POSTGRES_DB=${POSTGRES_DATABASE}

# Add a health check for the PostgreSQL server
HEALTHCHECK --interval=5s --timeout=5s --retries=5 \
CMD pg_isready -U ${POSTGRES_USER} || exit 1

# Expose PostgreSQL port
EXPOSE 5432
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Question when we run pdm run dev are we currently connecting to the right db port so that we automatically connect to the db when running locally?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yep 5432 is the current default db port.

28 changes: 21 additions & 7 deletions backend/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,15 @@ Ensure you have the following installed on your machine:
```
- **Docker**


- Create a `.env` file in `./backend` (the root directory, not in the backend folder) based on the .env.sample file. Update
the environment variables as needed. Consult the [Secrets](#secrets) section
for detailed instructions.

```bash
cp .env.sample .env
```

## Installation

Once PDM is installed, install the project dependencies by running:
Expand All @@ -28,20 +37,25 @@ pdm install
to install all the project dependancies listed in the `pyproject.toml` file.

## Running the Backend Locally
To start the backend locally, use the following command:

To start up the database using docker, run the following command:
```bash
pdm run dev
cd backend
pdm run db
```

Note: If you wish to run the backend outside of Docker (e.g., for local development), you'll need to set up a PostgreSQL database. Ensure your database configuration is set properly in the environment variables before running the project. For the time being, the recommended approach for local development using the database is to use the docker compose Postgres instance with your local dev backend.

To check if the database has been started up, type the following:
```bash
docker ps | grep llsc_db
docker ps | grep llsc_db_dev_local
```
This checks the list of docker containers and searchs for the container name `llsc_db`
This checks the list of docker containers and searchs for the container name `llsc_db_dev_local`

Note: If you wish to run the backend outside of Docker (e.g., for local development), you'll need to set up a PostgreSQL database. Ensure your database configuration is set properly in the environment variables before running the project.

To start the backend locally, use the following command:

```bash
pdm run dev
```
## Run Project

Take advantage of the docker compose file in the LLSC root directory to run the backend alongside the frontend by simply running
Expand Down
1 change: 1 addition & 0 deletions backend/pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ precommit = "pre-commit run"
precommit-install = "pre-commit install"
revision = "alembic revision --autogenerate"
upgrade = "alembic upgrade head"
db = "bash start_db_local.sh"

[tool.ruff]
target-version = "py312"
Expand Down
16 changes: 16 additions & 0 deletions backend/start_db_local.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
#!/bin/bash

envfile=".env"

# Prioritize base dir .env over backend dir .env, as docker-compose should pull from there
if [ -s "../.env" ]; then
envfile="../.env"
fi

docker build -t llsc_db_dev_local -f Dockerfile.db .
docker run -d \
--name llsc_db_dev_local \
--env-file $envfile \
-p 5432:5432 \
-v llsc_postgres_data:/var/lib/postgresql/data \
llsc_db_dev_local