Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion examples/mongodb/0.9/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,8 @@ MAINTAINER Debezium Community
COPY init-inventory.sh /usr/local/bin/
RUN chmod +x /usr/local/bin/init-inventory.sh

CMD ["mongod", "--replSet", "rs0", "--auth"]
COPY init-inventory-replicaset.sh /usr/local/bin/
RUN chmod +x /usr/local/bin/init-inventory-replicaset.sh

# CMD ["mongod", "--replSet", "rs0", "--auth"]
CMD ["mongod", "--replSet", "rs0"]

@gunnarmorling gunnarmorling Dec 11, 2018

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@jpechane, any idea how to make the "--auth" parameter optional, depending on how an env var passed when starting a container from that image? I could create a separate file of course but really hoped it can be avoided, so the example image can be use clustered and non-clustered. Thanks!

I.e. what I'm looking for is this:

if (USE_AUTH) {
     CMD ["mongod", "--replSet", "rs0", "--auth"]
}
else {
     CMD ["mongod", "--replSet", "rs0"]
}

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

How about introducing a script that will start the mongo and use it in CMD instruction? The script can then easily add/remove options as needed?

58 changes: 58 additions & 0 deletions examples/mongodb/0.9/init-inventory-replicaset.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
DEFAULT_MEMBER="`hostname`:27017"
MEMBERS=${1:-$DEFAULT_MEMBER}

i=0
members=`for member in $MEMBERS; do printf ",{ _id : %s host : \"%s\"}" $i, $member && let "i++"; done`
members=${members:1}
echo "Replica set members: $members"

mongo localhost:27017/inventory <<-EOF
rs.initiate({
_id: "rs0",
members: [ $members ]
});
EOF

primary=0
while [ $primary -lt 1 ]
do
primary=$(echo "rs.status()" | mongo localhost:27017/inventory | grep stateStr | grep PRIMARY | wc -l)
echo "Waiting for replica set to initiate"
sleep 1
done
echo "Replica set initiated and primary node elected"

sleep 3

echo "rs.status()" | mongo localhost:27017/inventory
mongo localhost:27017/inventory <<-EOF
use inventory;

db.products.insert([
{ _id : NumberLong("101"), name : 'scooter', description: 'Small 2-wheel scooter', weight : 3.14, quantity : NumberInt("3") },
{ _id : NumberLong("102"), name : 'car battery', description: '12V car battery', weight : 8.1, quantity : NumberInt("8") },
{ _id : NumberLong("103"), name : '12-pack drill bits', description: '12-pack of drill bits with sizes ranging from #40 to #3', weight : 0.8, quantity : NumberInt("18") },
{ _id : NumberLong("104"), name : 'hammer', description: "12oz carpenter's hammer", weight : 0.75, quantity : NumberInt("4") },
{ _id : NumberLong("105"), name : 'hammer', description: "14oz carpenter's hammer", weight : 0.875, quantity : NumberInt("5") },
{ _id : NumberLong("106"), name : 'hammer', description: "16oz carpenter's hammer", weight : 1.0, quantity : NumberInt("0") },
{ _id : NumberLong("107"), name : 'rocks', description: 'box of assorted rocks', weight : 5.3, quantity : NumberInt("44") },
{ _id : NumberLong("108"), name : 'jacket', description: 'water resistent black wind breaker', weight : 0.1, quantity : NumberInt("2") },
{ _id : NumberLong("109"), name : 'spare tire', description: '24 inch spare tire', weight : 22.2, quantity : NumberInt("5") }
]);

db.customers.insert([
{ _id : NumberLong("1001"), first_name : 'Sally', last_name : 'Thomas', email : 'sally.thomas@acme.com' },
{ _id : NumberLong("1002"), first_name : 'George', last_name : 'Bailey', email : 'gbailey@foobar.com' },
{ _id : NumberLong("1003"), first_name : 'Edward', last_name : 'Walker', email : 'ed@walker.com' },
{ _id : NumberLong("1004"), first_name : 'Anne', last_name : 'Kretchmar', email : 'annek@noanswer.org' }
]);

db.orders.insert([
{ _id : NumberLong("10001"), order_date : new ISODate("2016-01-16T00:00:00Z"), purchaser_id : NumberLong("1001"), quantity : NumberInt("1"), product_id : NumberLong("102") },
{ _id : NumberLong("10002"), order_date : new ISODate("2016-01-17T00:00:00Z"), purchaser_id : NumberLong("1002"), quantity : NumberInt("2"), product_id : NumberLong("105") },
{ _id : NumberLong("10003"), order_date : new ISODate("2016-02-19T00:00:00Z"), purchaser_id : NumberLong("1002"), quantity : NumberInt("2"), product_id : NumberLong("106") },
{ _id : NumberLong("10004"), order_date : new ISODate("2016-02-21T00:00:00Z"), purchaser_id : NumberLong("1003"), quantity : NumberInt("1"), product_id : NumberLong("107") }
]);
EOF

echo "Inserted example data"