From 9ce98b6beef25e56f641d082c27c1d5792b0ac65 Mon Sep 17 00:00:00 2001 From: alireza Date: Tue, 7 Nov 2023 20:44:21 +0330 Subject: [PATCH] feat: add docker compose file --- api/db.js | 2 +- api/index.js | 3 ++- docker-compose.yml | 42 ++++++++++++++++++++++++++++++++++++++++++ ecosystem.config.js | 11 +++++++++++ package-lock.json | 16 +++++++++++++--- package.json | 1 + 6 files changed, 70 insertions(+), 5 deletions(-) create mode 100644 docker-compose.yml create mode 100644 ecosystem.config.js diff --git a/api/db.js b/api/db.js index da84f8f..5b1a43f 100644 --- a/api/db.js +++ b/api/db.js @@ -1,6 +1,6 @@ const mongoose = require('mongoose'); // mongodb database connection string. change it as per your needs. here "mydb" is the name of the database. You don't need to create DB from mongodb terminal. mongoose create the db automatically. -mongoose.connect('mongodb://localhost:27017/arakrail', { +mongoose.connect(`mongodb://${process.env.MONGO_HOST}:27017/arakrail`, { useNewUrlParser: true, useUnifiedTopology: true, useFindAndModify: false, diff --git a/api/index.js b/api/index.js index fa55496..b6105c1 100644 --- a/api/index.js +++ b/api/index.js @@ -2,7 +2,7 @@ const express = require('express') const db = require('./db') const fileUpload = require('express-fileupload') const config = require('./config') - +require('dotenv').config({path: __dirname+'/.env'}) // Create express instnace const app = express() @@ -11,6 +11,7 @@ app.use(express.json()) app.use(express.urlencoded({extended: true})) app.use(fileUpload()) + // Require & Import API routes const Private = require('./routes/private') const Public = require('./routes/public') diff --git a/docker-compose.yml b/docker-compose.yml new file mode 100644 index 0000000..94582f4 --- /dev/null +++ b/docker-compose.yml @@ -0,0 +1,42 @@ +version: "3.9" + +services: + app: + image: node:14-alpine + working_dir: /app + command: sh -c "npm i && npm rebuild node-sass && npm run build && npm run start" + volumes: + - .:/app + ports: + - "${PORT}:${PORT}" + depends_on: + - mongo + restart: on-failure + + mongo: + image: mongo:4.4.25 + restart: always + ports: + - "27017:27017" + volumes: + - arakrail-data:/etc/mongo + environment: + MONGO_INITDB_ROOT_USERNAME: ${MONGO_USER} + MONGO_INITDB_ROOT_PASSWORD: ${MONGO_PASS} + +# mongo-express: +# image: mongo-express +# restart: always +# ports: +# - "8081:8081" +# environment: +# ME_CONFIG_BASICAUTH_USERNAME: ${MONGO_PANEL_USER} +# ME_CONFIG_BASICAUTH_PASSWORD: ${MONGO_PANEL_PASS} +# ME_CONFIG_MONGODB_ADMINUSERNAME: ${MONGO_USER} +# ME_CONFIG_MONGODB_ADMINPASSWORD: ${MONGO_PASS} +# ME_CONFIG_MONGODB_URL: "mongodb://${MONGO_PANEL_USER}:${MONGO_PANEL_PASS}@mongo:27017/" +# depends_on: +# - mongo + +volumes: + arakrail-data: \ No newline at end of file diff --git a/ecosystem.config.js b/ecosystem.config.js new file mode 100644 index 0000000..b54e398 --- /dev/null +++ b/ecosystem.config.js @@ -0,0 +1,11 @@ +module.exports = { + apps: [ + { + name: 'arakrail', + exec_mode: 'cluster', + instances: 'max', // Or a number of instances + script: './node_modules/nuxt/bin/nuxt.js', + args: 'start' + } + ] +} \ No newline at end of file diff --git a/package-lock.json b/package-lock.json index 279f25b..58a0d74 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1523,6 +1523,11 @@ "version": "2.0.4", "resolved": "https://registry.npmjs.org/defu/-/defu-2.0.4.tgz", "integrity": "sha512-G9pEH1UUMxShy6syWk01VQSRVs3CDWtlxtZu7A+NyqjxaCA4gSlWAKDBx6QiUEKezqS8+DUlXLI14Fp05Hmpwg==" + }, + "dotenv": { + "version": "8.6.0", + "resolved": "https://registry.npmjs.org/dotenv/-/dotenv-8.6.0.tgz", + "integrity": "sha512-IrPdXQsk2BbzvCBGBOTmmSH5SodmqZNt4ERAZDmW4CT+tL8VtvinqywuANaFu4bOMWki16nqf0e4oC0QIaDr/g==" } } }, @@ -1740,6 +1745,11 @@ "version": "2.0.4", "resolved": "https://registry.npmjs.org/defu/-/defu-2.0.4.tgz", "integrity": "sha512-G9pEH1UUMxShy6syWk01VQSRVs3CDWtlxtZu7A+NyqjxaCA4gSlWAKDBx6QiUEKezqS8+DUlXLI14Fp05Hmpwg==" + }, + "dotenv": { + "version": "8.6.0", + "resolved": "https://registry.npmjs.org/dotenv/-/dotenv-8.6.0.tgz", + "integrity": "sha512-IrPdXQsk2BbzvCBGBOTmmSH5SodmqZNt4ERAZDmW4CT+tL8VtvinqywuANaFu4bOMWki16nqf0e4oC0QIaDr/g==" } } }, @@ -4699,9 +4709,9 @@ } }, "dotenv": { - "version": "8.2.0", - "resolved": "https://registry.npmjs.org/dotenv/-/dotenv-8.2.0.tgz", - "integrity": "sha512-8sJ78ElpbDJBHNeBzUbUVLsqKdccaa/BXF1uPTw3GrvQTBgrQrtObr2mUrE38vzYd8cEv+m/JBfDLioYcfXoaw==" + "version": "16.3.1", + "resolved": "https://registry.npmjs.org/dotenv/-/dotenv-16.3.1.tgz", + "integrity": "sha512-IPzF4w4/Rd94bA9imS68tZBaYyBWSCE47V1RGuMrB94iyTOIEwRmVL2x/4An+6mETpLrKJ5hQkB8W4kFAadeIQ==" }, "duplexer": { "version": "0.1.2", diff --git a/package.json b/package.json index c818004..f2a6f19 100644 --- a/package.json +++ b/package.json @@ -18,6 +18,7 @@ "ckeditor4-vue": "^1.2.0", "core-js": "^3.6.5", "dateformat": "^4.0.0", + "dotenv": "^16.3.1", "element-ui": "^2.13.2", "express": "^4.17.1", "express-fileupload": "^1.2.0",