Skip to content

Commit

Permalink
final submission
Browse files Browse the repository at this point in the history
  • Loading branch information
cheehongw committed Nov 15, 2023
1 parent 70832f9 commit beda92e
Show file tree
Hide file tree
Showing 13 changed files with 61 additions and 26 deletions.
3 changes: 2 additions & 1 deletion .env.example
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,5 @@ POSTGRES_DB="user-service"
PG_PORT=5432
SECRET_KEY=

REDIS_PASSWORD=
REDIS_PASSWORD=
REACT_APP_BACKEND_HOST="localhost"
Binary file added G10_Report.pdf
Binary file not shown.
9 changes: 3 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,13 +1,10 @@
# Running this project

Simply run `docker-compose up --build` or `docker compose up --build`
Simply run `docker-compose up --build` or `docker compose up --build` from the root of this repo with the correct `.env` file.

Please see `.env.example` for an idea of what variables the env file should have.

# For devs
The website should be accessible at port 80 and 443

TBA

To manually push to our service registry, please set up gcloud authentication with our project title
Then build the images as you would normally with `docker-compose build`
Then push the builds to the registry with `docker-compose push`

2 changes: 1 addition & 1 deletion api_gateway/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import { isLocal } from './proxy/service_addresses';
import cors from 'cors';

const corsOptions = {
origin: ["http://peerprep-g10.com", "https://peerprep-g10.com", "http://localhost:3000"],
origin: ["http://peerprep-g10.com", "https://peerprep-g10.com", "http://localhost:3000", "http://localhost", "https://localhost"],
methods: ["GET", "POST", "PUT", "PATCH", "DELETE", "OPTIONS"],
optionsSuccessStatus: 200,
credentials: true,
Expand Down
3 changes: 1 addition & 2 deletions code_execution/src/executor_client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,7 @@ import { callbacks, langToId } from "./shared";
import { judge0Result, judge0submission, submissionResult } from "./types";
import { submitSubmission } from "./submission_client";

const JUDGE_API_URL = "http://peerprep-g10.com:2358"; //"https://judge0-ce.p.rapidapi.com";
const API_KEY = process.env.JUDGE0_API_KEY;
const JUDGE_API_URL = "http://judge0:2358"; //"https://judge0-ce.p.rapidapi.com";

async function submitIndividual(submission: judge0submission) {
const response = await axios.post(
Expand Down
4 changes: 3 additions & 1 deletion docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ services:
build:
context: ./frontend
dockerfile: Dockerfile.prod
args:
- REACT_APP_BACKEND_HOST=${REACT_APP_BACKEND_HOST}
image: asia-southeast1-docker.pkg.dev/cs3219-400714/peerprep/frontend:latest
environment:
- REACT_APP_ENV_TYPE=prod
Expand Down Expand Up @@ -94,13 +96,13 @@ services:
dockerfile: Dockerfile.prod
environment:
- PORT=8090
- JUDGE0_API_KEY=${JUDGE0_API_KEY}
ports:
- "8090:8090"
volumes:
- questions_test_cases:/app/question_test_cases

judge0-server:
container_name: judge0
image: judge0/judge0:1.13.0
ports:
- "2358:2358"
Expand Down
1 change: 0 additions & 1 deletion docker_compose_dev.yml
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,6 @@ services:
context: ./code_execution
environment:
- PORT=8090
- JUDGE0_API_KEY=${JUDGE0_API_KEY}
ports:
- "8090:8090"
volumes:
Expand Down
8 changes: 8 additions & 0 deletions frontend/Dockerfile.prod
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,21 @@ FROM node:18-alpine as build
WORKDIR /app
COPY package.json ./
COPY package-lock.json ./
COPY create-env-file.sh ./
RUN npm ci
COPY . ./

ARG REACT_APP_BACKEND_HOST

RUN sh create-env-file.sh REACT_APP_BACKEND_HOST=$REACT_APP_BACKEND_HOST
RUN npm run build


# Serve stage
FROM nginx:alpine
COPY nginx.conf /etc/nginx/conf.d/default.conf
COPY --from=build /app/build /usr/share/nginx/html
COPY --from=build /app/.env /usr/share/nginx/html

EXPOSE 80
CMD ["nginx", "-g", "daemon off;"]
9 changes: 9 additions & 0 deletions frontend/create-env-file.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
#!/usr/bin/env bash
#

touch .env

for envvar in "$@"
do
echo "$envvar" >> .env
done
15 changes: 15 additions & 0 deletions frontend/nginx.conf
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
server {
listen 80;
server_name localhost;

location / {
root /usr/share/nginx/html;
index index.html index.htm;
try_files $uri /index.html;
}

error_page 500 502 503 504 /50x.html;
location = /50x.html {
root /usr/share/nginx/html;
}
}
8 changes: 5 additions & 3 deletions frontend/src/api/gateway.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
import axios from 'axios'

const backendHost = process.env.REACT_APP_BACKEND_HOST;

export const apiGatewayClient = axios.create({
baseURL: process.env.NODE_ENV === 'production'? 'http://peerprep-g10.com:8000' : 'http://localhost:8000' ,
baseURL: process.env.NODE_ENV === 'production'? `http://${backendHost}:8000` : 'http://localhost:8000' ,
withCredentials: true
})


export const wsMatchMakeURL = process.env.NODE_ENV === 'production'? 'http://peerprep-g10.com:7999' : 'http://localhost:7999'
export const wsCollabUrl = process.env.NODE_ENV === 'production'? 'ws://peerprep-g10.com:8083' :'ws://localhost:8083'
export const wsMatchMakeURL = process.env.NODE_ENV === 'production'? `http://${backendHost}:7999` : 'http://localhost:7999'
export const wsCollabUrl = process.env.NODE_ENV === 'production'? `ws://${backendHost}:8083` :'ws://localhost:8083'
2 changes: 1 addition & 1 deletion frontend/src/reducers/authSlice.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ const dummyAdmin: User = {
};

const initialState: AuthState = {
user: dummyUser // null
user: null
}

const userSlice = createSlice({
Expand Down
23 changes: 13 additions & 10 deletions question_service/src/controller/questionController.ts
Original file line number Diff line number Diff line change
Expand Up @@ -214,17 +214,20 @@ export const updateQuestion = async (req : any, res : any) => {
// @access admin only
export const deleteQuestion = async (req : any, res : any) => {
try {
// function provided by mongoose to find an Question document with a given ID
// req.params.id is retrieved from /:id in route
const question = await Question.findById(req.params.id);
if(question === null) {
throw Error('Invalid ID. Question not found in database.');
}
// function provided by mongoose to find an Question document with a given ID
// req.params.id is retrieved from /:id in route
const question = await Question.findById(req.params.id);
if (question === null) {
throw Error("Invalid ID. Question not found in database.");
}

await fs.rm(`/app/question_test_cases/${question._id}`);
await question.deleteOne();
res.status(200).json({ message: 'Question removed' });
const testcases = `/app/question_test_cases/${question._id}/`;
if (fs.existsSync(testcases)) {
await fs.rm(testcases, { recursive: true });
}
await question.deleteOne();
res.status(200).json({ message: "Question removed" });
} catch (error: any) {
res.status(404).json({ message: error.message })
res.status(404).json({ message: error.message });
}
}

0 comments on commit beda92e

Please sign in to comment.