Merge pull request #2143 from bluewave-labs/fix/prod-docker

Fix/prod docker
This commit is contained in:
Alexander Holliday authored and GitHub committed 2025-04-25 16:28:50 -07:00
commit e020f61a04
2 files changed
+26 -15

No files matched your search

+25 -15
View File
@@ -1,31 +1,41 @@
function waitForPrimary() { function initiateReplicaSet() {
while (true) {
try { try {
rs.initiate({ rs.initiate({
_id: "rs0", _id: "rs0",
members: [{ _id: 0, host: "localhost:27017" }], members: [{ _id: 0, host: "localhost:27017" }],
}); });
break;
} catch (e) { } catch (e) {
print("Replica set initiation failed, retrying in 2s..."); print("Replica set already initiated or error occurred: " + e);
sleep(2000);
}
} }
} }
waitForPrimary(); function waitForPrimary() {
while (true) {
const isMaster = db.isMaster();
if (isMaster.ismaster) {
print("This node is now PRIMARY.");
break;
}
print("Waiting to become PRIMARY...");
sleep(2000);
}
}
// Switch to uptime_db function createUser() {
db = db.getSiblingDB("uptime_db"); db = db.getSiblingDB("uptime_db");
// Create app user var username = process.env.USERNAME_ENV_VAR;
var username = _getEnv("USERNAME_ENV_VAR"); var password = process.env.PASSWORD_ENV_VAR;
var password = _getEnv("PASSWORD_ENV_VAR");
db.createUser({ db.createUser({
user: username, user: username,
pwd: password, pwd: password,
roles: [{ role: "readWrite", db: "uptime_db" }], roles: [{ role: "readWrite", db: "uptime_db" }],
}); });
print("User '" + username + "' created successfully"); print("User '" + username + "' created successfully");
}
initiateReplicaSet();
waitForPrimary();
createUser();
+1
View File
@@ -96,6 +96,7 @@ class MongoDB {
try { try {
const connectionString = const connectionString =
process.env.DB_CONNECTION_STRING || "mongodb://localhost:27017/uptime_db"; process.env.DB_CONNECTION_STRING || "mongodb://localhost:27017/uptime_db";
console.log("Connecting to MongoDB with connection string:", connectionString);
await mongoose.connect(connectionString); await mongoose.connect(connectionString);
// If there are no AppSettings, create one // If there are no AppSettings, create one
await AppSettings.findOneAndUpdate( await AppSettings.findOneAndUpdate(