Skip to content

Commit 250c446

Browse files
authored
Merge pull request #33 from CS3219-AY2425S1/PEER-255-Dockerize-DBs
PEER-255 Add docker-compose config for user-db and user-service
2 parents 7431eab + 133c64b commit 250c446

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

45 files changed

+587
-291
lines changed

.env.local

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,3 +6,18 @@ QUESTION_EXPRESS_DB_PORT=5433
66

77
COLLAB_PGDATA="/data/collab-db"
88
COLLAB_EXPRESS_DB_PORT=5434
9+
10+
MATCHING_PGDATA="/data/collab-db"
11+
MATCHING_EXPRESS_DB_PORT=5434
12+
13+
USER_EXPRESS_ENV=compose
14+
USER_EXPRESS_PORT=9001
15+
16+
QUESTION_EXPRESS_ENV=compose
17+
QUESTION_EXPRESS_PORT=9002
18+
19+
COLLAB_EXPRESS_ENV=compose
20+
COLLAB_EXPRESS_PORT=9003
21+
22+
MATCHING_EXPRESS_ENV=compose
23+
MATCHING_EXPRESS_PORT=9003

Makefile

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,14 @@ migrate-seed:
77

88
db-up:
99
./scripts/ensure-volume.sh
10-
docker compose --env-file .env.local up -d
10+
docker compose --env-file .env.local -f docker-compose.local.yaml up -d
1111

1212
db-down:
13-
docker compose --env-file .env.local down
13+
docker compose --env-file .env.local -f docker-compose.local.yaml down
14+
15+
up:
16+
./scripts/ensure-volume.sh
17+
docker compose --env-file .env.local up -d
1418

19+
down:
20+
docker compose --env-file .env.local down

backend/collaboration/.env.local

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
EXPRESS_ENV="local"
22
EXPRESS_DB_HOST="localhost"
33
EXPRESS_DB_PORT=5434
4-
POSTGRES_DB="collaboration"
4+
POSTGRES_DB="collab"
55
POSTGRES_USER="peerprep-collab-express"
66
POSTGRES_PASSWORD="/86awM+Izo6949YgEQIls8HU+j5RlFYEInRy8auiNa8="
77
PGDATA="/data/collab-db"

