Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
28 commits
Select commit Hold shift + click to select a range
20fc2f5
feat: Add ChatSidebar component
anunayajoshi Oct 25, 2024
08f2322
add floating button
anunayajoshi Oct 25, 2024
43c54c9
PEER-236: Set up chat service
cyiting Oct 25, 2024
fb34dda
PEER-236: Set up database
cyiting Oct 25, 2024
37bca25
PEER-236: Backend websocket code
cyiting Oct 25, 2024
33c4deb
PEER-236: Graceful termination
cyiting Oct 25, 2024
bf9154a
env stuff
anunayajoshi Oct 25, 2024
b507a3a
PEER-236: Add use-chat hook, vite config, nginx config
cyiting Oct 25, 2024
8d9797c
Merge remote-tracking branch 'origin/anun/ass' into PEER-236-Messagin…
cyiting Nov 1, 2024
9220e6c
PEER-236: Frontend chatting functionality
cyiting Nov 1, 2024
7c762b7
PEER-236: Navigate from match to interview
cyiting Nov 1, 2024
1abcd02
PEER-236: Refactor partner and ai chat code
cyiting Nov 1, 2024
a460759
PEER-236: UI Fixes
cyiting Nov 1, 2024
38ad86c
PEER-242: Add continue on failure for gha deploy
SeeuSim Nov 1, 2024
89a8a03
PEER-236: Docker compose, nginx configs
cyiting Nov 1, 2024
8f70509
Merge remote-tracking branch 'origin/main' into PEER-236-Messaging-UI
cyiting Nov 1, 2024
b992011
PEER-236: Update dockerfile
cyiting Nov 1, 2024
8504789
Merge branch 'main' into PEER-236-Messaging-UI
SeeuSim Nov 1, 2024
b9dff5d
PEER-236: Add chat dev server and graceful termination
SeeuSim Nov 1, 2024
5bf8b89
PEER-236: UI changes
cyiting Nov 1, 2024
80bd0f6
PEER-236: Update border
cyiting Nov 1, 2024
cfe5d33
Merge branch 'PEER-236-Messaging-UI' of https://github.com/CS3219-AY2…
cyiting Nov 1, 2024
16d1fa3
PEER-236: UI fixes
cyiting Nov 1, 2024
2f26bff
PEER-236: Add persistence for collab room updated at
SeeuSim Nov 1, 2024
5f1df58
PEER-236: Update deps
SeeuSim Nov 1, 2024
4a50ebb
PEER-236: Fix chat component styles
SeeuSim Nov 2, 2024
0b5ff2e
PEER-236: Add K8s configs
SeeuSim Nov 2, 2024
1493798
PEER-236: Update CI file
SeeuSim Nov 2, 2024
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
7 changes: 7 additions & 0 deletions .env.local
Original file line number Diff line number Diff line change
Expand Up @@ -20,5 +20,12 @@ MATCHING_DB_PASSWORD="password"
MATCHING_DB_HOST_PORT=6378
MATCHING_DB_HOST_MGMT_PORT=3001

CHAT_SERVICE_NAME=chat-express
CHAT_EXPRESS_PORT=9005
CHAT_EXPRESS_DB_PORT=5435
CHAT_PGDATA="/data/chat-db"

FRONTEND_SERVICE_NAME=frontend
FRONTEND_PORT=3000
OPENAI_API_KEY=PUT_YOUR_OPENAI_API_KEY_HERE

13 changes: 13 additions & 0 deletions .github/workflows/build-deploy-docker.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ env:
QUESTION_EXPRESS_PORT: 9002
COLLAB_EXPRESS_PORT: 9003
MATCH_EXPRESS_PORT: 9004
CHAT_EXPRESS_PORT: 9005
FRONTEND_PORT: 3000

