Skip to content

Commit c1861bb

Browse files
LimZiJiasamuelim01
andauthored
Init user service (#39)
* Copy user service https://github.com/CS3219-AY2425S1/PeerPrep-UserService * Dockerise user-service Got user service to work in docker. It can only interface with an atlas cloud server currently. * Dockerise user-service User-service in docker can only communicate with an atlas mongodb server. * Merge with main Some files should have been committed in the previous commit. They are mostly to do with the dockerisation process. The merge with main might have messed with it. * Create .gitignore Somehow .gitignore was not commited with the last commit * Fix POST causing SEGSEGV Apparently bcrypt library cannot run on Docker's architecture. Change bcrypt to bcryptjs for compatibility. * Add test Test does not currently work * Basic user service Not connected to the login interface yet. Commiting to make a clean Pr. * Move user service folder * Fix minor user service issues * Remove orphan history file * Move `index.js` and `server.js` to the correct directory * Reduce use of port * Change login to use username * Fix user env typo --------- Co-authored-by: samuelim01 <[email protected]>
1 parent 154b802 commit c1861bb

34 files changed

+4148
-4
lines changed

.env.sample

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,20 @@
11
# This is a sample environment configuration file.
22
# Copy this file to .env and replace the placeholder values with your own.
3+
4+
# Question Service
35
QUESTION_DB_CLOUD_URI=<FILL-THIS-IN>
46
QUESTION_DB_LOCAL_URI=mongodb://question-db:27017/question
57
QUESTION_DB_USERNAME=user
68
QUESTION_DB_PASSWORD=password
79

8-
NODE_ENV=development
10+
# User Service
11+
USER_SERVICE_CLOUD_URI=mongodb+srv://admin:<db_password>@cluster0.uo0vu.mongodb.net/?retryWrites=true&w=majority&appName=Cluster0
12+
USER_SERVICE_LOCAL_URI=mongodb://127.0.0.1:27017/peerprepUserServiceDB
13+
14+
# Will use cloud MongoDB Atlas database
15+
ENV=PROD
16+
17+
# Secret for creating JWT signature
18+
JWT_SECRET=you-can-replace-this-with-your-own-secret
19+
20+
NODE_ENV=development

.gitignore

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1-
# Ignore IntelliJ IDEA project files
2-
.idea/
3-
.env
1+
**/node_modules
2+
**/.env
3+
**/.idea
4+
# Vim temp files
5+
*~
6+
*.swp
7+
*.swo

docker-compose.yml

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ services:
1212
- ./frontend:/app
1313
networks:
1414
- question-network
15+
- user-network
1516

1617
question:
1718
container_name: question
@@ -32,6 +33,7 @@ services:
3233
networks:
3334
- question-network
3435
- question-db-network
36+
- user-network
3537

3638
question-db:
3739
container_name: question-db
@@ -46,11 +48,33 @@ services:
4648
- question-db-network
4749
restart: always
4850

51+
user:
52+
container_name: user
53+
image: user
54+
build:
55+
context: services/user
56+
dockerfile: Dockerfile
57+
ports:
58+
- 3001
59+
environment:
60+
USER_SERVICE_CLOUD_URI: ${USER_SERVICE_CLOUD_URI}
61+
USER_SERVICE_LOCAL_URI: ${USER_SERVICE_LOCAL_URI}
62+
ENV: ${ENV}
63+
JWT_SECRET: ${JWT_SECRET}
64+
volumes:
65+
- /app/node_modules
66+
- ./services/user:/app
67+
networks:
68+
- user-network
69+
restart: always
70+
4971
volumes:
5072
question-db:
5173

5274
networks:
5375
question-network:
5476
driver: bridge
5577
question-db-network:
78+
driver: bridge
79+
user-network:
5680
driver: bridge

services/user/.env.sample

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
# User Service
2+
USER_SERVICE_CLOUD_URI=<cloud_uri>
3+
USER_SERVICE_LOCAL_URI=mongodb://127.0.0.1:27017/peerprepUserServiceDB
4+
PORT=3001
5+
6+
# Will use cloud MongoDB Atlas database
7+
ENV=PROD
8+
9+
# Secret for creating JWT signature
10+
JWT_SECRET=you-can-replace-this-with-your-own-secret
11+
12+
NODE_ENV=development

services/user/Dockerfile

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
FROM node:20-alpine
2+
3+
WORKDIR /app
4+
COPY package.json package-lock.json ./
5+
RUN npm install
6+
COPY . .
7+
EXPOSE 3001
8+
9+
CMD ["npm", "start"]

services/user/MongoDBSetup.md

Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
# Setting up MongoDB Instance for User Service
2+
3+
1. Visit the MongoDB Atlas Site [https://www.mongodb.com/atlas](https://www.mongodb.com/atlas) and click on "Try Free"
4+
5+
2. Sign Up/Sign In with your preferred method.
6+
7+
3. You will be greeted with welcome screens. Feel free to skip them till you reach the Dashboard page.
8+
9+
4. Create a Database Deployment by clicking on the green `+ Create` Button:
10+
11+
![alt text](./GuideAssets/Creation.png)
12+
13+
5. Make selections as followings:
14+
15+
- Select Shared Cluster
16+
- Select `aws` as Provider
17+
18+
![alt text](./GuideAssets/Selection1.png)
19+
20+
- Select `Singapore` for Region
21+
22+
![alt text](./GuideAssets/Selection2.png)
23+
24+
- Select `M0 Sandbox` Cluster (Free Forever - No Card Required)
25+
26+
> Ensure to select M0 Sandbox, else you may be prompted to enter card details and may be charged!
27+
28+
![alt text](./GuideAssets/Selection3.png)
29+
30+
- Leave `Additional Settings` as it is
31+
32+
- Provide a suitable name to the Cluster
33+
34+
![alt text](./GuideAssets/Selection4.png)
35+
36+
6. You will be prompted to set up Security for the database by providing `Username and Password`. Select that option and enter `Username` and `Password`. Please keep this safe as it will be used in User Service later on.
37+
38+
![alt text](./GuideAssets/Security.png)
39+
40+
7. Next, click on `Add my Current IP Address`. This will whiteliste your IP address and allow you to connect to the MongoDB Database.
41+
42+
![alt text](./GuideAssets/Network.png)
43+
44+
8. Click `Finish and Close` and the MongoDB Instance should be up and running.
45+
46+
## Whitelisting All IP's
47+
48+
1. Select `Network Access` from the left side pane on Dashboard.
49+
50+
![alt text](./GuideAssets/SidePane.png)
51+
52+
2. Click on the `Add IP Address` Button
53+
54+
![alt text](./GuideAssets/AddIPAddress.png)
55+
56+
3. Select the `ALLOW ACCESS FROM ANYWHERE` Button and Click `Confirm`
57+
58+
![alt text](./GuideAssets/IPWhitelisting.png)
59+
60+
Now, any IP Address can access this Database.

0 commit comments

Comments
 (0)