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
+38 -27

No files matched your search

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