Skip to content

Commit b775ab2

Browse files
committed
Merge branch 'main' of github.com:CS3219-AY2425S1/cs3219-ay2425s1-project-g16 into PEER-234-Editor-UI
Signed-off-by: SeeuSim <[email protected]>
2 parents db10cb7 + 3fcfda8 commit b775ab2

File tree

160 files changed

+9154
-9631
lines changed

Some content is hidden

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

160 files changed

+9154
-9631
lines changed

.env.local

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,12 +10,14 @@ QUESTION_PGDATA="/data/qn-db"
1010

1111
COLLAB_SERVICE_NAME=collab-express
1212
COLLAB_EXPRESS_PORT=9003
13+
COLLAB_EXPRESS_DB_PORT=5435
14+
COLLAB_PGDATA="/data/collab-db"
1315

1416
MATCHING_SERVICE_NAME=match-express
1517
MATCHING_EXPRESS_PORT=9004
1618
MATCHING_DB_USERNAME="peerprep-match-express"
1719
MATCHING_DB_PASSWORD="password"
18-
MATCHING_DB_HOST_PORT=6379
20+
MATCHING_DB_HOST_PORT=6378
1921
MATCHING_DB_HOST_MGMT_PORT=3001
2022

2123
FRONTEND_SERVICE_NAME=frontend

.eslintrc.json

