Skip to content

Commit 9132a02

Browse files
committed
Merge branch 'master' into api-gateway
2 parents 79a2575 + b2ffaef commit 9132a02

File tree

10 files changed

+152
-28
lines changed

10 files changed

+152
-28
lines changed

.github/workflows/build_push_registry.yml

Lines changed: 54 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ jobs:
1313
build-push-artifact:
1414
runs-on: ubuntu-latest
1515
outputs:
16-
build_status: ${{ steps.set_output.outputs.build_status }}
16+
should_deploy: ${{ steps.deploy.outputs.BUILD_STEP_RAN }}
1717
steps:
1818
- name: "Checkout"
1919
uses: "actions/checkout@v3"
@@ -33,6 +33,9 @@ jobs:
3333
- 'matching_service/**'
3434
collab_service:
3535
- 'collab_service/**'
36+
code_execution:
37+
- 'code_execution/**'
38+
3639
3740
- name: 'Create env file'
3841
run: |
@@ -54,41 +57,82 @@ jobs:
5457
run: |-
5558
gcloud auth configure-docker ${{ env.REGION }}-docker.pkg.dev --quiet
5659
57-
- name: Determine Build Status
58-
id: set_output
59-
run: echo "::set-output name=build_status::false"
60-
6160
- name: 1. Build and Push frontend
61+
id: a
6262
if: steps.changes.outputs.frontend == 'true'
6363
run: |
6464
docker-compose build frontend
6565
docker-compose push frontend
66-
echo "::set-output name=build_status::true"
6766
6867
- name: 2. Build and Push question-service
68+
id: b
6969
if: steps.changes.outputs.question_service == 'true'
7070
run: |
7171
docker-compose build question-service
7272
docker-compose push question-service
73-
echo "::set-output name=build_status::true"
7473
7574
- name: 3. Build and Push user-service
75+
id: c
7676
if: steps.changes.outputs.user_service == 'true'
7777
run: |
7878
docker-compose build user-service
7979
docker-compose push user-service
80-
echo "::set-output name=build_status::true"
8180
8281
- name: 4. Build and Push matching-service
82+
id: d
8383
if: steps.changes.outputs.matching_service == 'true'
8484
run: |
8585
docker-compose build matching-service
8686
docker-compose push matching-service
87-
echo "::set-output name=build_status::true"
8887
8988
- name: 5. Build and Push collab-service
89+
id: e
9090
if: steps.changes.outputs.collab_service == 'true'
9191
run: |
9292
docker-compose build collab-service
9393
docker-compose push collab-service
94-
echo "::set-output name=build_status::true"
94+
95+
- name: 6. Build and Push code-execution
96+
id: f
97+
if: steps.changes.outputs.code_execution == 'true'
98+
run: |
99+
docker-compose build code-execution
100+
docker-compose push code-execution
101+
102+
- name: determine deploy step
103+
id: deploy
104+
if: ${{ steps.a.conclusion == 'success' || steps.b.conclusion == 'success' || steps.c.conclusion == 'success' || steps.d.conclusion == 'success' || steps.e.conclusion == 'success' || steps.f.conclusion == 'success' }}
105+
run: |
106+
echo "BUILD_STEP_RAN=true" >> $GITHUB_OUTPUT
107+
108+
109+
deploy:
110+
needs: build-push-artifact
111+
if: ${{needs.build-push-artifact.outputs.should_deploy== 'true'}}
112+
runs-on: ubuntu-latest
113+
steps:
114+
- name: Checkout code
115+
uses: actions/checkout@v2
116+
117+
- name: "Set up google auth"
118+
id: auth
119+
uses: "google-github-actions/auth@v1"
120+
with:
121+
credentials_json: "${{ secrets.SERVICE_ACCOUNT_KEY }}"
122+
123+
- name: "Use gcloud CLI"
124+
run: "gcloud info"
125+
126+
- name: "SSH to VM"
127+
id: 'compute-ssh'
128+
uses: 'google-github-actions/ssh-compute@v0'
129+
with:
130+
instance_name: 'peerprep-prod'
131+
zone: 'asia-southeast1-b'
132+
ssh_private_key: '${{ secrets.SSH_KEY }}'
133+
command: 'echo "${{ secrets.ENV_FILE }}" | sudo tee /usr/src/peerprep/.env > /dev/null && sudo chmod 777 /usr/src/peerprep/scripts/init.sh && sudo /usr/src/peerprep/scripts/init.sh'
134+
135+
- id: 'test'
136+
run: |-
137+
echo '${{ steps.compute-ssh.outputs.stdout }}'
138+
echo '${{ steps.compute-ssh.outputs.stderr }}'

