Skip to content

Commit

Permalink
DBZ-7712 fixed init script for example mongodb images
Browse files Browse the repository at this point in the history
  • Loading branch information
MartinMedek authored and jpechane committed Mar 28, 2024
1 parent ff52001 commit 0160cf9
Show file tree
Hide file tree
Showing 6 changed files with 102 additions and 98 deletions.
2 changes: 2 additions & 0 deletions examples/mongodb/2.5/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@ FROM mongo:6.0
LABEL maintainer="Debezium Community"

COPY init-inventory.sh /usr/local/bin/
COPY insert-inventory-data.js /usr/local/bin/

RUN chmod +x /usr/local/bin/init-inventory.sh

# Starting with MongoDB 4.4 the authentication enabled MongoDB requires a key
Expand Down
70 changes: 21 additions & 49 deletions examples/mongodb/2.5/init-inventory.sh
Original file line number Diff line number Diff line change
Expand Up @@ -15,32 +15,32 @@ HOSTNAME=`hostname`
done
echo "Using HOSTNAME='$HOSTNAME'"

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

echo "Initiated replica set"

sleep 3
mongo localhost:27017/admin <<-EOF
db.createUser({ user: 'admin', pwd: 'admin', roles: [ { role: "userAdminAnyDatabase", db: "admin" } ] });
EOF
mongosh localhost:27017/admin --eval "
db.createUser({ user: 'admin', pwd: 'admin', roles: [ { role: 'userAdminAnyDatabase', db: 'admin' } ] });
"

mongo -u admin -p admin localhost:27017/admin <<-EOF
mongosh -u admin -p admin localhost:27017/admin --eval "
db.runCommand({
createRole: "listDatabases",
createRole: 'listDatabases',
privileges: [
{ resource: { cluster : true }, actions: ["listDatabases"]}
{ resource: { cluster : true }, actions: ['listDatabases']}
],
roles: []
});
db.runCommand({
createRole: "readChangeStream",
createRole: 'readChangeStream',
privileges: [
{ resource: { db: "", collection: ""}, actions: [ "find", "changeStream" ] }
{ resource: { db: '', collection: ''}, actions: [ 'find', 'changeStream' ] }
],
roles: []
});
Expand All @@ -49,46 +49,18 @@ mongo -u admin -p admin localhost:27017/admin <<-EOF
user: 'debezium',
pwd: 'dbz',
roles: [
{ role: "readWrite", db: "inventory" },
{ role: "read", db: "local" },
{ role: "listDatabases", db: "admin" },
{ role: "readChangeStream", db: "admin" },
{ role: "read", db: "config" },
{ role: "read", db: "admin" }
{ role: 'readWrite', db: 'inventory' },
{ role: 'read', db: 'local' },
{ role: 'listDatabases', db: 'admin' },
{ role: 'readChangeStream', db: 'admin' },
{ role: 'read', db: 'config' },
{ role: 'read', db: 'admin' }
]
});
EOF
"

echo "Created users"

mongo -u debezium -p dbz --authenticationDatabase admin 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 : '[email protected]' },
{ _id : NumberLong("1002"), first_name : 'George', last_name : 'Bailey', email : '[email protected]' },
{ _id : NumberLong("1003"), first_name : 'Edward', last_name : 'Walker', email : '[email protected]' },
{ _id : NumberLong("1004"), first_name : 'Anne', last_name : 'Kretchmar', email : '[email protected]' }
]);
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
mongosh -u debezium -p dbz localhost:27017 --file /usr/local/bin/insert-inventory-data.js

echo "Inserted example data"
28 changes: 28 additions & 0 deletions examples/mongodb/2.5/insert-inventory-data.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
db = db.getSiblingDB('inventory');

