Skip to content

Commit 8f70509

Browse files
committed
Merge remote-tracking branch 'origin/main' into PEER-236-Messaging-UI
2 parents 89a8a03 + 38ad86c commit 8f70509

File tree

88 files changed

+1780
-865
lines changed

Some content is hidden

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

88 files changed

+1780
-865
lines changed

.github/workflows/build-docker.yaml renamed to .github/workflows/build-deploy-docker.yaml

Lines changed: 54 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -105,7 +105,7 @@ jobs:
105105
echo "Outputs Generated: $formatted_matrix"
106106
echo "matrix=$formatted_matrix" >> $GITHUB_OUTPUT
107107
108-
build-and-push-image:
108+
build-push-deploy-image:
109109
needs: changes
110110
if: ${{ fromJson(needs.changes.outputs.matrix)[0] != null }}
111111
runs-on: ubuntu-latest
@@ -168,6 +168,10 @@ jobs:
168168
uses: docker/metadata-action@v5
169169
with:
170170
images: ${{ matrix.image }}
171+
tags: |
172+
type=ref,event=branch
173+
type=ref,event=pr
174+
type=raw,value=latest,enable={{is_default_branch}}
171175
172176
- name: Build and push Docker images for PeerPrep Services
173177
uses: docker/build-push-action@v6
@@ -182,14 +186,61 @@ jobs:
182186
cache-from: type=gha
183187
cache-to: type=gha,mode=max
184188

189+
- name: Auth GCloud
190+
id: gcloud-auth
191+
uses: google-github-actions/auth@v2
192+
if: ${{ contains(github.ref, 'main') && github.event.pull_request.title != 'Feedback' }}
193+
with:
194+
credentials_json: '${{ secrets.GKE_CJSON }}'
195+
continue-on-error: true
196+
197+
- name: Detect GKE Cluster
198+
id: gcloud-detect-gke
199+
if: ${{ contains(github.ref, 'main') && github.event.pull_request.title != 'Feedback' }}
200+
run: |-
201+
prev_step_success="${{ steps.gcloud-auth.outcome }}"
202+
if [[ "$prev_step_success" != "success" ]]; then
203+
echo "is_up=false" >> $GITHUB_OUTPUT
204+
exit 0
205+
fi
206+
207+
clusters="$(gcloud container clusters list)"
208+
is_up="$(echo $clusters | grep ${{ secrets.GKE_CLUSTER }})"
209+
if [[ -z "$is_up" ]]; then
210+
echo "is_up=false" >> $GITHUB_OUTPUT
211+
else
212+
echo "is_up=true" >> $GITHUB_OUTPUT
213+
fi
214+
215+
- name: Get GKE creds
216+
id: gcloud-get-gke-creds
217+
uses: google-github-actions/get-gke-credentials@v2
218+
if: ${{ contains(github.ref, 'main') && github.event.pull_request.title != 'Feedback' && steps.gcloud-detect-gke.outputs.is_up == 'true' }}
219+
with:
220+
cluster_name: ${{ secrets.GKE_CLUSTER }}
221+
location: ${{ secrets.GKE_ZONE }}
222+
223+
- name: Deploy to GKE
224+
id: gcloud-deploy-gke
225+
if: ${{ contains(github.ref, 'main') && github.event.pull_request.title != 'Feedback' && steps.gcloud-detect-gke.outputs.is_up == 'true' }}
226+
run: |-
227+
service="${{ matrix.package }}"
228+
deployment="frontend"
229+
if [[ "$service" == "collaboration" ]]; then
230+
deployment="collab-service"
231+
elif [[ "$service" != "frontend" ]]; then
232+
deployment="$service-service"
233+
fi
234+
kubectl -n peerprep rollout restart deployment "$deployment"
235+
185236
results:
186237
if: ${{ always() && !github.event.pull_request.draft }}
187238
runs-on: ubuntu-latest
188239
name: Final Results
189-
needs: build-and-push-image
240+
needs: build-push-deploy-image
190241
steps:
191242
- run: |
192-
result="${{ needs.build-and-push-image.result }}"
243+
result="${{ needs.build-push-deploy-image.result }}"
193244
if [[ $result == "success" || $result == "skipped" ]]; then
194245
exit 0
195246
else

Makefile

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,10 +11,18 @@ db-up:
1111

1212
db-down:
1313
docker compose --env-file .env.local -f docker-compose.local.yaml down
14+
echo 'y' | docker volume prune
1415

1516
up:
1617
./scripts/ensure-volume.sh
1718
docker compose --env-file .env.local up -d
1819