.github/workflows/deployment.yml

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,16 +3,13 @@ name: Deployment Workflow
33
on:
44
workflow_dispatch:
55
workflow_run:
6-
workflows: ["Selectively Build and Push to Artifact Registry", "Build and Push to Artifact Registry"]
6+
workflows: ["Build and Push to Artifact Registry"]
77
types:
88
- completed
99

1010
jobs:
1111
deploy:
1212
runs-on: ubuntu-latest
13-
if: >
14-
github.event_name == 'workflow_dispatch' ||
15-
(github.event_name == 'workflow_run' && github.event.workflow_run.conclusion == 'success' && github.event.workflow_run.outputs.build_status == 'true')
1613
steps:
1714
- name: Checkout code
1815
uses: actions/checkout@v2

code_execution/Dockerfile.prod

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
# Stage 1: Build the application
2+
FROM node:18-alpine AS builder
3+
4+
WORKDIR /app
5+
COPY package*.json ./
6+
RUN npm ci
7+
COPY . .
8+
RUN npm run build
9+
10+
# Stage 2: Setup the production environment
11+
FROM node:18-alpine
12+
WORKDIR /usr/src/app
13+
COPY package*.json ./
14+
RUN npm ci --only=production
15+
COPY --from=builder /app/dist ./dist
16+
17+
# Command to run the application
18+
CMD ["npm", "run", "serve"]

code_execution/package.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,8 @@
66
"scripts": {
77
"test": "echo \"Error: no test specified\" && exit 1",
88
"start": "ts-node src/index.ts",
9-
"build": "tsc --init"
9+
"build": "tsc",
10+
"serve": "node dist/index.js"
1011
},
1112
"keywords": [],
1213
"author": "",

code_execution/tsconfig.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@
5555
// "sourceMap": true, /* Create source map files for emitted JavaScript files. */
5656
// "inlineSourceMap": true, /* Include sourcemap files inside the emitted JavaScript. */
5757
// "outFile": "./", /* Specify a file that bundles all outputs into one JavaScript file. If 'declaration' is true, also designates a file that bundles all .d.ts output. */
58-
// "outDir": "./", /* Specify an output folder for all emitted files. */
58+
"outDir": "./dist", /* Specify an output folder for all emitted files. */
5959
// "removeComments": true, /* Disable emitting comments. */
6060
// "noEmit": true, /* Disable emitting files from a compilation. */
6161
// "importHelpers": true, /* Allow importing helper functions from tslib once per project, instead of including them per-file. */

collab_service/.dockerignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
node_modules
2+
npm-debug.log

docker-compose.yml

Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,50 @@ services:
8686
ports:
8787
- "8082:8082"
8888

89+
code-execution:
90+
container_name: code-execution
91+
image: asia-southeast1-docker.pkg.dev/cs3219-400714/peerprep/code-execution:latest
92+
build:
93+
context: ./code_execution
94+
dockerfile: Dockerfile.prod
95+
environment:
96+
- PORT=8090
97+
- JUDGE0_API_KEY=${JUDGE0_API_KEY}
98+
ports:
99+
- "8090:8090"
100+
volumes:
101+
- questions_test_cases:/app/question_test_cases
102+
103+
judge0-server:
104+
image: judge0/judge0:1.13.0
105+
ports:
106+
- "2358:2358"
107+
privileged: true
108+
environment:
109+
REDIS_PASSWORD: ${REDIS_PASSWORD}
110+
POSTGRES_HOST: postgres
111+
POSTGRES_USER: ${POSTGRES_USER}
112+
POSTGRES_PASSWORD: ${POSTGRES_PASSWORD}
113+
POSTGRES_DB: judge0
114+
POSTGRES_PORT: ${PG_PORT}
115+
116+
env_file:
117+
- config_env/config-judge0.env
118+
119+
judge0-workers:
120+
image: judge0/judge0:1.13.0
121+
command: ["./scripts/workers"]
122+
privileged: true
123+
environment:
124+
REDIS_PASSWORD: ${REDIS_PASSWORD}
125+
POSTGRES_HOST: postgres
126+
POSTGRES_USER: ${POSTGRES_USER}
127+
POSTGRES_PASSWORD: ${POSTGRES_PASSWORD}
128+
POSTGRES_DB: judge0
129+
POSTGRES_PORT: ${PG_PORT}
130+
env_file:
131+
- config_env/config-judge0.env
132+
89133
mongo:
90134
container_name: mongo
91135
image: mongo:6.0
@@ -124,6 +168,18 @@ services:
124168
retries: 5
125169
start_period: 30s
126170

