Skip to content

Commit

Permalink
Init db on start up
Browse files Browse the repository at this point in the history
  • Loading branch information
koechkevin committed Jan 22, 2024
1 parent f7e2bbc commit 55ae04e
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 35 deletions.
5 changes: 2 additions & 3 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
# Makefile

.PHONY: charterafrica init-db
.PHONY: charterafrica

charterafrica:
docker-compose --env-file apps/charterafrica/.env.local up charterafrica --build
docker-compose --env-file apps/charterafrica/.env.local up charterafrica --build -d

init-db:
docker-compose up mongodb_container --build -d
docker exec mongodb_container /scripts/db-init.sh
20 changes: 20 additions & 0 deletions data_container/scripts/db-init.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
const config = {
_id: "dbrs",
version: 1,
members: [
{
_id: 1,
host: "mongodb_container:27017",
priority: 1,
},
],
};
console.log("==================>");
rs.initiate(config, { force: true });

rs.status();
db.createUser({
user: "root",
pwd: "rootpassword",
roles: [{ role: "root", db: "admin" }],
});
2 changes: 1 addition & 1 deletion docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ services:
volumes:
- data_container:/data/db
- ./mongo-keyfile:/etc/mongo-keyfile
- ./scripts/db-init.sh:/scripts/db-init.sh
- ./data_container/scripts/db-init.js:/docker-entrypoint-initdb.d/db-init.js
restart: always
healthcheck:
test: echo 'db.runCommand("ping").ok' | mongosh mongodb_container:27017/charterafrica --quiet
Expand Down
31 changes: 0 additions & 31 deletions scripts/db-init.sh

This file was deleted.

0 comments on commit 55ae04e

Please sign in to comment.