From aac7080f7fac8bb7b44bb2e11316e904658ab2f2 Mon Sep 17 00:00:00 2001 From: Adolfo Reyna Date: Fri, 18 Oct 2024 11:59:15 -0400 Subject: [PATCH] Adding docker support --- .dockerignore | 5 +++++ .gitignore | 4 ++++ Dockerfile | 6 ++++-- docker-compose.yml | 38 ++++++++++++++++++++++++++++++++++++++ package.json | 5 ++++- 5 files changed, 55 insertions(+), 3 deletions(-) create mode 100644 .dockerignore create mode 100644 docker-compose.yml diff --git a/.dockerignore b/.dockerignore new file mode 100644 index 0000000..69f9963 --- /dev/null +++ b/.dockerignore @@ -0,0 +1,5 @@ +.git +.gitignore +node_modules +logs +dump \ No newline at end of file diff --git a/.gitignore b/.gitignore index 2f11a24..7e418d2 100644 --- a/.gitignore +++ b/.gitignore @@ -6,6 +6,10 @@ yarn-debug.log* yarn-error.log* lerna-debug.log* +# Dumps +dump + + # Diagnostic reports (https://nodejs.org/api/report.html) report.[0-9]*.[0-9]*.[0-9]*.[0-9]*.json diff --git a/Dockerfile b/Dockerfile index 32a9d46..66e098d 100644 --- a/Dockerfile +++ b/Dockerfile @@ -8,10 +8,12 @@ RUN apk add --no-cache python3 make g++ WORKDIR /app # Copy package.json and package-lock.json to the working directory -COPY package*.json ./ +COPY ["package.json", "package-lock.json", "./"] # Install dependencies RUN npm install +RUN npm rebuild bcrypt +RUN npm install nodemon -g # Copy the rest of the application source code COPY . . @@ -20,7 +22,7 @@ COPY . . EXPOSE 3001 # Command to run your app -CMD ["npm", "start"] +CMD ["nodemon"] # sudo docker build -t emi-backend . # sudo docker run -d -p 4000:5000 -e PORT=5000 emi-backend \ No newline at end of file diff --git a/docker-compose.yml b/docker-compose.yml new file mode 100644 index 0000000..ad19232 --- /dev/null +++ b/docker-compose.yml @@ -0,0 +1,38 @@ +version: '3.8' + +networks: + emi-network: + driver: bridge + +services: + app: + build: + context: . + ports: + - '3001:3001' + environment: + - MONGO_URL=mongodb://mongo:27017/testdb + - PORT=3001 + volumes: + - .:/app + - '/app/node_modules' + depends_on: + - mongo + command: nodemon + networks: + - emi-network + + mongo: + image: mongo:latest + ports: + - '27017:27017' + networks: + - emi-network + volumes: + - mongodbdata:/data/db + - ./dump:/dump + #entrypoint: mongodump ${MONGO_URL} && mongorestore --db EMI_SOCIAL dump/EMI_SOCIAL/ && mongod + +volumes: + mongodbdata: + driver: local # This ensures the volume is created \ No newline at end of file diff --git a/package.json b/package.json index ee18aa4..d5a22d5 100644 --- a/package.json +++ b/package.json @@ -5,7 +5,10 @@ "main": "index.js", "scripts": { "test": "echo \"Error: no test specified\" && exit 1", - "start": "node index.js" + "start": "node index.js", + "docker": "docker compose up -d", + "docker_restore": "docker-compose exec mongo mongorestore --db EMI_SOCIAL /dump/EMI_SOCIAL/", + "docker_dump": "docker-compose exec mongo mongodump --uri ${MONGO_URL} --out /dump" }, "author": "", "license": "ISC",