diff --git a/docker-compose.mongo-local.yml b/docker-compose.mongo-local.yml index 0f70fbcae6..e21e983e73 100644 --- a/docker-compose.mongo-local.yml +++ b/docker-compose.mongo-local.yml @@ -15,7 +15,7 @@ services: - "27017:27017" restart: "unless-stopped" volumes: - - "./mongodb-docker-data:/data/db" + - "./mongodb-data-docker:/data/db" entrypoint: [ "/usr/bin/mongod", "--bind_ip_all", "--replSet", "rs" ] mongoinit: image: "mongo:7.0" diff --git a/docker-compose.mongo-test-local.yml b/docker-compose.mongo-test-local.yml new file mode 100644 index 0000000000..3d916dcb72 --- /dev/null +++ b/docker-compose.mongo-test-local.yml @@ -0,0 +1,35 @@ +# big thanks to https://pakisan.github.io/posts/docker-compose-mongodb-single-node-replica-set/ <3 + +networks: + mongodb-network: + name: "mongodb-network" + driver: bridge +services: + mongodb: + image: "mongo:7.0" + container_name: "mongodb" + networks: + - mongodb-network + hostname: "mongodb" + ports: + - "27017:27017" + restart: "unless-stopped" + volumes: + - "./mongodb-data-docker-testing:/data/db" + entrypoint: [ "/usr/bin/mongod", "--bind_ip_all", "--replSet", "rs" ] + mongoinit: + image: "mongo:7.0" + container_name: "mongodb_replSet_initializer" + restart: "on-failure" # WITHOUT THIS, the initializer tries only once and fails + depends_on: + - mongodb + networks: + - mongodb-network + + command: > + bash -c " + until mongosh --host mongodb:27017 --eval 'db.adminCommand({ping:1})' >/dev/null 2>&1; do + sleep 1 + done + mongosh --host mongodb:27017 --eval 'try { rs.initiate({_id: \"rs\", members:[{_id:0, host: \"mongodb:27017\"}]}); } catch(e) { print(\"rs.initiate skipped or failed: \" + e); }' + " diff --git a/package.json b/package.json index 22c7b0ec2b..65d876ebab 100644 --- a/package.json +++ b/package.json @@ -108,6 +108,7 @@ "mongo:dev:rs": "run-rs -v 7.0.23 -l ubuntu2214 --keep --dbpath mongodb-data-rs --number 1 --quiet", "mongo:test:rs": "run-rs -v 7.0.23 -l ubuntu2214 --keep --dbpath mongodb-data-rs-testing --number 1 --quiet", "mongo:dev:docker": "docker compose -f docker-compose.mongo-local.yml up", + "mongo:test:docker": "docker compose -f docker-compose.mongo-test-local.yml up", "mongo:test": "node scripts/start-local-mongo.mjs --test-db", "postinstall": "git config --global url.\"https://\".insteadOf git:// && gulp build && cd website/client && npm install", "apidoc": "gulp apidoc",