-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #36 from CS3219-AY2425S1/PEER-118,256-Match-Collab…
…-Svc [PEER-118][PEER-256] Add Matching Svc, Dockerize Collab Svc
- Loading branch information
Showing
48 changed files
with
328 additions
and
529 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,29 +1,23 @@ | ||
USER_PGDATA="/data/user-db" | ||
USER_EXPRESS_DB_PORT=5431 | ||
|
||
QUESTION_PGDATA="/data/qn-db" | ||
QUESTION_EXPRESS_DB_PORT=5433 | ||
|
||
COLLAB_PGDATA="/data/collab-db" | ||
COLLAB_EXPRESS_DB_PORT=5434 | ||
|
||
MATCHING_PGDATA="/data/collab-db" | ||
MATCHING_EXPRESS_DB_PORT=5434 | ||
|
||
USER_SERVICE_NAME=user-express | ||
USER_EXPRESS_DB_PORT=5431 | ||
USER_EXPRESS_ENV=compose | ||
USER_EXPRESS_PORT=9001 | ||
USER_PGDATA="/data/user-db" | ||
|
||
QUESTION_SERVICE_NAME=question-express | ||
QUESTION_EXPRESS_ENV=compose | ||
QUESTION_EXPRESS_PORT=9002 | ||
QUESTION_EXPRESS_ENV=compose | ||
QUESTION_EXPRESS_DB_PORT=5433 | ||
QUESTION_PGDATA="/data/qn-db" | ||
|
||
COLLAB_CONTAINER_NAME=collab-express | ||
COLLAB_SERVICE_NAME=collab-express | ||
COLLAB_EXPRESS_ENV=compose | ||
COLLAB_EXPRESS_PORT=9003 | ||
|
||
MATCHING_SERVICE_NAME=match-express | ||
MATCHING_EXPRESS_ENV=compose | ||
MATCHING_EXPRESS_PORT=9004 | ||
|
||
FRONTEND_SERVICE_NAME=frontend | ||
FRONTEND_ENV=compose | ||
FRONTEND_PORT=3000 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
# To be injected by Docker Compose | ||
# PEERPREP_UI_HOST="http://frontend:3000" | ||
|
||
EXPRESS_PORT=9003 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
PEERPREP_UI_HOST="http://host.docker.internal:5173" | ||
|
||
EXPRESS_PORT=9003 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,3 @@ | ||
EXPRESS_ENV="local" | ||
EXPRESS_DB_HOST="localhost" | ||
EXPRESS_DB_PORT=5434 | ||
POSTGRES_DB="collab" | ||
POSTGRES_USER="peerprep-collab-express" | ||
POSTGRES_PASSWORD="/86awM+Izo6949YgEQIls8HU+j5RlFYEInRy8auiNa8=" | ||
PGDATA="/data/collab-db" | ||
PEERPREP_UI_HOST="http://localhost:5173" | ||
|
||
EXPRESS_PORT=9003 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,140 +1 @@ | ||
# Template Service | ||
|
||
This directory contains the code for the Template | ||
Service. | ||
|
||
## Database | ||
|
||
We use: | ||
|
||
- PostgreSQL 16 for the database. To run it, we use: | ||
- Docker to run the database, as well as inject any user-defined | ||
configurations or SQL files into the Docker image. | ||
- Docker-Compose to run the database, as well as any other | ||
services this API microservice may depend on. | ||
- [**Drizzle**](https://orm.drizzle.team/) for the ORM. | ||
|
||
Follow the instructions below for the setup, as well as to learn how to work with the database. | ||
|
||
### Setup | ||
|
||
1. Install Docker Desktop on your device. Launch it. | ||
|
||
2. To verify that it is launched and installed correctly, run the | ||
following in your terminal: | ||
|
||
```bash | ||
docker --version | ||
``` | ||
|
||
If the command does not error, and outputs a version, proceed to | ||
the next step. | ||
|
||
3. Inspect the `docker-compose.yml` file. It | ||
should look like this: | ||
|
||
```yml | ||
services: | ||
# ... | ||
postgres: | ||
# ... | ||
volumes: | ||
- "template-db-docker:/data/template-db" | ||
# - ./init.sql:/docker-entrypoint-initdb.d/init.sql | ||
ports: | ||
- "5431:5432" | ||
restart: unless-stopped | ||
|
||
volumes: | ||
template-db-docker: | ||
external: true | ||
``` | ||
|
||
We observe that this Database relies on a | ||
Docker Volume. Replace all instances of | ||
`template-db-docker` with your desired | ||
volume name. | ||
|
||
4. Then, create the Docker Volume with | ||
the following command: | ||
|
||
```bash | ||
# in this case, the command is | ||
# docker volume create template-db-docker | ||
docker volume create <volume-name> | ||
``` | ||
5. Finally, create the Database Container: | ||
|
||
```bash | ||
docker-compose up -d | ||
``` | ||
|
||
6. To bring it down, run this command: | ||
|
||
```bash | ||
docker-compose down | ||
``` | ||
|
||
### Schema | ||
|
||
We maintain the schema in the `src/lib/db/schema.ts` file. | ||
|
||
Refer to the Drizzle documentation to learn how | ||
to properly define schemas. Then, insert your | ||
schemas into the file. | ||
|
||
### Migration | ||
|
||
After you have created/updated your schemas in | ||
the file, persist them to the Database with | ||
Migrations. | ||
|
||
1. Configure your credentials (port, | ||
password, ...) in: | ||
|
||
- `drizzle.config.ts` | ||
- `drizzle.migrate.mts`. | ||
- `src/lib/db/index.ts`. | ||
|
||
In the future, we may wish to migrate these | ||
credentials to environment variables. | ||
|
||
2. Run the `npm run db:generate` command to | ||
generate your `.sql` Migration Files under the | ||
`drizzle` folder. | ||
|
||
3. Rename your | ||
`<migration_num>_<random_name>.sql` file | ||
to `<migration_num>_<meaningful_name>.sql`. | ||
|
||
For example: | ||
- Generated: `0000_dazzling_squirrel.sql` | ||
- Renamed: `0000_initial_schema.sql`. | ||
|
||
Then, rename the | ||
`meta/_journal.json` tag from | ||
`0000_dazzling_squirrel` to | ||
`0000_initial_schema` as well. Replace the | ||
migration number and name with the one you | ||
used. | ||
|
||
4. Finally, run the migration with this: | ||
|
||
```bash | ||
npm run db:migrate | ||
``` | ||
|
||
### Connecting with the DB | ||
|
||
1. Import the `db` instance from `lib/db`. | ||
2. Use the Drizzle APIs and the tables defined in | ||
`src/lib/schema.ts` to interact with the | ||
tables. | ||
|
||
```ts | ||
import { db, tableName } from '../lib/db'; | ||
const route = async (req, res) => { | ||
await db.select().from(tableName); //... | ||
} | ||
``` | ||
# Collaboration Service |
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
#!/bin/sh | ||
|
||
# To insert WS/RTC health checks | ||
|
||
npm run start |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.