171+
redis:
172+
container_name: redis
173+
image: redis:7
174+
ports:
175+
- "6379:6379"
176+
command: [
177+
"bash", "-c",
178+
'docker-entrypoint.sh --appendonly yes --requirepass "$$REDIS_PASSWORD"'
179+
]
180+
environment:
181+
REDIS_PASSWORD: ${REDIS_PASSWORD}
182+
127183
volumes:
128184
postgres_data:
129185
mongo-dev-data:

docker_compose_dev.yml

Lines changed: 11 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,6 @@ services:
7777
- "8083:8083"
7878

7979
# judge0-server:
80-
# container_name: judge0-server
8180
# image: judge0/judge0:1.13.0
8281
# ports:
8382
# - "2358:2358"
@@ -144,17 +143,17 @@ services:
144143
retries: 5
145144
start_period: 30s
146145

147-
# redis:
148-
# container_name: redis
149-
# image: redis:7
150-
# ports:
151-
# - "6379:6379"
152-
# command: [
153-
# "bash", "-c",
154-
# 'docker-entrypoint.sh --appendonly yes --requirepass "$$REDIS_PASSWORD"'
155-
# ]
156-
# environment:
157-
# REDIS_PASSWORD: ${REDIS_PASSWORD}
146+
redis:
147+
container_name: redis
148+
image: redis:7
149+
ports:
150+
- "6379:6379"
151+
command: [
152+
"bash", "-c",
153+
'docker-entrypoint.sh --appendonly yes --requirepass "$$REDIS_PASSWORD"'
154+
]
155+
environment:
156+
REDIS_PASSWORD: ${REDIS_PASSWORD}
158157

159158

160159
volumes:

frontend/src/components/ChatBox/ChatBox.component.tsx

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,7 @@ const ChatBox = () => {
7575
{entry.nickname !== user?.username && (
7676
<Avatar
7777
name={entry.nickname}
78+
src={entry.avatar}
7879
w="40px"
7980
h="40px"
8081
alignSelf="flex-start"
@@ -99,6 +100,7 @@ const ChatBox = () => {
99100
{entry.nickname === user?.username && (
100101
<Avatar
101102
name={entry.nickname}
103+
src={entry.avatar}
102104
w="40px"
103105
h="40px"
104106
alignSelf="flex-start"

frontend/src/contexts/sharededitor.context.tsx

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ import data from "../data/lang_temps.json";
1919
import { ToastId, useToast } from "@chakra-ui/react";
2020
import { wsCollabUrl } from "../api/gateway";
2121
import { getExecutionResult, submitCodeForExecution } from "../api/code";
22+
import { getProfilePicUrl } from "../api/user";
2223

2324
export type language = keyof typeof data;
2425

@@ -28,6 +29,7 @@ export const LangDataMap = data;
2829
export type chatRecord = {
2930
nickname: string;
3031
msg: string;
32+
avatar?: string;
3133
};
3234

3335
type executionResult =
@@ -143,6 +145,8 @@ export const SharedEditorProvider = ({
143145
const _submissions = useRef<Y.Array<any> | undefined>();
144146
const _poll_interval = useRef<NodeJS.Timeout | undefined>();
145147

148+
const myAvatar = getProfilePicUrl(user.profilePic);
149+
146150
const submitToServer = async (submission: submissionRecord) => {
147151
// curr submission and currsubmission in state should alr be submitted
148152
console.log("submitting answer to server");
@@ -183,6 +187,7 @@ export const SharedEditorProvider = ({
183187
{
184188
msg: s,
185189
nickname: user.username,
190+
avatar: myAvatar,
186191
},
187192
]);
188193
setChat(_chat.toArray());

0 commit comments

Comments
 (0)