Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[feat]: dockerized the backend services #53

Merged
merged 1 commit into from
Oct 31, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 10 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -153,10 +153,10 @@ _![OpenAPI Swagger Schemas](./idea/high/swaggerschema.png)_

The codebase is organized as :

1. _ts-frontend_ - The react frontend
2. _backend/ts-backend_ - The primary express backend with mongoDB
3. _backend/loc_ - The secondary express backend with Postgres
4. _backend/ws_ - The websocket backend
1. _ts-frontend_ - The react frontend (_default port 5173_)
2. _backend/ts-backend_ - The primary express backend with mongoDB (_default port 5050_)
3. _backend/loc_ - The secondary express backend with Postgres (_default port 6060_)
4. _backend/ws_ - The websocket backend (_default port 8080_)

- Clone the PrivacyNetwork repository

Expand Down Expand Up @@ -218,6 +218,12 @@ backend/loc/src/mockdata
└── User.sql
```

- Run with docker (_start all services with a single command_)

```bash
docker compose up
```

- Run the frontend

```bash
Expand Down
2 changes: 2 additions & 0 deletions backend/loc/.dockerignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
node_modules
dist
20 changes: 20 additions & 0 deletions backend/loc/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
FROM node:20.18.0

RUN useradd -ms /bin/bash loc
# /home/loc \

WORKDIR /home/loc

COPY package*.json /home/loc/

RUN npm install

COPY . .

RUN npx prisma generate

USER loc

EXPOSE 6060

CMD [ "npm", "run", "dev" ]
2 changes: 2 additions & 0 deletions backend/ts-backend/.dockerignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
node_modules
dist
2 changes: 1 addition & 1 deletion backend/ts-backend/.env.example
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,5 @@ GOOGLE_API_KEY=<GOOGLE_API_KEY: for logging in with Google>
MONGO_URI=<MONGO_URI: for mongoDB database connection>
SECRET_KEY=<CLIENT_SECRET: for generating/verifying the JWT token>
PORT=<PORT: at which the ts-backend server runs>
LOCATION_BACKEND_URI=<LOCATION_BACKEND_URI: for location querying req to loc server>
LOCATION_BACKEND_URI=<LOCATION_BACKEND_URI: for location querying req to loc server> [loc:6060 or localhost:6060]
BACKEND_INTERCOMMUNICATION_SECRET=<BACKEND_INTERCOMMUNICATION_SECRET: for backend intercommunication>
18 changes: 18 additions & 0 deletions backend/ts-backend/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
FROM node:20.18.0

RUN useradd -ms /bin/bash ts-backend
# /home/ts-backend \

WORKDIR /home/ts-backend

COPY package*.json /home/ts-backend/

RUN npm install

COPY . .

USER ts-backend

EXPOSE 5050

CMD [ "npm", "run", "dev" ]
2 changes: 2 additions & 0 deletions backend/ws/.dockerignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
node_modules
dist
18 changes: 18 additions & 0 deletions backend/ws/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
FROM node:20.18.0

RUN useradd -ms /bin/bash ws
# /home/ws \

WORKDIR /home/ws

COPY package*.json /home/ws/

RUN npm install

COPY . .

USER ws

EXPOSE 8080

CMD [ "sh", "-c", "npm run build && npm start" ]
51 changes: 51 additions & 0 deletions docker-compose.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
version: '3.8'

services:
ts-backend:
build:
context: ./backend/ts-backend
dockerfile: Dockerfile
ports:
- '5050:5050'
volumes:
- ./backend/ts-backend:/app
environment:
env_file: './backend/ts-backend.env'
container_name: tracebook_ts-backend
networks:
- tracebook
depends_on:
- loc
- ws

loc:
build:
context: ./backend/loc
dockerfile: Dockerfile
ports:
- '6060:6060'
volumes:
- ./backend/loc:/app
environment:
env_file: './backend/loc.env'
container_name: tracebook_loc
networks:
- tracebook

ws:
build:
context: ./backend/ws
dockerfile: Dockerfile
ports:
- '8080:8080'
volumes:
- ./backend/ws:/app
environment:
env_file: './backend/ws.env'
container_name: tracebook_ws
networks:
- tracebook

networks:
tracebook:
driver: bridge
Loading