1920
down:
2021
docker compose --env-file .env.local down
22+
echo 'y' | docker volume prune
23+
24+
k8s-up:
25+
./scripts/k8s-up.sh
26+
27+
k8s-down:
28+
./scripts/k8s-down.sh

backend/collaboration/.env.compose

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33

44
EXPRESS_PORT=9003
55
EXPRESS_DB_HOST="collab-db"
6-
EXPRESS_DB_PORT=5435
6+
EXPRESS_DB_PORT=5432
77
POSTGRES_DB="collab"
88
POSTGRES_USER="peerprep-collab-express"
99
POSTGRES_PASSWORD="6rYE0nIzI2ThzDO"

backend/matching/.env.compose

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,4 +7,4 @@ EXPRESS_PORT=9004
77

88
MATCHING_DB_USERNAME="peerprep-match-express"
99
MATCHING_DB_PASSWORD="G7jBgyz9wGAFQ5La"
10-
REDIS_ARGS="--requirepass G7jBgyz9wGAFQ5La --user ${MATCHING_DB_USERNAME} on >G7jBgyz9wGAFQ5La ~* allcommands --user default off nopass nocommands"
10+
REDIS_ARGS="--requirepass G7jBgyz9wGAFQ5La --user peerprep-match-express on >G7jBgyz9wGAFQ5La ~* allcommands --user default off nopass nocommands"

backend/matching/src/lib/db/client.ts

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,9 +13,14 @@ class RedisClient {
1313
host: DB_HOSTNAME,
1414
port: DB_PORT,
1515
},
16-
}).on('error', (err) => {
17-
logger.error(`Redis Client error: ${err}`);
18-
});
16+
})
17+
.on('error', (err) => {
18+
const { name, message, stack, cause } = err as Error;
19+
logger.error({ name, message, stack, cause }, 'Redis Client error');
20+
})
21+
.on('connect', () => {
22+
logger.info('Redis Client connected');
23+
});
1924
}
2025
}
2126

backend/matching/src/lib/db/seed.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,6 @@ const main = async () => {
2424
return;
2525
}
2626

27-
logger.info('Connected');
2827
const isSeeded = await redisClient.hGetAll(SEED_KEY);
2928

3029
if (Object.keys(isSeeded).length > 0) {

backend/matching/src/workers/matcher.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -133,7 +133,7 @@ async function match() {
133133
sendNotif([requestorSocketPort], MATCHING_EVENT.MATCHING);
134134
await redisClient.hSet(getPoolKey(requestorUserId), 'pending', 'false');
135135

136-
const clause = [`-@userId:(${requestorUserId}) @pending:(true)`];
136+
let clause = [`-@userId:(${requestorUserId})`, '@pending:(true)'];
137137

138138
if (difficulty) {
139139
clause.push(`@difficulty:{${difficulty}}`);
@@ -143,6 +143,9 @@ async function match() {
143143
clause.push(`@topic:{${topic}}`);
144144
}
145145

146+
// Push UserID clause to the back.
147+
clause = clause.reverse();
148+
146149
const searchParams = {
147150
LIMIT: { from: 0, size: 1 },
148151
SORTBY: { BY: 'timestamp', DIRECTION: 'ASC' },

backend/question/.env.compose

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

44
EXPRESS_PORT=9002
5-
EXPRESS_DB_HOST="qn-db"
6-
EXPRESS_DB_PORT=5433
5+
EXPRESS_DB_HOST="question-db"
6+
EXPRESS_DB_PORT=5432
77
POSTGRES_DB="question"
88
POSTGRES_USER="peerprep-qn-express"
99
POSTGRES_PASSWORD="Xk8qEcEI2sizjfEn/lF6mLqiyBECjIHY3q6sdXf9poQ="

backend/question/src/config.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,3 +11,5 @@ export const dbConfig = {
1111
user: process.env.POSTGRES_USER,
1212
password: process.env.POSTGRES_PASSWORD,
1313
};
14+
15+
export const LOAD_TEST_POD = process.env.LOAD_TEST_POD || 'http://question-service-load-test';

backend/question/src/server.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ import helmet from 'helmet';
77
import { StatusCodes } from 'http-status-codes';
88
import pino from 'pino-http';
99

10-
import { UI_HOST } from '@/config';
10+
import { LOAD_TEST_POD, UI_HOST } from '@/config';
1111
import { config, db } from '@/lib/db';
1212
import { logger } from '@/lib/utils';
1313
import questionsRouter from '@/routes/question';
@@ -32,7 +32,7 @@ app.use(json());
3232
app.use(helmet());
3333
app.use(
3434
cors({
35-
origin: [UI_HOST],
35+
origin: [UI_HOST, LOAD_TEST_POD],
3636
credentials: true,
3737
})
3838
);

0 commit comments

Comments
 (0)