Lines changed: 39 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,9 +11,16 @@
1111
"ecmaVersion": "latest",
1212
"sourceType": "module"
1313
},
14-
"plugins": ["import", "unused-imports", "react", "@typescript-eslint", "tailwindcss"],
14+
"plugins": [
15+
"import",
16+
"unused-imports",
17+
"react",
18+
"@typescript-eslint",
19+
"tailwindcss",
20+
"react-hooks",
21+
"simple-import-sort"
22+
],
1523
"rules": {
16-
// "@next/next/no-img-element": "off",
1724
"@typescript-eslint/no-explicit-any": "warn",
1825
"@typescript-eslint/explicit-module-boundary-types": "off",
1926
"@typescript-eslint/explicit-function-return-type": 0,
@@ -29,11 +36,21 @@
2936
"@typescript-eslint/no-empty-interface": "off",
3037
"@typescript-eslint/no-unused-vars": 0,
3138
"@typescript-eslint/no-use-before-define": 0,
39+
3240
// Basic
3341
"array-callback-return": "warn",
3442
"no-console": "warn",
43+
"no-multiple-empty-lines": ["error", { "max":1 }],
3544
"no-prototype-builtins": 0,
36-
// "no-expected-multiline": "warn", // can't find rule definition
45+
// "no-expected-multiline": "warn", // can"t find rule definition
46+
47+
"padding-line-between-statements": [
48+
"warn",
49+
{ "blankLine": "always", "prev": "*", "next": "block" },
50+
{ "blankLine": "always", "prev": "block", "next": "*" },
51+
{ "blankLine": "always", "prev": "*", "next": "block-like" },
52+
{ "blankLine": "always", "prev": "block-like", "next": "*" }
53+
],
3754

3855
// React
3956
"react/display-name": 0,
@@ -47,6 +64,8 @@
4764
}
4865
],
4966
"react-hooks/rules-of-hooks": "off",
67+
"simple-import-sort/imports": "error",
68+
"simple-import-sort/exports": "error",
5069
"tailwindcss/enforces-negative-arbitrary-values": "off",
5170
"unused-imports/no-unused-imports": "error",
5271
"unused-imports/no-unused-vars": [
@@ -66,6 +85,22 @@
6685
"rules": {
6786
"react/prop-types": "off"
6887
}
88+
},
89+
{
90+
"files": ["*.js", "*.ts", "*.tsx"],
91+
"rules": {
92+
"simple-import-sort/imports": [
93+
"error",
94+
{
95+
"groups": [
96+
["^(?:os|path|http|fs|crypto|util|events|stream|url|zlib|querystring|tls|dgram|net|dns|child_process|cluster|readline|vm|assert|buffer|process|timers)(\/.*)?$"],
97+
["^(?!(@\/|\\.\\.\/|\\.\/))"],
98+
["^@\/"],
99+
["^(?:\\.\/|\\.\\.\/|\\.)"]
100+
]
101+
}
102+
]
103+
}
69104
}
70105
]
71-
}
106+
}
Lines changed: 197 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,197 @@
1+
name: Build & publish PeerPrep images
2+
on:
3+
pull_request:
4+
types:
5+
- opened
6+
- reopened
7+
- synchronize
8+
- ready_for_review
9+
push:
10+
branches:
11+
- main
12+
13+
env:
14+
DOCKER_REGISTRY_USN: ay2425s1cs3219g16
15+
USER_EXPRESS_PORT: 9001
16+
QUESTION_EXPRESS_PORT: 9002
17+
COLLAB_EXPRESS_PORT: 9003
18+
MATCH_EXPRESS_PORT: 9004
19+
FRONTEND_PORT: 3000
20+
21+
jobs:
22+
changes:
23+
if: ${{ !github.event.pull_request.draft && github.event.pull_request.title != 'Feedback' }}
24+
runs-on: ubuntu-latest
25+
# Required permissions
26+
permissions:
27+
pull-requests: read
28+
# Set job outputs to values from filter step
29+
outputs:
30+
matrix: ${{ steps.set-matrix.outputs.matrix }} # Output the matrix as a JSON string
31+
steps:
32+
- uses: actions/checkout@v4
33+
if: contains(github.ref, 'main')
34+
# For pull requests it's not necessary to checkout the code
35+
- uses: dorny/paths-filter@v3
36+
id: filter
37+
with:
38+
filters: |
39+
user:
40+
- 'backend/user/**'
41+
question:
42+
- 'backend/question/**'
43+
collaboration:
44+
- 'backend/collaboration/**'
45+
matching:
46+
- 'backend/matching/**'
47+
frontend:
48+
- 'frontend/**'
49+
- name: output-job-matrix
50+
id: set-matrix
51+
run: |
52+
is_main=${{ contains(github.ref, 'main') }}
53+
matrix=()
54+
if [[ "${{ steps.filter.outputs.user }}" == "true" || "$is_main" == "true" ]]; then
55+
config=$(jq -n \
56+
--arg pkg "user" \
57+
--arg img "$DOCKER_REGISTRY_USN/user-express" \
58+
--arg ctx "./backend/user" \
59+
--arg dkr "./backend/user/express.Dockerfile" \
60+
--arg bag "port=$USER_EXPRESS_PORT" \
61+
'{package: $pkg, image: $img, context: $ctx, dockerfile: $dkr, "build-args": $bag}')
62+
matrix+=("$config")
63+
fi
64+
if [[ "${{ steps.filter.outputs.question }}" == "true" || "$is_main" == "true" ]]; then
65+
config=$(jq -n \
66+
--arg pkg "question" \
67+
--arg img "$DOCKER_REGISTRY_USN/question-express" \
68+
--arg ctx "./backend/question" \
69+
--arg dkr "./backend/question/express.Dockerfile" \
70+
--arg bag "port=$QUESTION_EXPRESS_PORT" \
71+
'{package: $pkg, image: $img, context: $ctx, dockerfile: $dkr, "build-args": $bag}')
72+
matrix+=("$config")
73+
fi
74+
if [[ "${{ steps.filter.outputs.collaboration }}" == "true" || "$is_main" == "true" ]]; then
75+
config=$(jq -n \
76+
--arg pkg "collaboration" \
77+
--arg img "$DOCKER_REGISTRY_USN/collab-express" \
78+
--arg ctx "./backend/collaboration" \
79+
--arg dkr "./backend/collaboration/express.Dockerfile" \
80+
--arg bag "port=$COLLAB_EXPRESS_PORT" \
81+
'{package: $pkg, image: $img, context: $ctx, dockerfile: $dkr, "build-args": $bag}')
82+
matrix+=("$config")
83+
fi
84+
if [[ "${{ steps.filter.outputs.matching }}" == "true" || "$is_main" == "true" ]]; then
85+
config=$(jq -n \
86+
--arg pkg "matching" \
87+
--arg img "$DOCKER_REGISTRY_USN/match-express" \
88+
--arg ctx "./backend/matching" \
89+
--arg dkr "./backend/matching/express.Dockerfile" \
90+
--arg bag "port=$MATCH_EXPRESS_PORT" \
91+
'{package: $pkg, image: $img, context: $ctx, dockerfile: $dkr, "build-args": $bag}')
92+
matrix+=("$config")
93+
fi
94+
if [[ "${{ steps.filter.outputs.frontend }}" == "true" || "$is_main" == "true" ]]; then
95+
config=$(jq -n \
96+
--arg pkg "frontend" \
97+
--arg img "$DOCKER_REGISTRY_USN/frontend" \
98+
--arg ctx "./frontend" \
99+
--arg dkr "./frontend/frontend.Dockerfile" \
100+
--arg bag "port=$FRONTEND_PORT" \
101+
'{package: $pkg, image: $img, context: $ctx, dockerfile: $dkr, "build-args": $bag}')
102+
matrix+=("$config")
103+
fi
104+
formatted_matrix=$(echo "${matrix[@]}" | jq -cs .)
105+
echo "Outputs Generated: $formatted_matrix"
106+
echo "matrix=$formatted_matrix" >> $GITHUB_OUTPUT
107+
108+
build-and-push-image:
109+
needs: changes
110+
if: ${{ fromJson(needs.changes.outputs.matrix)[0] != null }}
111+
runs-on: ubuntu-latest
112+
strategy:
113+
fail-fast: false
114+
matrix:
115+
include: ${{ fromJson(needs.changes.outputs.matrix) }} # Use the matrix from the first job
116+
# - package: user
117+
# image: ay2425s1cs3219g16/user-express
118+
# context: ./backend/user
119+
# dockerfile: ./backend/user/express.Dockerfile
120+
# build-args: |
121+
# port=9001
122+
# - package: question
123+
# image: ay2425s1cs3219g16/question-express
124+
# context: ./backend/question
125+
# dockerfile: ./backend/question/express.Dockerfile
126+
# build-args: |
127+
# port=9002
128+
# - package: collaboration
129+
# image: ay2425s1cs3219g16/collab-express
130+
# context: ./backend/collaboration
131+
# dockerfile: ./backend/collaboration/express.Dockerfile
132+
# build-args: |
133+
# port=9003
134+
# - package: matching
135+
# image: ay2425s1cs3219g16/match-express
136+
# context: ./backend/matching
137+
# dockerfile: ./backend/matching/express.Dockerfile
138+
# build-args: |
139+
# port=9004
140+
# - package: frontend
141+
# image: ay2425s1cs3219g16/frontend
142+
# context: ./frontend
143+
# dockerfile: ./frontend/frontend.Dockerfile
144+
# build-args: |
145+
# port=3000
146+
permissions:
147+
contents: read
148+
packages: write
149+
150+
steps:
151+
- name: Checkout repository
152+
uses: actions/checkout@v4
153+
154+
- name: Set up QEMU
155+
uses: docker/setup-qemu-action@v3
156+
157+
- name: Set up Docker Buildx
158+
uses: docker/setup-buildx-action@v3
159+
160+
- name: Log in to the Container registry
161+
uses: docker/login-action@v3
162+
with:
163+
username: ${{ secrets.DOCKER_USERNAME }}
164+
password: ${{ secrets.DOCKER_PASSWORD }}
165+
166+
- name: Extract metadata (tags, labels) for Docker
167+
id: meta
168+
uses: docker/metadata-action@v5
169+
with:
170+
images: ${{ matrix.image }}
171+
172+
- name: Build and push Docker images for PeerPrep Services
173+
uses: docker/build-push-action@v6
174+
with:
175+
platforms: linux/amd64,linux/arm64
176+
context: ${{ matrix.context }}
177+
file: ${{ matrix.dockerfile }}
178+
build-args: ${{ matrix.build-args }}
179+
push: true
180+
tags: ${{ steps.meta.outputs.tags }}
181+
labels: ${{ steps.meta.outputs.labels }}
182+
cache-from: type=gha
183+
cache-to: type=gha,mode=max
184+
185+
results:
186+
if: ${{ always() }}
187+
runs-on: ubuntu-latest
188+
name: Final Results
189+
needs: build-and-push-image
190+
steps:
191+
- run: |
192+
result="${{ needs.build-and-push-image.result }}"
193+
if [[ $result == "success" || $result == "skipped" ]]; then
194+
exit 0
195+
else
196+
exit 1
197+
fi

