From db66ee556163a39e25e54e2e776de47ae7b6e14c Mon Sep 17 00:00:00 2001 From: Brendan Tan Date: Thu, 3 Oct 2024 17:10:39 +0800 Subject: [PATCH 1/3] Add Docker files --- .gitignore | 3 +-- docker-compose.yml | 16 ++++++++++++++++ frontend/.gitignore | 2 +- frontend/Dockerfile.dev | 13 +++++++++++++ 4 files changed, 31 insertions(+), 3 deletions(-) create mode 100644 docker-compose.yml create mode 100644 frontend/Dockerfile.dev diff --git a/.gitignore b/.gitignore index 6638279561..46ccfe3c20 100644 --- a/.gitignore +++ b/.gitignore @@ -1,3 +1,2 @@ node_modules/ -docker-compose* -Dockerfile* +docker-compose.prod* diff --git a/docker-compose.yml b/docker-compose.yml new file mode 100644 index 0000000000..c5e221dbaf --- /dev/null +++ b/docker-compose.yml @@ -0,0 +1,16 @@ +# docker-compose for dev + +services: + frontend: + build: + context: ./frontend + dockerfile: Dockerfile.dev + # depends_on: + # - + ports: + - "3000:3000" + develop: + watch: + - action: sync + path: ./frontend + target: /app diff --git a/frontend/.gitignore b/frontend/.gitignore index ef5108c31d..9fc5ae20ee 100644 --- a/frontend/.gitignore +++ b/frontend/.gitignore @@ -35,4 +35,4 @@ yarn-error.log* *.tsbuildinfo next-env.d.ts -Dockerfile* \ No newline at end of file +Dockerfile.prod \ No newline at end of file diff --git a/frontend/Dockerfile.dev b/frontend/Dockerfile.dev new file mode 100644 index 0000000000..9ca431a6ac --- /dev/null +++ b/frontend/Dockerfile.dev @@ -0,0 +1,13 @@ +FROM node:22-alpine3.19 AS builder +WORKDIR /app + +COPY package.json package-lock.json ./ +RUN npm ci +COPY . . + +ENV HOSTNAME="0.0.0.0" +ENV PORT=3000 + +EXPOSE 3000 + +CMD ["npm", "run", "dev"] \ No newline at end of file From d3a2d3098c3f3172ff7d928ecfb8d382d8d28f03 Mon Sep 17 00:00:00 2001 From: Brendan Tan Date: Thu, 3 Oct 2024 17:15:04 +0800 Subject: [PATCH 2/3] Add Docker files for question service --- backend/question-service/Dockerfile.dev | 13 +++++++++++++ docker-compose.yml | 14 ++++++++++++++ 2 files changed, 27 insertions(+) create mode 100644 backend/question-service/Dockerfile.dev diff --git a/backend/question-service/Dockerfile.dev b/backend/question-service/Dockerfile.dev new file mode 100644 index 0000000000..99030b06a7 --- /dev/null +++ b/backend/question-service/Dockerfile.dev @@ -0,0 +1,13 @@ +FROM node:22-alpine3.19 AS builder +WORKDIR /app + +COPY package.json package-lock.json ./ +RUN npm ci +COPY . . + +ENV HOSTNAME="0.0.0.0" +ENV PORT=2000 + +EXPOSE 2000 + +CMD ["npm", "run", "dev"] \ No newline at end of file diff --git a/docker-compose.yml b/docker-compose.yml index c5e221dbaf..517668c059 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -14,3 +14,17 @@ services: - action: sync path: ./frontend target: /app + + question: + build: + context: ./backend/question-service + dockerfile: Dockerfile.dev + # depends_on: + # - + ports: + - "2000:2000" + develop: + watch: + - action: sync + path: ./backend/question-service + target: /app From ffe860c5fe890f8acf2467759ef49a80471d6ec9 Mon Sep 17 00:00:00 2001 From: Brendan Tan Date: Thu, 3 Oct 2024 17:44:48 +0800 Subject: [PATCH 3/3] Update README --- README.md | 15 ++++++++++----- frontend/README.md | 8 +++++--- 2 files changed, 15 insertions(+), 8 deletions(-) diff --git a/README.md b/README.md index 2a0d8f899a..a45f311e2a 100644 --- a/README.md +++ b/README.md @@ -15,15 +15,20 @@ The question microservice exposes the following API endpoints: - ```questions/patch/[Question ID]``` - Patches a question from the database by ID number. ### Running PeerPrep -In the root directory, ```backend/question-service```, and ```frontend``` folders, run +In the root directory, run ```sh -npm install +docker compose up -d ``` -Then, in the project root, run +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 -npm run start +docker compose up --watch --build ``` -and access PeerPrep at [localhost:3000](http://localhost:3000) ### Note: - You can choose to develop individual microservices within separate folders within this repository **OR** use individual repositories (all public) for each microservice. diff --git a/frontend/README.md b/frontend/README.md index 131dce2e40..02e4930bd0 100644 --- a/frontend/README.md +++ b/frontend/README.md @@ -2,7 +2,11 @@ This is a [Next.js](https://nextjs.org) project bootstrapped with [`create-next- ## Getting Started -Run the development server: +The preferred way is to use Docker Compose from the PeerPrep root directory: +```sh +docker compose up --watch --build +``` +Otherwise, run the development server: ```bash npm run dev @@ -10,8 +14,6 @@ npm run dev Open [http://localhost:3000](http://localhost:3000) with your browser to see the result. -You can start editing the page by modifying `app/page.tsx`. The page auto-updates as you edit the file. - ## Stack - [React](https://react.dev)