Skip to content

Commit 3a40520

Browse files
committed
Update Docker configuration to enable MongoDB binding on all interfaces and add initialization script for user creation in the database.
1 parent a907fed commit 3a40520

2 files changed

Lines changed: 19 additions & 1 deletion

File tree

docker-compose.yaml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ services:
1414
image: mongo:8.0
1515
command:
1616
- "--auth"
17-
- "--bind_ip=127.0.0.1,::1"
17+
- "--bind_ip_all"
1818
- "--setParameter=enableLocalhostAuthBypass=false"
1919
restart: always
2020
container_name: telegram_rp_bot_mongo
@@ -28,6 +28,7 @@ services:
2828
APP_PASS: ${APP_PASS}
2929
volumes:
3030
- mongo_data:/data/db
31+
- ./init/01-init-app-user.js:/docker-entrypoint-initdb.d/01-init-app-user.js:ro
3132
networks:
3233
- internal
3334

init/01-init-app-user.js

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
const APP_DB = _getenv("APP_DB") || "botdb";
2+
const APP_USER = _getenv("APP_USER") || "botuser";
3+
const APP_PASS = _getenv("APP_PASS") || "change_me";
4+
5+
const dbh = db.getSiblingDB(APP_DB);
6+
const existing = dbh.getUser(APP_USER);
7+
8+
if (!existing) {
9+
dbh.createUser({
10+
user: APP_USER,
11+
pwd: APP_PASS,
12+
roles: [ { role: "readWrite", db: APP_DB } ]
13+
});
14+
} else {
15+
// Optional: rotate password automatically if APP_PASS changes
16+
// dbh.updateUser(APP_USER, { pwd: APP_PASS });
17+
}

0 commit comments

Comments
 (0)