Skip to content
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
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ db/bk
db/bson/user.bson
db/bson/user.metadata.json
db/init-prod.js
db/db
db/bson-for-azure
sample-app/node_modules
docker-compose.yml
Expand All @@ -11,3 +12,5 @@ dump
bk
backend/dist
docker/db
docker/backend
docker/frontend
4 changes: 2 additions & 2 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -53,10 +53,10 @@ With Version 2, this Open Source project is now open for contribution! You can h
test> use lotr
lotr>
```
- the database files are stored in `./docker/db/` - to restore from the original, stop the running containers, delete that directory, and bring the environment back up:
- the database files are stored in `./db/db/` - to restore from the original, stop the running containers, delete that directory, and bring the environment back up:
```
make down
sudo rm -rf ./docker/db
sudo rm -rf ./db/db
make up
```

Expand Down
1 change: 1 addition & 0 deletions backend/.dockerignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
node_modules
14 changes: 14 additions & 0 deletions backend/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
FROM node:21.2

WORKDIR /app

COPY package.json .

RUN npm install

# Copy the rest of the application code
COPY . .

EXPOSE 3001

CMD ["npm", "run", "dev"]
7 changes: 7 additions & 0 deletions db/dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
FROM mongo:7.0-jammy as lotr_mongo

COPY ./bson/* /db/data/init/

EXPOSE 27017

RUN echo "mongorestore -d lotr db/data/init" > /docker-entrypoint-initdb.d/init.sh
29 changes: 11 additions & 18 deletions docker/compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,38 +2,31 @@ name: lotr
services:
mongo:
build:
context: ..
dockerfile: docker/dockerfile
target: lotr_mongo
context: ../db
environment:
MONGO_INITDB_DATABASE: lotr
ports:
- 27017:27017
restart: on-failure
volumes:
- ./db:/data/db
- ${PWD}/../db:/data

backend:
# Using the debian version rather than alpine to support binary execution e.g. bcrypt
image: node:21.2
command: [ "npm", "run", "dev" ]
build: ../backend
depends_on:
- mongo
environment:
DATABASE_URL: "mongodb://mongo:27017/lotr"
ports:
- 3001:3001
volumes:
- ../backend:/app
working_dir: /app
- ${PWD}/../backend:/backend
ports:
- "3001:3001"

frontend:
image: node:21.2-alpine
command: [ "npm", "run", "start" ]
build: ../frontend
depends_on:
- backend
ports:
- 3000:3000
- mongo
volumes:
- ../frontend:/app
working_dir: /app
- ${PWD}/../frontend:/frontend
ports:
- "3000:3000"
14 changes: 1 addition & 13 deletions docker/dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -25,16 +25,4 @@ RUN getent passwd $USER_ID || adduser --disabled-password --gecos '' --uid $USER
# Set the active user and open the interactive terminal
USER user

ENTRYPOINT [ "bash" ]



################
### DATABASE ###
################

FROM mongo:7.0-jammy as lotr_mongo

COPY ./db/bson /data/init

RUN echo "mongorestore --archive='/data/init'" > /docker-entrypoint-initdb.d/init.sh
ENTRYPOINT [ "bash" ]
1 change: 1 addition & 0 deletions frontend/.dockerignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
node_modules
14 changes: 14 additions & 0 deletions frontend/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
FROM node:21.2-alpine

WORKDIR /app

COPY package.json .

RUN npm install

# Copy the rest of the application code
COPY . .

EXPOSE 3000

CMD [ "npm", "run", "start" ]
4 changes: 2 additions & 2 deletions makefile
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# build the command line interface and install node packages
build:
docker build --build-arg "USER_ID=$$(id -u)" --build-arg "GROUP_ID=$$(id -g)" -f ./docker/dockerfile --target lotr_cli -t lotr-cli:latest .
docker run -v ./backend:/app/backend -v ./frontend:/app/frontend --entrypoint /app/npm-build.sh -it --rm --name lotr-cli lotr-cli
docker run -v ${PWD}/backend:/app/backend -v ${PWD}/frontend:/app/frontend --entrypoint /app/npm-build.sh -it --rm --name lotr-cli lotr-cli

# start and stop the local environment
up:
Expand All @@ -11,4 +11,4 @@ down:

# run the command line interface to manage application dependencies and run tests
cli:
docker run -v ./backend:/app/backend -v ./frontend:/app/frontend -it --rm --name lotr-cli lotr-cli
docker run -v ${PWD}/backend:/app/backend -v ${PWD}/frontend:/app/frontend -it --rm --name lotr-cli lotr-cli