Merge pull request #2143 from bluewave-labs/fix/prod-docker
Fix/prod docker
This commit is contained in:
2 files changed
+38
-27
No files matched your search
@@ -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" }],
|
});
|
||||||
});
|
} catch (e) {
|
||||||
break;
|
print("Replica set already initiated or error occurred: " + e);
|
||||||
} catch (e) {
|
|
||||||
print("Replica set initiation failed, retrying in 2s...");
|
|
||||||
sleep(2000);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
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();
|
waitForPrimary();
|
||||||
|
createUser();
|
||||||
// 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");
|
|
||||||
@@ -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(
|
||||||
|
|||||||
Reference in new issue
Block a user