Skip to content

Commit

Permalink
Merge pull request #64 from brendantwh/main
Browse files Browse the repository at this point in the history
Add env config to Docker setup
  • Loading branch information
brendantwh authored Nov 8, 2024
2 parents c39c9b9 + 0e793fb commit 2eced45
Show file tree
Hide file tree
Showing 5 changed files with 103 additions and 42 deletions.
10 changes: 10 additions & 0 deletions .env
Original file line number Diff line number Diff line change
@@ -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
45 changes: 29 additions & 16 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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.
Expand Down
18 changes: 13 additions & 5 deletions docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -19,7 +27,7 @@ services:
context: ./backend/question-service
dockerfile: Dockerfile.dev
ports:
- "2000:2000"
- "${QUESTION_API_PORT}:2000"
develop:
watch:
- action: sync
Expand All @@ -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
Expand Down Expand Up @@ -73,7 +81,7 @@ services:
environment:
KAFKA_BROKER: kafka:9092
ports:
- "3002:3002"
- "${MATCHING_API_PORT}:3002"
depends_on:
kafka:
condition: service_healthy
Expand All @@ -83,4 +91,4 @@ services:
context: ./backend/signaling-service
dockerfile: Dockerfile.dev
ports:
- "3003:3003"
- "${COLLAB_API_PORT}:3003"
42 changes: 21 additions & 21 deletions frontend/.env.local
Original file line number Diff line number Diff line change
@@ -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=[email protected]
NEXT_PUBLIC_EMAIL_PASS=peerprepg44
30 changes: 30 additions & 0 deletions frontend/Dockerfile.dev
Original file line number Diff line number Diff line change
@@ -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 . .
Expand Down

0 comments on commit 2eced45

Please sign in to comment.