Skip to content

Commit

Permalink
Init user service (#39)
Browse files Browse the repository at this point in the history
* 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 <samuelim01@gmail.com>
  • Loading branch information
LimZiJia and samuelim01 authored Sep 28, 2024
1 parent 154b802 commit c1861bb
Show file tree
Hide file tree
Showing 34 changed files with 4,148 additions and 4 deletions.
14 changes: 13 additions & 1 deletion .env.sample
Original file line number Diff line number Diff line change
@@ -1,8 +1,20 @@
# This is a sample environment configuration file.
# Copy this file to .env and replace the placeholder values with your own.

# Question Service
QUESTION_DB_CLOUD_URI=<FILL-THIS-IN>
QUESTION_DB_LOCAL_URI=mongodb://question-db:27017/question
QUESTION_DB_USERNAME=user
QUESTION_DB_PASSWORD=password

NODE_ENV=development
# User Service
USER_SERVICE_CLOUD_URI=mongodb+srv://admin:<db_password>@cluster0.uo0vu.mongodb.net/?retryWrites=true&w=majority&appName=Cluster0
USER_SERVICE_LOCAL_URI=mongodb://127.0.0.1:27017/peerprepUserServiceDB

# Will use cloud MongoDB Atlas database
ENV=PROD

# Secret for creating JWT signature
JWT_SECRET=you-can-replace-this-with-your-own-secret

NODE_ENV=development
10 changes: 7 additions & 3 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
# Ignore IntelliJ IDEA project files
.idea/
.env
**/node_modules
**/.env
**/.idea
# Vim temp files
*~
*.swp
*.swo
24 changes: 24 additions & 0 deletions docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ services:
- ./frontend:/app
networks:
- question-network
- user-network

question:
container_name: question
Expand All @@ -32,6 +33,7 @@ services:
networks:
- question-network
- question-db-network
- user-network

question-db:
container_name: question-db
Expand All @@ -46,11 +48,33 @@ services:
- question-db-network
restart: always

user:
container_name: user
image: user
build:
context: services/user
dockerfile: Dockerfile
ports:
- 3001
environment:
USER_SERVICE_CLOUD_URI: ${USER_SERVICE_CLOUD_URI}
USER_SERVICE_LOCAL_URI: ${USER_SERVICE_LOCAL_URI}
ENV: ${ENV}
JWT_SECRET: ${JWT_SECRET}
volumes:
- /app/node_modules
- ./services/user:/app
networks:
- user-network
restart: always

volumes:
question-db:

networks:
question-network:
driver: bridge
question-db-network:
driver: bridge
user-network:
driver: bridge
12 changes: 12 additions & 0 deletions services/user/.env.sample
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
# User Service
USER_SERVICE_CLOUD_URI=<cloud_uri>
USER_SERVICE_LOCAL_URI=mongodb://127.0.0.1:27017/peerprepUserServiceDB
PORT=3001

# Will use cloud MongoDB Atlas database
ENV=PROD

# Secret for creating JWT signature
JWT_SECRET=you-can-replace-this-with-your-own-secret

NODE_ENV=development
9 changes: 9 additions & 0 deletions services/user/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
FROM node:20-alpine

WORKDIR /app
COPY package.json package-lock.json ./
RUN npm install
COPY . .
EXPOSE 3001

CMD ["npm", "start"]
60 changes: 60 additions & 0 deletions services/user/MongoDBSetup.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
# Setting up MongoDB Instance for User Service

1. Visit the MongoDB Atlas Site [https://www.mongodb.com/atlas](https://www.mongodb.com/atlas) and click on "Try Free"

2. Sign Up/Sign In with your preferred method.

3. You will be greeted with welcome screens. Feel free to skip them till you reach the Dashboard page.

4. Create a Database Deployment by clicking on the green `+ Create` Button:

![alt text](./GuideAssets/Creation.png)

5. Make selections as followings:

- Select Shared Cluster
- Select `aws` as Provider

![alt text](./GuideAssets/Selection1.png)

- Select `Singapore` for Region

![alt text](./GuideAssets/Selection2.png)

- Select `M0 Sandbox` Cluster (Free Forever - No Card Required)

> Ensure to select M0 Sandbox, else you may be prompted to enter card details and may be charged!
![alt text](./GuideAssets/Selection3.png)

- Leave `Additional Settings` as it is

- Provide a suitable name to the Cluster

![alt text](./GuideAssets/Selection4.png)

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.

![alt text](./GuideAssets/Security.png)

7. Next, click on `Add my Current IP Address`. This will whiteliste your IP address and allow you to connect to the MongoDB Database.

![alt text](./GuideAssets/Network.png)

8. Click `Finish and Close` and the MongoDB Instance should be up and running.

## Whitelisting All IP's

1. Select `Network Access` from the left side pane on Dashboard.

![alt text](./GuideAssets/SidePane.png)

2. Click on the `Add IP Address` Button

![alt text](./GuideAssets/AddIPAddress.png)

3. Select the `ALLOW ACCESS FROM ANYWHERE` Button and Click `Confirm`

![alt text](./GuideAssets/IPWhitelisting.png)

Now, any IP Address can access this Database.
Loading

0 comments on commit c1861bb

Please sign in to comment.