diff --git a/.gitignore b/.gitignore index 0f5d43b..d0435b0 100644 --- a/.gitignore +++ b/.gitignore @@ -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 @@ -11,3 +12,5 @@ dump bk backend/dist docker/db +docker/backend +docker/frontend diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index 2edb66d..a36da49 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -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 ``` diff --git a/backend/.dockerignore b/backend/.dockerignore new file mode 100644 index 0000000..b512c09 --- /dev/null +++ b/backend/.dockerignore @@ -0,0 +1 @@ +node_modules \ No newline at end of file diff --git a/backend/Dockerfile b/backend/Dockerfile new file mode 100644 index 0000000..464e21c --- /dev/null +++ b/backend/Dockerfile @@ -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"] diff --git a/db/dockerfile b/db/dockerfile new file mode 100644 index 0000000..560954d --- /dev/null +++ b/db/dockerfile @@ -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 diff --git a/docker/compose.yml b/docker/compose.yml index 537bd98..dd0f494 100644 --- a/docker/compose.yml +++ b/docker/compose.yml @@ -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" diff --git a/docker/dockerfile b/docker/dockerfile index b6cd496..6117907 100644 --- a/docker/dockerfile +++ b/docker/dockerfile @@ -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" ] \ No newline at end of file diff --git a/frontend/.dockerignore b/frontend/.dockerignore new file mode 100644 index 0000000..b512c09 --- /dev/null +++ b/frontend/.dockerignore @@ -0,0 +1 @@ +node_modules \ No newline at end of file diff --git a/frontend/Dockerfile b/frontend/Dockerfile new file mode 100644 index 0000000..703428c --- /dev/null +++ b/frontend/Dockerfile @@ -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" ] diff --git a/makefile b/makefile index 930bae1..9bee421 100644 --- a/makefile +++ b/makefile @@ -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: @@ -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