From 5fc9729f4d01c997bf6e69afb42ab9a29332b2b2 Mon Sep 17 00:00:00 2001 From: iynixil Date: Mon, 11 Nov 2024 15:13:58 +0800 Subject: [PATCH 1/3] Update docker-compose file, Add containerization of frontend --- backend/feedback-service/package-lock.json | 6 --- docker-compose.yml | 56 ++++++++++++++++++---- frontend/Dockerfile | 23 +++++++++ 3 files changed, 69 insertions(+), 16 deletions(-) delete mode 100644 backend/feedback-service/package-lock.json create mode 100644 frontend/Dockerfile diff --git a/backend/feedback-service/package-lock.json b/backend/feedback-service/package-lock.json deleted file mode 100644 index 238195c120..0000000000 --- a/backend/feedback-service/package-lock.json +++ /dev/null @@ -1,6 +0,0 @@ -{ - "name": "feedback-service", - "lockfileVersion": 3, - "requires": true, - "packages": {} -} diff --git a/docker-compose.yml b/docker-compose.yml index c4ffff3291..50f303a0ae 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -46,12 +46,11 @@ services: container_name: matching-service environment: - RABBIT_HOSTNAME=rabbitmq # URL to connect to rabbitmq container in the network + - API_GATEWAY_URL=http://api-gateway:8000 depends_on: # condition to wait for rabbitmq container to be ready rabbitmq: condition: service_healthy build: ./backend/matching-service # Path to the directory containing the Dockerfile for building the matching-service image. - ports: - - 5002:5002 # Maps port 5002 on the host to port 5002 in the container, making the app accessible on the host. volumes: - ./backend/matching-service:/app # Mounts the host directory './backend/matching-service' to '/app' in the container. - /app/node_modules # Anonymous Volume @@ -60,18 +59,54 @@ services: collaboration-service: container_name: collaboration-service - build: ./backend/collaboration-service # Path to the directory containing the Dockerfile for building the matching-service image. + environment: + - URL_QUESTION_SERVICE=http://question-service:5000/question + - API_GATEWAY_URL=http://api-gateway:8000 + build: ./backend/collaboration-service # Path to the directory containing the Dockerfile for building the collaboration-service image. ports: - - 5003:5003 # Maps port 5002 on the host to port 5002 in the container, making the app accessible on the host. + - 5003:5003 # Maps port 5003 on the host to port 5003 in the container, making the app accessible on the host. volumes: - - ./backend/collaboration-service:/app # Mounts the host directory './backend/matching-service' to '/app' in the container. + - ./backend/collaboration-service:/app # Mounts the host directory './backend/collaboration-service' to '/app' in the container. - /app/node_modules # Anonymous Volume networks: - - peerprep-network # Connects the matching-service to the 'peerprep-network' network. + - peerprep-network # Connects the collaboration-service to the 'peerprep-network' network. + + api-gateway: + container_name: api-gateway + environment: + - QUESTION_SERVICE_URL=http://question-service:5000/question + - USER_SERVICE_URL=http://user-service:5001/user + - COLLABORATION_SERVICE_URL=http://collaboration-service:5003/collaboration + depends_on: + question-service: + condition: service_started + user-service: + condition: service_started + collaboration-service: + condition: service_started + build: ./backend/api-gateway # Path to the directory containing the Dockerfile for building the api-gateway image. + ports: + - 8000:8000 # Maps port 8000 on the host to port 8000 in the container, making the app accessible on the host. + volumes: + - ./backend/api-gateway:/app # Mounts the host directory './backend/api-gateway' to '/app' in the container. + - /app/node_modules # Anonymous Volume + networks: + - peerprep-network # Connects the api-gateway to the 'peerprep-network' network. + + frontend: + container_name: frontend environment: - # - QUESTION_SERVICE_URL=question-service - - QUESTION_SERVICE_URL=http://question-service:5000 - + - REACT_APP_API_GATEWAY_URL=http://localhost:8000 + build: ./frontend + ports: + - 3000:3000 + volumes: + - ./frontend:/app + - /app/node_modules + networks: + - peerprep-network + depends_on: + - api-gateway volumes: rabbitmq_data: @@ -79,4 +114,5 @@ volumes: networks: peerprep-network: # Defines a network named 'peerprep-network'. name: peerprep-network - driver: bridge # Uses the bridge driver for the network, which is the default and most common network type in Docker. \ No newline at end of file + driver: bridge # Uses the bridge driver for the network, which is the default and most common network type in Docker. + external: true \ No newline at end of file diff --git a/frontend/Dockerfile b/frontend/Dockerfile new file mode 100644 index 0000000000..9108f34960 --- /dev/null +++ b/frontend/Dockerfile @@ -0,0 +1,23 @@ +# Use an official Node.js runtime as a parent image +FROM node:20-alpine + +# Set the working directory in the container +WORKDIR /app + +# Copy package.json and package-lock.json +COPY package*.json ./ + +# Install any dependencies +RUN npm install + +# Bundle app source inside the Docker image +COPY . . + +ARG REACT_APP_API_GATEWAY_URL +ENV REACT_APP_API_GATEWAY_URL=$REACT_APP_API_GATEWAY_URL + +# Make port 3000 available to the world outside this container +EXPOSE 3000 + +# Define the command to run your app +CMD ["npm", "start"] \ No newline at end of file From 84fb26c70b3227910c9d753f8a70fe7726f36eca Mon Sep 17 00:00:00 2001 From: iynixil Date: Mon, 11 Nov 2024 21:59:16 +0800 Subject: [PATCH 2/3] Update README.md to include docker-compose instructions and info about production deployment --- README.md | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/README.md b/README.md index bb00edd1b0..1985e724f4 100644 --- a/README.md +++ b/README.md @@ -6,3 +6,16 @@ - 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. - The teaching team should be given access to the repositories as we may require viewing the history of the repository in case of any disputes or disagreements. + +### Run PeerPrep with docker-compose: +Prerequisite: Ensure that Docker is installed and running. +1. Clone the repository. +2. Ensure that the respective `.env` files for all microservices, and the frontend, have been added in. +3. In any IDE or terminal, `cd` to the project root directory, and run the following commands: + - `docker-compose build --no-cache` to build the images + - `docker-compose up -d` to run the web app on `localhost:3000` + - `docker-compose down` to stop running the containers + +### Production Deployment of PeerPrep +- The production build and deployment of PeerPrep is located under the `deployment` branch. +- Deployment link: http://g46-peerprep-env.eba-u9cm3q7g.ap-southeast-1.elasticbeanstalk.com/ \ No newline at end of file From 77411e341b9df57ea164abe3112bb6457c0aeefc Mon Sep 17 00:00:00 2001 From: iynixil Date: Wed, 13 Nov 2024 16:15:52 +0800 Subject: [PATCH 3/3] Remove unnecessary lines in frontend Dockerfile --- frontend/Dockerfile | 3 --- 1 file changed, 3 deletions(-) diff --git a/frontend/Dockerfile b/frontend/Dockerfile index 9108f34960..f2952f8894 100644 --- a/frontend/Dockerfile +++ b/frontend/Dockerfile @@ -13,9 +13,6 @@ RUN npm install # Bundle app source inside the Docker image COPY . . -ARG REACT_APP_API_GATEWAY_URL -ENV REACT_APP_API_GATEWAY_URL=$REACT_APP_API_GATEWAY_URL - # Make port 3000 available to the world outside this container EXPOSE 3000