jobs:
Expand Down Expand Up @@ -44,6 +45,8 @@ jobs:
- 'backend/collaboration/**'
matching:
- 'backend/matching/**'
chat:
- 'backend/chat/**'
frontend:
- 'frontend/**'
- name: output-job-matrix
Expand Down Expand Up @@ -91,6 +94,16 @@ jobs:
'{package: $pkg, image: $img, context: $ctx, dockerfile: $dkr, "build-args": $bag}')
matrix+=("$config")
fi
if [[ "${{ steps.filter.outputs.chat }}" == "true" || "$is_main" == "true" ]]; then
config=$(jq -n \
--arg pkg "chat" \
--arg img "$DOCKER_REGISTRY_USN/chat-express" \
--arg ctx "./backend/chat" \
--arg dkr "./backend/chat/express.Dockerfile" \
--arg bag "port=$CHAT_EXPRESS_PORT" \
'{package: $pkg, image: $img, context: $ctx, dockerfile: $dkr, "build-args": $bag}')
matrix+=("$config")
fi
if [[ "${{ steps.filter.outputs.frontend }}" == "true" || "$is_main" == "true" ]]; then
config=$(jq -n \
--arg pkg "frontend" \
Expand Down
2 changes: 2 additions & 0 deletions backend/chat/.dockerignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
node_modules
dist/
7 changes: 7 additions & 0 deletions backend/chat/.env.compose
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
EXPRESS_PORT=9005
EXPRESS_DB_HOST=chat-db
EXPRESS_DB_PORT=5435
POSTGRES_DB=chat
POSTGRES_USER=peerprep-chat-express
POSTGRES_PASSWORD=Xk8qEcEI2sizjfEn/lF6mLqiyBECjIHY3q6sdXf9poQ=
PGDATA="/data/chat-db"
9 changes: 9 additions & 0 deletions backend/chat/.env.docker
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
PEERPREP_UI_HOST=http://host.docker.internal:5173

EXPRESS_PORT=9005
EXPRESS_DB_HOST=host.docker.internal
EXPRESS_DB_PORT=5435
POSTGRES_DB=chat
POSTGRES_USER=peerprep-chat-express
POSTGRES_PASSWORD=Xk8qEcEI2sizjfEn/lF6mLqiyBECjIHY3q6sdXf9poQ=
PGDATA=/data/chat-db
9 changes: 9 additions & 0 deletions backend/chat/.env.local
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
PEERPREP_UI_HOST=http://localhost:5173

EXPRESS_PORT=9005
EXPRESS_DB_HOST=localhost
EXPRESS_DB_PORT=5435
POSTGRES_DB=chat
POSTGRES_USER=peerprep-chat-express
POSTGRES_PASSWORD=Xk8qEcEI2sizjfEn/lF6mLqiyBECjIHY3q6sdXf9poQ=
PGDATA=/data/chat-db
30 changes: 30 additions & 0 deletions backend/chat/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
# Matching Service

## Running with Docker (Standalone)

1. Run this command to build:
```sh
docker build \
-t chat-express-local \
--build-arg port=9005 \
-f express.Dockerfile .
```
2. Run this command, from the roxot folder:

```sh
make db-up
```

3. Run the necessary migrate and seed commands, if you haven't yet.

4. Run this command to expose the container:
```sh
docker run -p 9005:9005 --env-file ./.env.docker chat-express-local
```
5. To stop the process, use the Docker UI or CLI with `docker rm -f <container_id>` (The child process loop has issues terminating)

## Running with Docker-Compose (Main config)

Edit the variables in the `.env.compose` file and run `make up` from the root folder.

Any startup instructions will be run from `entrypoint.sh` instead.
16 changes: 16 additions & 0 deletions backend/chat/drizzle.config.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
import { defineConfig } from 'drizzle-kit';

const config = {
host: process.env.EXPRESS_DB_HOST!,
port: Number.parseInt(process.env.EXPRESS_DB_PORT!),
database: process.env.POSTGRES_DB!,
user: process.env.POSTGRES_USER,
password: process.env.POSTGRES_PASSWORD,
};

export default defineConfig({
schema: './src/lib/db/schema.ts',
out: './drizzle',
dialect: 'postgresql',
dbCredentials: config,
});
20 changes: 20 additions & 0 deletions backend/chat/drizzle/0000_initial_schema.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
DO $$
BEGIN
CREATE TYPE "public"."action" AS ENUM('SEED');
EXCEPTION
WHEN duplicate_object THEN null;
END $$;

CREATE TABLE IF NOT EXISTS "admin" (
"id" uuid PRIMARY KEY DEFAULT gen_random_uuid() NOT NULL,
"created_at" timestamp DEFAULT now(),
"action" "public"."action" NOT NULL
);

CREATE TABLE IF NOT EXISTS "chat_messages" (
"id" uuid PRIMARY KEY DEFAULT gen_random_uuid() NOT NULL,
"room_id" varchar(255) NOT NULL,
"sender_id" uuid NOT NULL,
"message" text NOT NULL,
"created_at" timestamp DEFAULT now()
);
97 changes: 97 additions & 0 deletions backend/chat/drizzle/meta/0000_snapshot.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,97 @@
{
"id": "fb253102-46c6-477c-a0e6-5dad3ea879eb",
"prevId": "00000000-0000-0000-0000-000000000000",
"version": "7",
"dialect": "postgresql",
"tables": {
"public.admin": {
"name": "admin",
"schema": "",
"columns": {
"id": {
"name": "id",
"type": "uuid",
"primaryKey": true,
"notNull": true,
"default": "gen_random_uuid()"
},
"created_at": {
"name": "created_at",
"type": "timestamp",
"primaryKey": false,
"notNull": false,
"default": "now()"
},
"action": {
"name": "action",
"type": "action",
"typeSchema": "public",
"primaryKey": false,
"notNull": true
}
},
"indexes": {},
"foreignKeys": {},
"compositePrimaryKeys": {},
"uniqueConstraints": {}
},
"public.chat_messages": {
"name": "chat_messages",
"schema": "",
"columns": {
"id": {
"name": "id",
"type": "uuid",
"primaryKey": true,
"notNull": true,
"default": "gen_random_uuid()"
},
"room_id": {
"name": "room_id",
"type": "varchar(255)",
"primaryKey": false,
"notNull": true
},
"sender_id": {
"name": "sender_id",
"type": "uuid",
"primaryKey": false,
"notNull": true
},
"message": {
"name": "message",
"type": "text",
"primaryKey": false,
"notNull": true
},
"created_at": {
"name": "created_at",
"type": "timestamp",
"primaryKey": false,
"notNull": false,
"default": "now()"
}
},
"indexes": {},
"foreignKeys": {},
"compositePrimaryKeys": {},
"uniqueConstraints": {}
}
},
"enums": {
"public.action": {
"name": "action",
"schema": "public",
"values": [
"SEED"
]
}
},
"schemas": {},
"sequences": {},
"_meta": {
"columns": {},
"schemas": {},
"tables": {}
}
}
13 changes: 13 additions & 0 deletions backend/chat/drizzle/meta/_journal.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
{
"version": "7",
"dialect": "postgresql",
"entries": [
{
"idx": 0,
"version": "7",
"when": 1729871791234,
"tag": "0000_initial_schema",
"breakpoints": true
}
]
}
13 changes: 13 additions & 0 deletions backend/chat/entrypoint.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
#!/bin/sh

# Drizzle will handle its own logic to remove conflicts
npm run db:prod:migrate

# Checks admin table and will not seed if data exists
npm run db:prod:seed

rm -rf drizzle src tsconfig.json

npm uninstall tsx drizzle-kit

npm run start
25 changes: 25 additions & 0 deletions backend/chat/express.Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
FROM node:lts-alpine AS build
WORKDIR /data/chat-express
COPY package*.json ./
RUN npm install
COPY . .
RUN npm run build

FROM node:lts-alpine AS production
WORKDIR /data/chat-express
COPY --from=build /data/chat-express/package*.json ./
COPY --from=build --chown=node:node /data/chat-express/dist ./dist

RUN npm ci --omit=dev

# For migration
RUN npm install tsx drizzle-kit
COPY drizzle ./drizzle
COPY src/lib/db/ ./src/lib/db
COPY src/config.ts ./src
COPY tsconfig.json .
COPY entrypoint.sh .

ARG port
EXPOSE ${port}
ENTRYPOINT [ "/bin/sh", "entrypoint.sh" ]
47 changes: 47 additions & 0 deletions backend/chat/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
{
"name": "chat",
"version": "1.0.0",
"main": "dist/index.js",
"scripts": {
"dev": "env-cmd -f .env.local nodemon src/index.ts | pino-pretty",
"build": "tsc && tsc-alias",
"start": "node dist/index.js",
"build:local": "env-cmd -f .env.local tsc && tsc-alias",
"start:local": "env-cmd -f .env.local node dist/index.js",
"db:generate": "env-cmd -f .env.local drizzle-kit generate",
"db:migrate": "env-cmd -f .env.local tsx ./src/lib/db/migrate.ts",
"db:prod:migrate": "tsx ./src/lib/db/migrate.ts",
"db:prod:seed": "tsx ./src/lib/db/seed.ts",
"db:seed": "env-cmd -f .env.local tsx src/lib/db/seed.ts",
"db:seed:prod": "tsx src/lib/db/seed.ts",
"fmt": "prettier --config .prettierrc src --write",
"test": "echo \"Error: no test specified\" && exit 1"
},
"keywords": [],
"author": "",
"license": "ISC",
"description": "",
"dependencies": {
"dotenv": "^16.4.5",
"drizzle-orm": "^0.33.0",
"express": "^4.21.0",
"http": "^0.0.1-security",
"http-status-codes": "^2.3.0",
"pino": "^9.4.0",
"pino-http": "^10.3.0",
"postgres": "^3.4.4",
"socket.io": "^4.8.1",
"tsc-alias": "^1.8.10",
"tsx": "^4.19.1"
},
"devDependencies": {
"@types/express": "^4.17.21",
"@types/node": "^22.5.5",
"drizzle-kit": "^0.24.2",
"nodemon": "^3.1.4",
"pino-pretty": "^11.2.2",
"ts-node": "^10.9.2",
"tsx": "^4.19.1",
"typescript": "^5.6.3"
}
}
13 changes: 13 additions & 0 deletions backend/chat/src/config.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
import 'dotenv/config';

export const UI_HOST = process.env.PEERPREP_UI_HOST!;

export const EXPRESS_PORT = process.env.EXPRESS_PORT;

export const dbConfig = {
host: process.env.EXPRESS_DB_HOST!,
port: Number.parseInt(process.env.EXPRESS_DB_PORT!),
database: process.env.POSTGRES_DB!,
user: process.env.POSTGRES_USER,
password: process.env.POSTGRES_PASSWORD,
};
Empty file.
Loading