diff --git a/.env b/.env new file mode 100644 index 0000000000..0256ef612f --- /dev/null +++ b/.env @@ -0,0 +1,10 @@ +# URLs - change these to your local or cloud deployment IP address/URL if necessary +PUBLIC_URL=http://localhost +WS_PUBLIC_URL=ws://localhost + +# Port numbers - change these if you are already using these ports for other (non-PeerPrep) services +FRONTEND_PORT=3000 +QUESTION_API_PORT=2000 +USER_API_PORT=3001 +MATCHING_API_PORT=3002 +COLLAB_API_PORT=3003 \ No newline at end of file diff --git a/README.md b/README.md index e8fe1a1a9e..4f75898f0a 100644 --- a/README.md +++ b/README.md @@ -2,6 +2,35 @@ # CS3219 Project (PeerPrep) - AY2425S1 ## Group: G44 +### Running PeerPrep +Before you run PeerPrep, please check the `.env` file in the root directory, and modify the IP address/URL and/or ports if necessary. It should look something like this: +```sh +# URLs - change these to your local or cloud deployment IP address/URL if necessary +PUBLIC_URL=http://localhost +WS_PUBLIC_URL=ws://localhost + +# Port numbers - change these if you are already using these ports for other (non-PeerPrep) services +FRONTEND_PORT=3000 +QUESTION_API_PORT=2000 +USER_API_PORT=3001 +MATCHING_API_PORT=3002 +COLLAB_API_PORT=3003 +``` + +Then, in the root directory, run +```sh +docker compose up -d +``` +and access PeerPrep at [localhost:3000](http://localhost:3000), or the IP address/URL you set earlier in the `.env` file + +> To force a rebuild of the images, run +> `docker compose up -d --build` + +#### Developing +If you are developing PeerPrep, you can use [Compose Watch](https://docs.docker.com/compose/how-tos/file-watch/) to automatically update and preview code changes: +```sh +docker compose up --watch --build +``` ### API Endpoints #### Question Service @@ -60,22 +89,6 @@ Replies with: } ``` -### Running PeerPrep -In the root directory, run -```sh -docker compose up -d -``` -and access PeerPrep at [localhost:3000](http://localhost:3000) - -> To force a rebuild of the images, run -> `docker compose up -d --build` - -#### Developing -If you are developing PeerPrep, you can use [Compose Watch](https://docs.docker.com/compose/how-tos/file-watch/) to automatically update and preview code changes: -```sh -docker compose up --watch --build -``` - ### Note: - You can choose to develop individual microservices within separate folders within this repository **OR** use individual repositories (all public) for each microservice. - In the latter scenario, you should enable sub-modules on this GitHub classroom repository to manage the development/deployment **AND** add your mentor to the individual repositories as a collaborator. diff --git a/docker-compose.yml b/docker-compose.yml index e912149780..92cdb1a85b 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -6,8 +6,16 @@ services: build: context: ./frontend dockerfile: Dockerfile.dev + args: + PUBLIC_URL: ${PUBLIC_URL} + WS_PUBLIC_URL: ${WS_PUBLIC_URL} + FRONTEND_PORT: ${FRONTEND_PORT} + QUESTION_API_PORT: ${QUESTION_API_PORT} + USER_API_PORT: ${USER_API_PORT} + MATCHING_API_PORT: ${MATCHING_API_PORT} + COLLAB_API_PORT: ${COLLAB_API_PORT} ports: - - "3000:3000" + - "${FRONTEND_PORT}:${FRONTEND_PORT}" develop: watch: - action: sync @@ -19,7 +27,7 @@ services: context: ./backend/question-service dockerfile: Dockerfile.dev ports: - - "2000:2000" + - "${QUESTION_API_PORT}:2000" develop: watch: - action: sync @@ -33,7 +41,7 @@ services: env_file: - ./backend/user-service/.env ports: - - "3001:3001" + - "${USER_API_PORT}:3001" zookeeper: image: confluentinc/cp-zookeeper:7.7.1 @@ -73,7 +81,7 @@ services: environment: KAFKA_BROKER: kafka:9092 ports: - - "3002:3002" + - "${MATCHING_API_PORT}:3002" depends_on: kafka: condition: service_healthy @@ -83,4 +91,4 @@ services: context: ./backend/signaling-service dockerfile: Dockerfile.dev ports: - - "3003:3003" + - "${COLLAB_API_PORT}:3003" diff --git a/frontend/.env.local b/frontend/.env.local index 1c8c7356e0..22e5b0a2a8 100644 --- a/frontend/.env.local +++ b/frontend/.env.local @@ -1,29 +1,29 @@ -PUBLIC_URL=http://localhost -WS_PUBLIC_URL=ws://localhost +# PUBLIC_URL=http://localhost +# WS_PUBLIC_URL=ws://localhost -# Frontend servce -FRONTEND_PORT=3000 -NEXT_PUBLIC_FRONTEND_URL=$PUBLIC_URL:$FRONTEND_PORT +# # Frontend servce +# FRONTEND_PORT=3000 +# NEXT_PUBLIC_FRONTEND_URL=$PUBLIC_URL:$FRONTEND_PORT -# Question service -QUESTION_API_PORT=2000 -NEXT_PUBLIC_QUESTION_API_BASE_URL=$PUBLIC_URL:$QUESTION_API_PORT/questions +# # Question service +# QUESTION_API_PORT=2000 +# NEXT_PUBLIC_QUESTION_API_BASE_URL=$PUBLIC_URL:$QUESTION_API_PORT/questions -# User service -USER_API_PORT=3001 -USER_API_BASE_URL=$PUBLIC_URL:$USER_API_PORT -NEXT_PUBLIC_USER_API_AUTH_URL=$USER_API_BASE_URL/auth -NEXT_PUBLIC_USER_API_USERS_URL=$USER_API_BASE_URL/users -NEXT_PUBLIC_USER_API_EMAIL_URL=$USER_API_BASE_URL/email -NEXT_PUBLIC_USER_API_HISTORY_URL=$USER_API_BASE_URL/users/history +# # User service +# USER_API_PORT=3001 +# USER_API_BASE_URL=$PUBLIC_URL:$USER_API_PORT +# NEXT_PUBLIC_USER_API_AUTH_URL=$USER_API_BASE_URL/auth +# NEXT_PUBLIC_USER_API_USERS_URL=$USER_API_BASE_URL/users +# NEXT_PUBLIC_USER_API_EMAIL_URL=$USER_API_BASE_URL/email +# NEXT_PUBLIC_USER_API_HISTORY_URL=$USER_API_BASE_URL/users/history -# Matching service -MATCHING_API_PORT=3002 -NEXT_PUBLIC_MATCHING_API_URL=$PUBLIC_URL:$MATCHING_API_PORT/matching +# # Matching service +# MATCHING_API_PORT=3002 +# NEXT_PUBLIC_MATCHING_API_URL=$PUBLIC_URL:$MATCHING_API_PORT/matching -# Collab service -COLLAB_API_PORT=3003 -NEXT_PUBLIC_COLLAB_API_URL=$WS_PUBLIC_URL:$COLLAB_API_PORT +# # Collab service +# COLLAB_API_PORT=3003 +# NEXT_PUBLIC_COLLAB_API_URL=$WS_PUBLIC_URL:$COLLAB_API_PORT NEXT_PUBLIC_EMAIL_USER=peerprep.no.reply@gmail.com NEXT_PUBLIC_EMAIL_PASS=peerprepg44 \ No newline at end of file diff --git a/frontend/Dockerfile.dev b/frontend/Dockerfile.dev index 9ca431a6ac..d926e1ac0d 100644 --- a/frontend/Dockerfile.dev +++ b/frontend/Dockerfile.dev @@ -1,6 +1,36 @@ FROM node:22-alpine3.19 AS builder WORKDIR /app +ARG PUBLIC_URL +ARG WS_PUBLIC_URL +ARG FRONTEND_PORT +ARG QUESTION_API_PORT +ARG USER_API_PORT +ARG MATCHING_API_PORT +ARG COLLAB_API_PORT + +ENV PUBLIC_URL=${PUBLIC_URL} +ENV WS_PUBLIC_URL=${WS_PUBLIC_URL} + +ENV FRONTEND_PORT=${FRONTEND_PORT} +ENV NEXT_PUBLIC_FRONTEND_URL=${PUBLIC_URL}:${FRONTEND_PORT} + +ENV QUESTION_API_PORT=${QUESTION_API_PORT} +ENV NEXT_PUBLIC_QUESTION_API_BASE_URL=${PUBLIC_URL}:${QUESTION_API_PORT}/questions + +ENV USER_API_PORT=${USER_API_PORT} +ENV USER_API_BASE_URL=${PUBLIC_URL}:${USER_API_PORT} +ENV NEXT_PUBLIC_USER_API_AUTH_URL=${USER_API_BASE_URL}/auth +ENV NEXT_PUBLIC_USER_API_USERS_URL=${USER_API_BASE_URL}/users +ENV NEXT_PUBLIC_USER_API_EMAIL_URL=${USER_API_BASE_URL}/email +ENV NEXT_PUBLIC_USER_API_HISTORY_URL=${USER_API_BASE_URL}/users/history + +ENV MATCHING_API_PORT=${MATCHING_API_PORT} +ENV NEXT_PUBLIC_MATCHING_API_URL=${PUBLIC_URL}:${MATCHING_API_PORT}/matching + +ENV COLLAB_API_PORT=${COLLAB_API_PORT} +ENV NEXT_PUBLIC_COLLAB_API_URL=${PUBLIC_URL}:${COLLAB_API_PORT} + COPY package.json package-lock.json ./ RUN npm ci COPY . .