Skip to content

Latest commit

 

History

History
83 lines (52 loc) · 4.06 KB

readme.md

File metadata and controls

83 lines (52 loc) · 4.06 KB

Couchers.org backend

This is the backend for Couchers.org built in Python. The React web frontend and React Native apps make API calls to it using gRPC which are defined via Protocol Buffers. The business logic manipulates a PostgreSQL database via SQLAlchemy. Geospatial features are provided by the PostGIS extension.

Readme last updated: 2024/11/14.

Quick Start

These instructions should work directly on Linux and macOS. If you are using Windows, please install Ubuntu via WSL2, then follow these instructions inside Ubuntu.

You need Docker engine installed. Please refer to the Docker install documentation for how to set it up.

Next, run the follwoing commands to get up and running:

## Check out the repo and navigate to
git clone https://github.com/Couchers-org/couchers.git
cd couchers

## Generate the autogenerated API definitions using protobuf and grpc
cd app
docker run --rm -w /app -v $(pwd):/app registry.gitlab.com/couchers/grpc ./generate_protos.sh

## Build and start the docker containers
docker compose up --build

This will spin up a complete copy of the database, backend, and proxies needed to run the platform.

This will not currently run the frontend, to do that, please follow the instructions in app/web/readme.md under Quick Start, then Running against a local backend.

Running tests in docker

You can run all backend tests in docker with the following command, executed in the app folder:

docker compose -f docker-compose.test.yml up --build

Running tests locally

## Start the test database
cd app
docker compose -f docker-compose.test.yml up --no-deps postgres_tests

## Create a virtual environment and enter it, then install the requirements.
cd backend
python3 -m venv venv
source venv/bin/activate
pip install -r requirements.txt

## Now run the test
DATABASE_CONNECTION_STRING="postgresql://postgres:06b3890acd2c235c41be0bbfe22f1b386a04bf02eedf8c977486355616be2aa1@localhost:6544/postgres" pytest src/tests/

Q/A:

Q: I can't connect to the DB!

A: First doublecheck what port the DB is listening on - run docker compose up postgres and it should say something like listening on IPv6 address "::", port 6545. Then doublecheck you have the right password. There are TWO passwords - one for the test db and one for the normal db! See app/postgres.dev.env and app/postgres.test.env

Here is information for debugging the backend inside VS Code

Q: I'm seeing issues with migrations or the database not being up to date!

A: This happens when you either switch between branches that mutate the database or something else funny happens. The easiest way is to nuke the database:

  1. Stop postgres docker container
  2. Delete the postgres folder in app/data
  3. Re-run docker compose up --build

If you have any trouble, send Aapeli a message on Slack. He's more than happy to spend a bit of time helping you set things up!

Q: How do I log in or sign up when developing?

A: If you are using the local backend, you can log in with the username "aapeli" and the password "Aapeli's password". This comes from the dummy data. For emails, see the next question.

If you are using the live dev api ("next"/staging), it will send you real emails so you can sign up. However, all links will point to next.couchershq.org. If you want to open them with the couchers frontend you are working on locally, change the links to http://localhost:3000/rest/of/the/url.

Q: How do I receive emails like the signup confirmation email in local dev?

A: We run MailDev with the docker compose setup: it will receive emails and let you browse them. To view emails, visit http://localhost:1080.