// CREATE TEST DATA
db.products.insertMany([
{ _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.insertMany([
{ _id : NumberLong("1001"), first_name : 'Sally', last_name : 'Thomas', email : '[email protected]' },
{ _id : NumberLong("1002"), first_name : 'George', last_name : 'Bailey', email : '[email protected]' },
{ _id : NumberLong("1003"), first_name : 'Edward', last_name : 'Walker', email : '[email protected]' },
{ _id : NumberLong("1004"), first_name : 'Anne', last_name : 'Kretchmar', email : '[email protected]' }
]);

db.orders.insertMany([
{ _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") }
]);
2 changes: 2 additions & 0 deletions examples/mongodb/2.6/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@ FROM mongo:6.0
LABEL maintainer="Debezium Community"

COPY init-inventory.sh /usr/local/bin/
COPY insert-inventory-data.js /usr/local/bin/

RUN chmod +x /usr/local/bin/init-inventory.sh

# Starting with MongoDB 4.4 the authentication enabled MongoDB requires a key
Expand Down
70 changes: 21 additions & 49 deletions examples/mongodb/2.6/init-inventory.sh
Original file line number Diff line number Diff line change
Expand Up @@ -15,32 +15,32 @@ HOSTNAME=`hostname`
done
echo "Using HOSTNAME='$HOSTNAME'"

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

echo "Initiated replica set"

sleep 3
mongo localhost:27017/admin <<-EOF
db.createUser({ user: 'admin', pwd: 'admin', roles: [ { role: "userAdminAnyDatabase", db: "admin" } ] });
EOF
mongosh localhost:27017/admin --eval "
db.createUser({ user: 'admin', pwd: 'admin', roles: [ { role: 'userAdminAnyDatabase', db: 'admin' } ] });
"

mongo -u admin -p admin localhost:27017/admin <<-EOF
mongosh -u admin -p admin localhost:27017/admin --eval "
db.runCommand({
createRole: "listDatabases",
createRole: 'listDatabases',
privileges: [
{ resource: { cluster : true }, actions: ["listDatabases"]}
{ resource: { cluster : true }, actions: ['listDatabases']}
],
roles: []
});
db.runCommand({
createRole: "readChangeStream",
createRole: 'readChangeStream',
privileges: [
{ resource: { db: "", collection: ""}, actions: [ "find", "changeStream" ] }
{ resource: { db: '', collection: ''}, actions: [ 'find', 'changeStream' ] }
],
roles: []
});
Expand All @@ -49,46 +49,18 @@ mongo -u admin -p admin localhost:27017/admin <<-EOF
user: 'debezium',
pwd: 'dbz',
roles: [
{ role: "readWrite", db: "inventory" },
{ role: "read", db: "local" },
{ role: "listDatabases", db: "admin" },
{ role: "readChangeStream", db: "admin" },
{ role: "read", db: "config" },
{ role: "read", db: "admin" }
{ role: 'readWrite', db: 'inventory' },
{ role: 'read', db: 'local' },
{ role: 'listDatabases', db: 'admin' },
{ role: 'readChangeStream', db: 'admin' },
{ role: 'read', db: 'config' },
{ role: 'read', db: 'admin' }
]
});
EOF
"

echo "Created users"

mongo -u debezium -p dbz --authenticationDatabase admin 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 : '[email protected]' },
{ _id : NumberLong("1002"), first_name : 'George', last_name : 'Bailey', email : '[email protected]' },
{ _id : NumberLong("1003"), first_name : 'Edward', last_name : 'Walker', email : '[email protected]' },
{ _id : NumberLong("1004"), first_name : 'Anne', last_name : 'Kretchmar', email : '[email protected]' }
]);
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
mongosh -u debezium -p dbz localhost:27017 --file /usr/local/bin/insert-inventory-data.js

echo "Inserted example data"
28 changes: 28 additions & 0 deletions examples/mongodb/2.6/insert-inventory-data.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
db = db.getSiblingDB('inventory');

// CREATE TEST DATA
db.products.insertMany([
{ _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.insertMany([
{ _id : NumberLong("1001"), first_name : 'Sally', last_name : 'Thomas', email : '[email protected]' },
{ _id : NumberLong("1002"), first_name : 'George', last_name : 'Bailey', email : '[email protected]' },
{ _id : NumberLong("1003"), first_name : 'Edward', last_name : 'Walker', email : '[email protected]' },
{ _id : NumberLong("1004"), first_name : 'Anne', last_name : 'Kretchmar', email : '[email protected]' }
]);

db.orders.insertMany([
{ _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") }
]);

0 comments on commit 0160cf9

Please sign in to comment.