diff --git a/Makefile b/Makefile index ff758f6a5..76511e3d4 100644 --- a/Makefile +++ b/Makefile @@ -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 diff --git a/data_container/scripts/db-init.js b/data_container/scripts/db-init.js new file mode 100755 index 000000000..fead4547c --- /dev/null +++ b/data_container/scripts/db-init.js @@ -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" }], +}); diff --git a/docker-compose.yml b/docker-compose.yml index 0fe185312..9a410cb47 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -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 diff --git a/scripts/db-init.sh b/scripts/db-init.sh deleted file mode 100755 index f31f1b0a7..000000000 --- a/scripts/db-init.sh +++ /dev/null @@ -1,31 +0,0 @@ -#!/bin/bash - -DELAY=5 - -mongosh -u root -p rootpassword --authenticationDatabase admin <