.github/workflows/clear-cache.yaml

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
name: Cleanup caches after merge
2+
on:
3+
pull_request:
4+
types:
5+
- closed
6+
workflow_dispatch:
7+
8+
jobs:
9+
cleanup:
10+
runs-on: ubuntu-latest
11+
permissions:
12+
# `actions:write` permission is required to delete caches
13+
# See also: https://docs.github.com/en/rest/actions/cache?apiVersion=2022-11-28#delete-a-github-actions-cache-for-a-repository-using-a-cache-id
14+
actions: write
15+
contents: read
16+
17+
steps:
18+
- name: Check out code
19+
uses: actions/checkout@v4
20+
21+
- name: Cleanup cache
22+
run: |
23+
gh extension install actions/gh-actions-cache
24+
25+
REPO=${{ github.repository }}
26+
BRANCH=refs/pull/${{ github.event.pull_request.number }}/merge
27+
28+
echo "Fetching list of cache key"
29+
cacheKeysForPR=$(gh actions-cache list -R $REPO -B $BRANCH --limit 100 --sort size | cut -f 1 )
30+
31+
## Setting this to not fail the workflow while deleting cache keys.
32+
set +e
33+
echo "Deleting caches..."
34+
for cacheKey in $cacheKeysForPR
35+
do
36+
gh actions-cache delete $cacheKey -R $REPO -B $BRANCH --confirm
37+
done
38+
echo "Done"
39+
env:
40+
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}

