Skip to content

Commit

Permalink
Merge pull request #34 from brendantwh/containerize
Browse files Browse the repository at this point in the history
Add Docker files
  • Loading branch information
JohnChia123 authored Oct 3, 2024
2 parents bc2fe60 + ffe860c commit f17f809
Show file tree
Hide file tree
Showing 7 changed files with 73 additions and 11 deletions.
3 changes: 1 addition & 2 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,2 @@
node_modules/
docker-compose*
Dockerfile*
docker-compose.prod*
15 changes: 10 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
13 changes: 13 additions & 0 deletions backend/question-service/Dockerfile.dev
Original file line number Diff line number Diff line change
@@ -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"]
30 changes: 30 additions & 0 deletions docker-compose.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
# 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

question:
build:
context: ./backend/question-service
dockerfile: Dockerfile.dev
# depends_on:
# -
ports:
- "2000:2000"
develop:
watch:
- action: sync
path: ./backend/question-service
target: /app
2 changes: 1 addition & 1 deletion frontend/.gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -35,4 +35,4 @@ yarn-error.log*
*.tsbuildinfo
next-env.d.ts

Dockerfile*
Dockerfile.prod
13 changes: 13 additions & 0 deletions frontend/Dockerfile.dev
Original file line number Diff line number Diff line change
@@ -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"]
8 changes: 5 additions & 3 deletions frontend/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,18 @@ 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
```

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)
Expand Down

0 comments on commit f17f809

Please sign in to comment.