backend/collaboration/package.json

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
"build:prod": "env-cmd -f .env.prod tsc && tsc-alias",
1010
"start:prod": "env-cmd -f .env.local node dist/index.js",
1111
"db:generate": "env-cmd -f .env.local drizzle-kit generate",
12-
"db:migrate": "env-cmd -f .env.local tsx drizzle.migrate.ts",
12+
"db:migrate": "env-cmd -f .env.local tsx ./src/lib/db/migrate.ts",
1313
"db:inspect": "env-cmd -f .env.local drizzle-kit studio",
1414
"fmt": "prettier --config .prettierrc src --write",
1515
"test": "echo \"Error: no test specified\" && exit 1"
@@ -19,14 +19,17 @@
1919
"license": "ISC",
2020
"description": "",
2121
"dependencies": {
22+
"cors": "^2.8.5",
2223
"drizzle-orm": "^0.33.0",
2324
"env-cmd": "^10.1.0",
2425
"express": "^4.21.0",
26+
"http-status-codes": "^2.3.0",
2527
"pino": "^9.4.0",
2628
"pino-http": "^10.3.0",
2729
"postgres": "^3.4.4"
2830
},
2931
"devDependencies": {
32+
"@types/cors": "^2.8.17",
3033
"@types/express": "^4.17.21",
3134
"@types/node": "^22.5.5",
3235
"drizzle-kit": "^0.24.2",
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
import 'dotenv/config';
2+
3+
export const JWT_SECRET_KEY = process.env.EXPRESS_JWT_SECRET_KEY!;
4+
5+
export const UI_HOST = process.env.PEERPREP_UI_HOST!;
6+
7+
export const EXPRESS_PORT = process.env.EXPRESS_PORT;
8+
9+
export const dbConfig = {
10+
host: process.env.EXPRESS_DB_HOST!,
11+
port: Number.parseInt(process.env.EXPRESS_DB_PORT!),
12+
database: process.env.POSTGRES_DB!,
13+
user: process.env.POSTGRES_USER,
14+
password: process.env.POSTGRES_PASSWORD,
15+
};

backend/collaboration/src/index.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
1+
import { EXPRESS_PORT } from '@/config';
12
import { logger } from '@/lib/utils';
23
import app, { dbHealthCheck } from '@/server';
34

4-
const port = process.env.PORT || 8001;
5+
const port = Number.parseInt(EXPRESS_PORT || '8001');
56

67
const listenMessage = `App listening on port: ${port}`;
78
app.listen(port, () => {
File renamed without changes.

backend/collaboration/src/server.ts

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,27 @@
11
import { exit } from 'process';
22

3+
import cors from 'cors';
4+
import { sql } from 'drizzle-orm';
35
import express, { json } from 'express';
6+
import { StatusCodes } from 'http-status-codes';
47
import pino from 'pino-http';
5-
import { sql } from 'drizzle-orm';
68

79
import { config, db } from '@/lib/db';
810
import { logger } from '@/lib/utils';
11+
import { UI_HOST } from './config';
912

1013
const app = express();
1114
app.use(pino());
1215
app.use(json());
16+
app.use(
17+
cors({
18+
origin: [UI_HOST],
19+
credentials: true,
20+
})
21+
);
1322

14-
app.get('/', async (_req, res) => {
15-
res.json({
16-
message: 'OK',
17-
});
18-
});
23+
// Health Check for Docker
24+
app.get('/health', (_req, res) => res.status(StatusCodes.OK).send('OK'));
1925

2026
export const dbHealthCheck = async () => {
2127
try {

backend/question/drizzle/0000_initial_schema.sql

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,15 @@
1+
DO $$ BEGIN
2+
CREATE TYPE "public"."action" AS ENUM('SEED');
3+
EXCEPTION
4+
WHEN duplicate_object THEN null;
5+
END $$;
6+
--> statement-breakpoint
7+
CREATE TABLE IF NOT EXISTS "admin" (
8+
"id" uuid PRIMARY KEY DEFAULT gen_random_uuid() NOT NULL,
9+
"created_at" timestamp DEFAULT now(),
10+
"action" "action" NOT NULL
11+
);
12+
--> statement-breakpoint
113
CREATE TABLE IF NOT EXISTS "questions" (
214
"id" serial PRIMARY KEY NOT NULL,
315
"title" varchar(255) NOT NULL,

backend/question/drizzle/meta/0000_snapshot.json

Lines changed: 41 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,40 @@
11
{
2-
"id": "537c03f5-13dd-427a-ae0d-cfd203da09ed",
2+
"id": "84b2ca8d-3021-496f-8769-bbc4dada6468",
33
"prevId": "00000000-0000-0000-0000-000000000000",
44
"version": "7",
55
"dialect": "postgresql",
66
"tables": {
7+
"public.admin": {
8+
"name": "admin",
9+
"schema": "",
10+
"columns": {
11+
"id": {
12+
"name": "id",
13+
"type": "uuid",
14+
"primaryKey": true,
15+
"notNull": true,
16+
"default": "gen_random_uuid()"
17+
},
18+
"created_at": {
19+
"name": "created_at",
20+
"type": "timestamp",
21+
"primaryKey": false,
22+
"notNull": false,
23+
"default": "now()"
24+
},
25+
"action": {
26+
"name": "action",
27+
"type": "action",
28+
"typeSchema": "public",
29+
"primaryKey": false,
30+
"notNull": true
31+
}
32+
},
33+
"indexes": {},
34+
"foreignKeys": {},
35+
"compositePrimaryKeys": {},
36+
"uniqueConstraints": {}
37+
},
738
"public.questions": {
839
"name": "questions",
940
"schema": "",
@@ -59,7 +90,15 @@
5990
"uniqueConstraints": {}
6091
}
6192
},
62-
"enums": {},
93+
"enums": {
94+
"public.action": {
95+
"name": "action",
96+
"schema": "public",
97+
"values": [
98+
"SEED"
99+
]
100+
}
101+
},
63102
"schemas": {},
64103
"sequences": {},
65104
"_meta": {

0 commit comments

Comments
 (0)