Skip to content

Commit

Permalink
fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
Michael7371 committed Mar 27, 2024
1 parent 6d02416 commit a62d3dd
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 17 deletions.
26 changes: 23 additions & 3 deletions docker-compose-mongo.yml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
version: '3'

# include:
# - docker-compose.yml
include:
- docker-compose.yml

services:
mongo:
Expand Down Expand Up @@ -50,7 +50,7 @@ services:
- ./scripts/mongo/create_indexes.js:/create_indexes.js


kafka-connect:
connect:
image: kafka-connect:latest
build:
context: ./jpo-s3-deposit/mongo-connector
Expand Down Expand Up @@ -87,6 +87,26 @@ services:
CONNECT_ZOOKEEPER_CONNECT: "zookeeper:2181"
volumes:
- ./jpo-s3-deposit/mongo-connector/connect_start.sh:/scripts/connect_start.sh

console:
image: docker.redpanda.com/redpandadata/console:v2.3.8
restart: on-failure
entrypoint: /bin/sh
command: -c "echo \"$$CONSOLE_CONFIG_FILE\" > /tmp/config.yml; /app/console"
environment:
CONFIG_FILEPATH: /tmp/config.yml
CONSOLE_CONFIG_FILE: |
kafka:
brokers: ["${DOCKER_HOST_IP}:9092"]
connect:
enabled: true
clusters:
- name: mongo
url: http://connect:8083
ports:
- "8000:8080"
depends_on:
- connect

volumes:
mongo1_data:
Expand Down
33 changes: 19 additions & 14 deletions scripts/mongo/create_indexes.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
/*
This script is responsible for initializing the replica set, creating collections, adding indexes and TTLs
*/

console.log("Running create_indexes.js");

const ode_db = process.env.MONGO_DB_NAME;
Expand All @@ -14,6 +13,8 @@ const ttlInDays = process.env.MONGO_COLLECTION_TTL; // TTL in days
const expire_seconds = ttlInDays * 24 * 60 * 60;
const retry_milliseconds = 5000;

console.log("ODE DB Name: " + ode_db);

try {
console.log("Initializing replica set...");

Expand Down Expand Up @@ -85,28 +86,32 @@ try{
// creates another user
console.log("Creating ODE user...");
admin = db.getSiblingDB("admin");
admin.createUser(
{
user: ode_user,
pwd: ode_pass,
roles: [ { role: "readWrite", db: ode_db },
{ role: "readWrite", db: "admin" } ,

]
}
);
// Check if user already exists
var user = admin.getUser(ode_user);
if (user == null) {
admin.createUser(
{
user: ode_user,
pwd: ode_pass,
roles: [
{ role: "readWrite", db: ode_db },
{ role: "readWrite", db: "admin" }
]
}
);
} else {
console.log("User \"" + ode_user + "\" already exists.");
}

db.getSiblingDB(ode_db);
print("Connected to the MongoDB instance.");
} catch (error) {
print("Error connecting to the MongoDB instance: " + error);
}


// Wait for the collections to exist in mongo before trying to create indexes on them
let missing_collection_count;
const db = db.getSiblingDB(ode_db);
do {
print("");
try {
missing_collection_count = 0;
const collection_names = db.getCollectionNames();
Expand Down

0 comments on commit a62d3dd

Please sign in to comment.