-
-
Notifications
You must be signed in to change notification settings - Fork 11
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
#253 [Devops] Setup mongo and add telegram db Fail.
- Loading branch information
Showing
28 changed files
with
626 additions
and
27 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
FROM mongo | ||
|
||
# copy javascript | ||
COPY /mongo/init-mongo.js /docker-entrypoint-initdb.d/ | ||
|
||
# Public port 0 0 0 0 | ||
CMD ["mongod", "--bind_ip_all"] | ||
|
||
|
||
|
||
|
||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
const db = db.getSiblingDB('library_school_service'); | ||
const user = db.getUser('docker'); | ||
if (!db && !user) { | ||
db.createUser({ | ||
user: 'docker', | ||
pwd: 'docker', | ||
roles: [{ role: 'readWrite', db: 'library_school_service' }], | ||
}); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
27 changes: 27 additions & 0 deletions
27
backend-manager-student/src/share/configs/configs.mongodb.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
//! CONFIG | ||
const CONFIGS = require('./config'); | ||
|
||
const DEVELOPER = { | ||
db: { | ||
host: CONFIGS.MONGO_INIT_MONGO_HOST, | ||
port: CONFIGS.MONGO_INIT_MONGO_PORT, | ||
db: CONFIGS.MONGO_INIT_DB_DATABASE, | ||
user: CONFIGS.MONGO_INIT_DB_ROOT_USERNAME, | ||
password: CONFIGS.MONGO_INI_TDB_ROOT_PASSWORD, | ||
source: CONFIGS.MONGO_INIT_DB_SOURCE, | ||
}, | ||
}; | ||
const PRODUCTION = { | ||
db: { | ||
host: CONFIGS.MONGO_INIT_MONGO_HOST, | ||
port: CONFIGS.MONGO_INIT_MONGO_PORT, | ||
db: CONFIGS.MONGO_INIT_DB_DATABASE, | ||
user: CONFIGS.MONGO_INIT_DB_ROOT_USERNAME, | ||
password: CONFIGS.MONGO_INI_TDB_ROOT_PASSWORD, | ||
source: CONFIGS.MONGO_INIT_DB_SOURCE, | ||
}, | ||
}; | ||
const config = { DEVELOPER, PRODUCTION }; | ||
const env = process.env.NODE_ENV || 'DEVELOPER'; | ||
|
||
module.exports = config[env]; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,67 @@ | ||
//! LIBRARY | ||
const mongoose = require('mongoose'); | ||
|
||
//! CONFIGS | ||
const CONSTANTS = require('../configs/constants'); | ||
const HELPERS = require('../utils/helper'); | ||
const { db: { host, port, db, user, password, source } } = require('../configs/configs.mongodb'); | ||
|
||
//! PUBSUB | ||
const { handleException } = require('../utils/redis_pub_sub_helper'); | ||
|
||
/** | ||
* @author Nguyễn Tiến Tài | ||
* @created_at 10/04/2023 | ||
* @description setup nosql MongoDb | ||
*/ | ||
|
||
const connectString = HELPERS.getURIFromTemplate(CONSTANTS.MONGO.STRING_CONNECT, { | ||
user, | ||
password, | ||
host, | ||
port, | ||
db, | ||
source, | ||
}); | ||
|
||
// Singleton | ||
class Database { | ||
constructor() { | ||
this.connect(); | ||
} | ||
|
||
// Connect | ||
// eslint-disable-next-line class-methods-use-this | ||
connect() { | ||
//! DEVELOPERS | ||
// eslint-disable-next-line no-constant-condition, no-self-compare | ||
if (1 === 1) { | ||
mongoose.set('debug', CONSTANTS.DELETED_ENABLE); | ||
mongoose.set('debug', { color: CONSTANTS.DELETED_ENABLE }); | ||
} | ||
|
||
mongoose.connect(connectString, { | ||
maxPoolSize: CONSTANTS.MONGO.POOL_SIZE, | ||
useNewUrlParser: CONSTANTS.DELETED_ENABLE, | ||
useUnifiedTopology: CONSTANTS.DELETED_ENABLE, | ||
// eslint-disable-next-line no-unused-vars | ||
}).then((_) => { | ||
console.info('CONNECTED TO MONGODB SUCCESS !!'); | ||
}).catch((err) => { | ||
handleException(err, CONSTANTS.NAME_SERVER.DB, CONSTANTS.NAME_DATABASE.MONGO); | ||
console.error(err); | ||
}); | ||
} | ||
|
||
static getInstance() { | ||
if (!Database.instance) { | ||
Database.instance = new Database(); | ||
} | ||
|
||
return Database.instance; | ||
} | ||
} | ||
|
||
const instanceMongoDb = Database.getInstance(); | ||
|
||
module.exports = instanceMongoDb; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.