Skip to content

Commit 81cf79d

Browse files
authored
Merge branch 'master' into bhcs/fix-logs
2 parents c17d6d7 + 3ebce12 commit 81cf79d

File tree

24 files changed

+408
-80
lines changed

24 files changed

+408
-80
lines changed

.gitignore

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
firebase-auth/*.json
2+
mongodb-data
3+
postgres-data
4+
.env

README.md

Lines changed: 76 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,76 @@
1-
[![Review Assignment Due Date](https://classroom.github.com/assets/deadline-readme-button-24ddc0f5d75046c5622901739e7c5dd533143b0c8e959d652212380cedb1ea36.svg)](https://classroom.github.com/a/6BOvYMwN)
2-
# AssignmentTemplate
1+
# Testing
2+
3+
We recommend using our production environment for testing. You can find the production environment at [https://peerprep.sivarn.com](https://peerprep.sivarn.com).
4+
5+
A set of email/password with admin privileges will be uploaded to Canvas through Sharing Assignment Private Info assignment.
6+
7+
# Testing Locally
8+
9+
- Install Docker for your operating system. You can find the installation instructions [here](https://docs.docker.com/get-docker/).
10+
- Clone the repository.
11+
- Run `git submodule update --init` to clone the submodules.
12+
- In the frontend folder, add .env file with the following content:
13+
14+
```
15+
NEXT_PUBLIC_FIREBASE_API_KEY=AIzaSyAMiTV5yv2D-gvCy2TNEFREZIMUJ3SnYD8
16+
NEXT_PUBLIC_FIREBASE_AUTH_DOMAIN=peerprep-test.firebaseapp.com
17+
NEXT_PUBLIC_FIREBASE_PROJECT_ID=peerprep-test
18+
NEXT_PUBLIC_FIREBASE_STORAGE_BUCKET=peerprep-test.appspot.com
19+
NEXT_PUBLIC_FIREBASE_MESSAGING_SENDER_ID=655590321803
20+
NEXT_PUBLIC_FIREBASE_APP_ID=1:655590321803:web:293756d86132bdafddae8e
21+
NEXT_PUBLIC_FIREBASE_MEASUREMENT_ID=G-XXSP3K70CN
22+
NEXT_PUBLIC_PEERPREP_INNKEEPER_SOCKET_URL=localhost
23+
```
24+
25+
Note that usually these values are kept secret, but since this is a test environment, we are not concerned about security.
26+
27+
- In the root folder, add .env file with the following content:
28+
29+
```
30+
POSTGRES_USER=peerprep
31+
POSTGRES_PASSWORD=somepassword
32+
GOOGLE_APPLICATION_CREDENTIALS=/firebase-auth/service-account.json
33+
MONGODB_URL=mongodb://peerprep-mongo:27017/questions
34+
BUCKET_NAME=peerprep-test.appspot.com
35+
USERS_SERVICE_URL=http://peerprep-users-service:6969
36+
POSTGRES_URL=postgres://peerprep:somepassword@peerprep-postgres/peerprep
37+
INITIALIZATION_VECTOR=vector
38+
ENCRYPTION_KEY=key
39+
```
40+
41+
- In the firebase-auth folder, add service-account.json (file name has to be exact match) file with the following content:
42+
43+
```
44+
{
45+
"type": "service_account",
46+
"project_id": "peerprep-test",
47+
"private_key_id": "3a7f69677fabe63fb16358b58a9bab77a79b6e22",
48+
"private_key": "-----BEGIN PRIVATE KEY-----\nMIIEuwIBADANBgkqhkiG9w0BAQEFAASCBKUwggShAgEAAoIBAQDI/7aXOEK+k/iZ\nGfo4K2WKeV2u8QSuE9RfN9oVff5fgTUHdYNK9KXF+JRAfxqf2ZJkh3hdS4ipvSxp\n1HGZQ+l9Qu4XTpQRABv+9zhhI0NQr/xk/zZzR92lVlDP/UeXqkthnhd4dKo+MId1\nl2JAeOWQaCEyDtGi0pIFnwW9k4K8Myo/hjWwE+wV4SdgY2kjBUprYsv9iAllUELn\nsr8hxXmko6YMtnF0H4GI1cD/z8GLwRsD6Y/ZUBRK8oDQFVdKHe2U5DvPqCfZ1bxb\nDfX+Jx/7+pKeWbAqFJB9s6YSJ1imQzQYuYLip2fLE2BSpUXMvlI8CxTuoxAuXHSM\nEMbMbVMnAgMBAAECggEAPuR4oy+Y/t35IxrURyAZGS+ppzRGNRwCTzsAM8plPkgF\nKkzUZK9RcbU62kWLNKpVGryi5npcjFQjoge19fGgjS/UpRlSzlD88ZY0n3xzszsl\n3ApZZM//ZB0ykyoa7TN9e9GGYYwLuwLfV+Wi+i56EmnqvSmS4g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h+DIlK9L\nTk7APwYR9tLFOY1wVT71\n-----END PRIVATE KEY-----\n",
49+
"client_email": "[email protected]",
50+
"client_id": "113117889579042558853",
51+
"auth_uri": "https://accounts.google.com/o/oauth2/auth",
52+
"token_uri": "https://oauth2.googleapis.com/token",
53+
"auth_provider_x509_cert_url": "https://www.googleapis.com/oauth2/v1/certs",
54+
"client_x509_cert_url": "https://www.googleapis.com/robot/v1/metadata/x509/firebase-adminsdk-737ke%40peerprep-test.iam.gserviceaccount.com",
55+
"universe_domain": "googleapis.com"
56+
}
57+
```
58+
59+
Note that usually these values are kept secret, but since this is a test environment, we are not concerned about security.
60+
61+
- In the root folder, run `docker compose -f docker-compose.yml up -d`.
62+
63+
- Application should be running at [http://localhost](http://localhost).
64+
65+
# Giving yourself admin privileges
66+
67+
- Login to the application in your browser using Google/Github.
68+
- Run the following commands in your terminal:
69+
70+
```
71+
docker exec -it peerprep-postgres bash
72+
psql -U peerprep
73+
UPDATE profiles SET role='admin';
74+
```
75+
76+
This will give every user admin privileges. Note that this is only for testing purposes.

deployment/Dockerfile-executor

Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,27 @@
11
# To build a Docker image from this file, run from the root directory:
2+
23
# docker build -f deployment/Dockerfile-executor -t peerprep-executor .
34

4-
FROM nixos/nix:2.3.12
5+
FROM opensuse/tumbleweed
56

67
# Environment variables
8+
79
ENV APP_ROOT /executor
810

911
WORKDIR $APP_ROOT
1012
COPY executor .
1113

12-
RUN nix-channel --update
13-
RUN nix-env -iA nixpkgs.shadow nixpkgs.gcc12 nixpkgs.python3Minimal nixpkgs.jdk19_headless
14-
RUN nix-env -if default.nix
14+
RUN groupadd -g 1300 -r peerprep && useradd -g 1300 -u 1500 -r executor
15+
16+
RUN zypper refresh
17+
RUN zypper install -t pattern -y devel_C_C++
18+
RUN zypper install -y cmake
19+
RUN zypper install -y java-11-openjdk-devel
1520

16-
RUN groupadd -g 1300 -r peerprep
17-
RUN useradd -g 1300 -u 1500 -r executor
21+
RUN cmake -DCMAKE_BUILD_TYPE=Release -S . -B ./build
22+
RUN cmake --build ./build --config Release
23+
RUN cp ./build/executor ./executor
1824

1925
EXPOSE 9000
2026

21-
CMD ["executor"]
27+
CMD ["./executor"]

deployment/Dockerfile-frontend

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,33 @@
11
# To build a Docker image from this file, run from the root directory:
2+
23
# docker build -f deployment/Dockerfile-frontend -t peerprep-frontend .
34

45
# Intermediate image for building the Next app
6+
57
FROM node:18.17.1
68

79
# Environment variables
10+
811
ENV APP_ROOT /frontend
912

1013
# Copy source code into container
14+
1115
RUN mkdir --parents $APP_ROOT
1216
WORKDIR $APP_ROOT
1317
COPY frontend .
1418

1519
# Install dependencies
16-
RUN yarn install --frozen-lockfile
20+
21+
RUN yarn install --frozen-lockfile --network-timeout 1000000000
1722

1823
# Build app
24+
1925
RUN yarn build
2026

2127
# Expose port
28+
2229
EXPOSE 3000
2330

2431
# Final image for running the Next app
32+
2533
CMD ["yarn", "start"]

deployment/Dockerfile-innkeeper

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,33 @@
11
# To build a Docker image from this file, run from the root directory:
2+
23
# docker build -f deployment/Dockerfile-innkeeper -t peerprep-innkeeper-service .
34

45
# Intermediate image for building the Next app
6+
57
FROM node:18.17.1
68

79
# Environment variables
10+
811
ENV APP_ROOT /innkeeper
912

1013
# Copy source code into container
14+
1115
RUN mkdir --parents $APP_ROOT
1216
WORKDIR $APP_ROOT
1317
COPY innkeeper .
1418

1519
# Install dependencies
20+
1621
RUN yarn install --frozen-lockfile
1722

1823
# Build app
24+
1925
RUN yarn build
2026

2127
# Expose port
28+
2229
EXPOSE 4100
2330

2431
# Final image for running the Socket.IO app
32+
2533
CMD ["yarn", "start"]

deployment/Dockerfile-nginx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ RUN rm -f /etc/nginx/conf.d/* /etc/nginx/sites-enabled/*
66

77
# Copy NGINX config
88
COPY deployment/nginx/nginx.conf /etc/nginx
9-
COPY deployment/nginx/sites-enabled/* /etc/nginx/sites-enabled/
9+
COPY deployment/nginx/sites-enabled/peerprep.sivarn.com /etc/nginx/sites-enabled/peerprep.sivarn.com
1010

1111
# Expose ports
1212
EXPOSE 80

deployment/Dockerfile-nginx-local

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
# Use nginx to serve the app
2+
FROM nginx:stable
3+
4+
# Delete NGINX defaults
5+
RUN rm -f /etc/nginx/conf.d/* /etc/nginx/sites-enabled/*
6+
7+
# Copy NGINX config
8+
COPY deployment/nginx/nginx.conf /etc/nginx
9+
COPY deployment/nginx/sites-enabled/localhost /etc/nginx/sites-enabled/locahost
10+
11+
# Expose ports
12+
EXPOSE 80
13+
EXPOSE 443
14+
15+
# Add a script containing the main command to be executed
16+
COPY deployment/scripts/cmd-nginx.sh /usr/bin/
17+
CMD ["cmd-nginx.sh"]

deployment/Dockerfile-questions

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,33 @@
11
# To build a Docker image from this file, run from the root directory:
2+
23
# docker build -f deployment/Dockerfile-questions -t peerprep-questions-service .
34

45
# Intermediate image for building the Next app
6+
57
FROM node:18.17.1
68

79
# Environment variables
10+
811
ENV APP_ROOT /questions
912

1013
# Copy source code into container
14+
1115
RUN mkdir --parents $APP_ROOT
1216
WORKDIR $APP_ROOT
1317
COPY questions .
1418

1519
# Install dependencies
20+
1621
RUN yarn install --frozen-lockfile
1722

1823
# Build app
24+
1925
RUN yarn build
2026

2127
# Expose port
28+
2229
EXPOSE 4000
2330

2431
# Final image for running the Express app
32+
2533
CMD ["yarn", "start"]
Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
# When searching for a virtual server by name, if name matches more than one of the specified variants, e.g.
2+
# both wildcard name and regular expression match, the first matching variant will be chosen, in the following
3+
# order of precedence:
4+
#
5+
# 1. exact name
6+
# 2. longest wildcard name starting with an asterisk, e.g. “*.example.org”
7+
# 3. longest wildcard name ending with an asterisk, e.g. “mail.*”
8+
# 4. first matching regular expression (in order of appearance in a configuration file)
9+
10+
server {
11+
listen 80;
12+
server_name localhost;
13+
14+
location / {
15+
proxy_pass http://peerprep-frontend:3000/;
16+
proxy_set_header Host $host;
17+
proxy_set_header X-Real-IP $remote_addr;
18+
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
19+
proxy_set_header X-Forwarded-Proto $scheme;
20+
}
21+
22+
location /api/v1/questions/ {
23+
proxy_pass http://peerprep-questions-service:4000/api/v1/questions/;
24+
proxy_set_header Host $host;
25+
proxy_set_header X-Real-IP $remote_addr;
26+
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
27+
proxy_set_header X-Forwarded-Proto $scheme;
28+
}
29+
30+
location /api/v1/users/ {
31+
proxy_pass http://peerprep-users-service:6969/api/v1/users/;
32+
proxy_set_header Host $host;
33+
proxy_set_header X-Real-IP $remote_addr;
34+
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
35+
proxy_set_header X-Forwarded-Proto $scheme;
36+
}
37+
38+
location /api/v1/innkeeper/ {
39+
proxy_pass http://peerprep-innkeeper-service:4100/api/v1/innkeeper/;
40+
proxy_set_header Host $host;
41+
proxy_http_version 1.1;
42+
proxy_set_header Upgrade $http_upgrade;
43+
proxy_set_header Connection "upgrade";
44+
proxy_set_header X-Real-IP $remote_addr;
45+
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
46+
proxy_set_header X-Forwarded-Proto $scheme;
47+
}
48+
49+
location /api/v1/execute/ {
50+
include /etc/nginx/fastcgi_params;
51+
fastcgi_pass peerprep-executor-service:9000;
52+
}
53+
}
54+
55+
# Catch-all for unrecognised requests
56+
server {
57+
listen 80 default_server;
58+
server_name _;
59+
return 444;
60+
}

0 commit comments

Comments
 (0)