Skip to content

Commit 4f52a4d

Browse files
Assignment 4
1 parent 71957f2 commit 4f52a4d

File tree

9 files changed

+114
-13
lines changed

9 files changed

+114
-13
lines changed

Readme.md

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,10 @@
11
# Setting up PeerPrep
22

33
1. Install docker desktop
4-
2. Use readme in /user-service to setup user service
5-
3. Use readme in /questionapi to setup question service
6-
4. Use readme in /client to setup client
4+
2. Run docker compose up -d in project root directory
75
5. Once the container is built, the application should be running on localhost:3002
86

7+
98
# Help
109
* Give the containers sometime to start up
1110
* Delete the docker containers and images and rebuild the containers

client/Dockerfile

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
FROM node:16-alpine as builder
2+
WORKDIR './client'
3+
COPY ./package.json ./
4+
RUN npm install
5+
COPY . .
6+
# RUN npm run build // only use for deployment
7+
EXPOSE 3002
8+
CMD ["npm", "start"]

client/src/pages/Authentication/Register.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -102,10 +102,10 @@ export default function Register() {
102102
const handleInputChange = (event) => {
103103
const newValue = event.target.value;
104104

105-
105+
// Define a regular expression pattern to match your criteria
106106
const pattern = /^[a-z0-9._-]{1,30}$/;
107107

108-
108+
// Test if the input value matches the pattern
109109
if (!pattern.test(newValue)) {
110110
setErrorUsername("Use only lowercase a-z, 0-9, ., _ or -");
111111

docker-compose.yml

Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
services:
2+
user-service:
3+
build:
4+
context: ./user-service
5+
dockerfile: Dockerfile.userservice-backend
6+
ports:
7+
- "3000:3000"
8+
env_file:
9+
- ./user-service/.env
10+
depends_on:
11+
user-service-db:
12+
condition: service_healthy
13+
restart: on-failure
14+
15+
user-service-db:
16+
build:
17+
context: ./user-service
18+
dockerfile: Dockerfile.postgres-db
19+
env_file:
20+
- ./user-service/.env
21+
healthcheck:
22+
test: [ "CMD-SHELL", "pg_isready -U postgres" ]
23+
interval: 5s
24+
timeout: 3s
25+
retries: 3
26+
restart: on-failure
27+
28+
question-service:
29+
build: ./question-service
30+
ports:
31+
- "3001:3001"
32+
depends_on:
33+
- user-service
34+
env_file:
35+
- ./question-service/.env
36+
restart: on-failure
37+
38+
client:
39+
build: ./client
40+
ports:
41+
- "3002:3002"
42+
depends_on:
43+
- user-service
44+
- question-service
45+
restart: on-failure
46+
# nginx-api-gateway:
47+
# build: ./nginx
48+
# ports:
49+
# - "80:80"
50+
# depends_on:
51+
# - user-service
52+
# - question-service
53+
# - matching-service
54+
# - collaboration-service
55+
# - client
56+
# restart: on-failure

question-service/Dockerfile

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
FROM alpine:latest
2+
RUN apk update && \
3+
apk add nodejs npm
4+
RUN npm install -g nodemon
5+
WORKDIR '/question-service'
6+
COPY package*.json ./
7+
RUN npm install
8+
# RUN npm ci --omit=dev
9+
COPY . .
10+
EXPOSE 3001
11+
CMD [ "nodemon", "index.js" ]

question-service/readme.md

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,15 @@
1-
# Starting sev (Dev mode)
1+
# MongoDB question-service setup using docker
22

3-
1. Run `npm i` => install all dependencies from package.json
4-
2. Run `nodemon index.js` => hot reloads the event loop
3+
1. Install docker desktop
4+
2. In the root dir question-service/ run `docker build . -t <docker-username>/question-api`
5+
3. Amend container name and port as needed and run the command
6+
`docker run -p 3001:3001 -d <docker-username>/question-api`
57

8+
Note: To access docker container:
69
Use the following link: `http://localhost:3001/`
710
You should see the following display: `You are on the question api service!`
11+
12+
# Starting sev (Dev mode)
13+
14+
1. Run `npm i` => install all dependencies from package.json
15+
2. Run `nodemon index.js` => hot reloads the event loop

user-service/.env.example

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
DB_USER=postgres
22
POSTGRES_PASSWORD=<fill in>
3-
DB_ADDR=localhost
4-
DB_PORT=1111
3+
DB_ADDR=user-service-db
4+
DB_PORT=5432
55
DB_NAME=userservice
66
JWT_SECRET=<fill in>
77
ADMIN_PASSWORD=<admin password to login to db fill in>
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
FROM node:18
2+
WORKDIR /userservice
3+
COPY package*.json ./
4+
RUN npm i
5+
COPY app.ts ./
6+
COPY tsconfig.json ./
7+
WORKDIR /userservice/src
8+
COPY src ./
9+
EXPOSE 3000
10+
RUN npm run build
11+
CMD ["npm", "run", "start:prod"]

user-service/readme.md

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,16 @@
22

33
1. Install docker desktop
44
2. In the root dir user-service/ run `docker build -f Dockerfile.postgres-db -t user-service-psql .`
5-
3. Amend the password, container name and port as needed and run the command
6-
`docker run -p 1111:5432 -e POSTGRES_PASSWORD=<POSTGRES_PASSWORD> --name user-service-db -d user-service-psql`
5+
3. Create user-service container
6+
`docker build -f Dockerfile.userservice-backend -t user-service-backend .`
7+
4. Create network for user-service
8+
`docker network create user-service`
9+
5. Start DB container from image - replace fields
10+
`docker run --env-file=.env --name user-service-db -d --network=user-service user-service-psql`
11+
6. Get DB container IP - copy this value into DB_ADDR in .env
12+
`docker inspect user-service-db | grep IPAddress`
13+
7. Start user-service container from image
14+
`docker run -p 3000:3000 --env-file=.env --name user-service-backend -d --network=user-service user-service-backend`
715

816
# Setup
917

@@ -25,4 +33,4 @@
2533
### Admin account
2634

2735
28-
password: Set by ADMIN_PASSWORD field
36+
password: Set by ADMIN_PASSWORD field

0 commit comments

Comments
 (0)