backend/collaboration/.env.compose

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,3 +2,9 @@
22
# PEERPREP_UI_HOST="http://frontend:3000"
33

44
EXPRESS_PORT=9003
5+
EXPRESS_DB_HOST="collab-db"
6+
EXPRESS_DB_PORT=5435
7+
POSTGRES_DB="collab"
8+
POSTGRES_USER="peerprep-collab-express"
9+
POSTGRES_PASSWORD="6rYE0nIzI2ThzDO"
10+
PGDATA="/data/collab-db"

backend/collaboration/.env.docker

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,9 @@
1-
PEERPREP_UI_HOST="http://host.docker.internal:5173"
1+
PEERPREP_UI_HOST=http://host.docker.internal:5173
22

33
EXPRESS_PORT=9003
4+
EXPRESS_DB_HOST=host.docker.internal
5+
EXPRESS_DB_PORT=5435
6+
POSTGRES_DB=collab
7+
POSTGRES_USER=peerprep-collab-express
8+
POSTGRES_PASSWORD=6rYE0nIzI2ThzDO
9+
PGDATA=/data/collab-db

backend/collaboration/.env.local

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,9 @@
11
PEERPREP_UI_HOST="http://localhost:5173"
22

33
EXPRESS_PORT=9003
4+
EXPRESS_DB_HOST="localhost"
5+
EXPRESS_DB_PORT=5435
6+
POSTGRES_DB="collab"
7+
POSTGRES_USER="peerprep-collab-express"
8+
POSTGRES_PASSWORD="6rYE0nIzI2ThzDO"
9+
PGDATA="/data/collab-db"
Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,2 @@
11
#!/bin/sh
2-
3-
# To insert WS/RTC health checks
4-
5-
npm run start
2+
npm run start

backend/collaboration/express.Dockerfile

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ FROM node:lts-alpine AS build
22
WORKDIR /data/collab-express
33
COPY package*.json ./
44
RUN npm install
5+
ARG env
56
COPY . .
67
RUN npm run build
78

@@ -12,6 +13,8 @@ COPY --from=build --chown=node:node /data/collab-express/dist ./dist
1213

1314
RUN npm ci --omit=dev
1415

16+
RUN sed -i 's|./ws|ws|g' ./dist/ws.js
17+
1518
COPY entrypoint.sh .
1619

1720
ARG port

0 commit comments

Comments
 (0)