remove previous code, dont share mongo data folders on runtype (rs and docker)

This commit is contained in:
negue
2025-11-27 22:24:18 +01:00
parent 30dc7e5d91
commit 3c519476ec
7 changed files with 5491 additions and 3169 deletions

2
.gitignore vendored
View File

@@ -47,5 +47,5 @@ webpack.webstorm.config
# mongodb replica set for local dev
mongodb-*.tgz
/mongodb-data*
/mongodb-*
/.nyc_output

View File

@@ -1,6 +1,5 @@
# big thanks to https://pakisan.github.io/posts/docker-compose-mongodb-single-node-replica-set/ <3
version: "3.9"
networks:
mongodb-network:
name: "mongodb-network"
@@ -16,7 +15,7 @@ services:
- "27017:27017"
restart: "unless-stopped"
volumes:
- "./mongodb-data:/data/db"
- "./mongodb-docker-data:/data/db"
entrypoint: [ "/usr/bin/mongod", "--bind_ip_all", "--replSet", "rs" ]
mongoinit:
image: "mongo:7.0"
@@ -28,10 +27,9 @@ services:
- mongodb-network
command: >
mongosh --host mongodb:27017 --eval "rs.initiate({
_id: \"rs\",
members: [
{_id: 0, host: \"mongodb\"}
]
})"
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); }'
"

View File

@@ -5,8 +5,8 @@ import path from 'path';
import babel from 'gulp-babel';
import os from 'os';
import fs from 'fs';
/* import spawn from 'cross-spawn'; // eslint-disable-line import/no-extraneous-dependencies
import clean from 'rimraf'; */
import spawn from 'cross-spawn';
import clean from 'rimraf';
gulp.task('build:babel:server', () => gulp.src('website/server/**/*.js')
.pipe(babel())
@@ -35,7 +35,7 @@ gulp.task('build:prod', gulp.series(
// When used on windows `run-rs` must first be run without the `--keep` option
// in order to be setup correctly, afterwards it can be used.
const MONGO_PATH = path.join(__dirname, '/../mongodb-data/');
const MONGO_PATH = path.join(__dirname, '/../mongodb-data-rs/');
gulp.task('build:prepare-mongo', async () => {
if (fs.existsSync(MONGO_PATH)) {
@@ -51,7 +51,7 @@ gulp.task('build:prepare-mongo', async () => {
console.log('MongoDB data folder is missing, setting up.'); // eslint-disable-line no-console
// use run-rs without --keep, kill it as soon as the replica set starts
/* const runRsProcess = spawn('node', ['../scripts/start-local-mongo.mjs --build-db']);
const runRsProcess = spawn('npm', ['run', 'mongo:dev:rs']);
for await (const chunk of runRsProcess.stdout) {
const stringChunk = chunk.toString();
@@ -79,8 +79,6 @@ gulp.task('build:prepare-mongo', async () => {
throw new Error(`Error running run-rs: ${error}`);
}
*/
});
gulp.task('build:dev', gulp.series(

887
package-lock.json generated

File diff suppressed because it is too large Load Diff

View File

@@ -105,11 +105,9 @@
"start": "node --watch ./website/server/index.js",
"start:simple": "node ./website/server/index.js",
"debug": "node --watch --inspect ./website/server/index.js",
"mongo:dev_old": "run-rs -v 7.0.23 -l ubuntu2214 --keep --dbpath mongodb-data --number 1 --quiet",
"mongo:test_old": "run-rs -v 7.0.23 -l ubuntu2214 --keep --dbpath mongodb-data-testing --number 1 --quiet",
"mongo:dev_": "node scripts/start-local-mongo.mjs",
"mongo:dev": "docker compose -f docker-compose.mongo-local.yml up",
"mongo:dev:down": "docker compose -f docker-compose.mongo-local.yml down",
"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": "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",
@@ -123,10 +121,10 @@
"chalk": "^5.3.0",
"cross-spawn": "^7.0.5",
"mocha": "^5.1.1",
"mongodb-memory-server": "^10.1.2",
"monk": "^7.3.4",
"nyc": "^15.1.0",
"require-again": "^2.0.0",
"run-rs": "^0.7.7",
"sinon-chai": "^3.7.0",
"sinon-stub-promise": "^4.0.0"
}

View File

@@ -1,54 +0,0 @@
/* eslint-disable-file */
import { MongoMemoryReplSet } from 'mongodb-memory-server';
import { dirname } from 'node:path';
import { existsSync, mkdirSync } from 'node:fs';
import { fileURLToPath } from 'node:url';
const TEST_MODE = process.argv.includes('--test-db');
const BUILD_MODE = process.argv.includes('--build-db');
const __dirname = dirname(fileURLToPath(import.meta.url));
const pathSuffix = TEST_MODE ? '-test' : BUILD_MODE ? '-build' : '';
const mongoDbPath = `${__dirname}/../mongodb-data`+pathSuffix;
if (!existsSync(mongoDbPath)) {
mkdirSync(mongoDbPath);
}
(async () => {
// async code in where
// This will create an new instance of "MongoMemoryServer" and automatically start it
const mongod = await MongoMemoryReplSet.create({
replSet: {
count: 3,
dbName: TEST_MODE ? 'habitica-test' : 'habitica-dev',
dbPath: mongoDbPath,
name: 'rs',
},
instanceOpts: [
{
port: 27017,
},
{
port: 27018,
},
{
port: 27019,
},
],
dispose: {
cleanup: !BUILD_MODE && !TEST_MODE,
}
});
const uri = mongod.getUri();
console.log(`MongoDB running at ${uri}`, mongod.state);
// Keep the Node.js process running
setInterval(() => {}, 1000);
})();

File diff suppressed because it is too large Load Diff