summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--database/Dockerfile2
-rw-r--r--docker-compose.yml28
-rw-r--r--mongodb/Dockerfile5
-rw-r--r--mongodb/mongo-init-opendc-db.sh54
-rw-r--r--mongodb/mongo-init.js67
5 files changed, 155 insertions, 1 deletions
diff --git a/database/Dockerfile b/database/Dockerfile
index 0e933b40..e30aed51 100644
--- a/database/Dockerfile
+++ b/database/Dockerfile
@@ -5,4 +5,4 @@ MAINTAINER Fabian Mastenbroek <f.s.mastenbroek@student.tudelft.nl>
ADD schema.sql /docker-entrypoint-initdb.d
# Add test data into database
-ADD test.sql /docker-entrypoint-initdb.d
+#ADD test.sql /docker-entrypoint-initdb.d
diff --git a/docker-compose.yml b/docker-compose.yml
index a89b7260..4331a5a8 100644
--- a/docker-compose.yml
+++ b/docker-compose.yml
@@ -43,3 +43,31 @@ services:
# uncomment in production
# volumes:
# - "/data/mariadb:/var/lib/mysql"
+ mongo:
+ build:
+ context: ./mongodb
+ restart: on-failure
+ environment:
+ MONGO_INITDB_ROOT_USERNAME: root
+ MONGO_INITDB_ROOT_PASSWORD: rootpassword
+ MONGO_INITDB_DATABASE: admin
+ OPENDC_DB: opendc
+ OPENDC_DB_USERNAME: opendc
+ OPENDC_DB_PASSWORD: opendcpassword
+ ports:
+ - 27017:27017
+ #volumes:
+ # - mongo-volume:/data/db
+
+ mongo-express:
+ image: mongo-express
+ restart: on-failure
+ ports:
+ - 8082:8081
+ environment:
+ ME_CONFIG_MONGODB_ADMINUSERNAME: root
+ ME_CONFIG_MONGODB_ADMINPASSWORD: rootpassword
+
+volumes:
+ mongo-volume:
+ external: false \ No newline at end of file
diff --git a/mongodb/Dockerfile b/mongodb/Dockerfile
new file mode 100644
index 00000000..b4eb9dd1
--- /dev/null
+++ b/mongodb/Dockerfile
@@ -0,0 +1,5 @@
+FROM mongo:4.2.5
+MAINTAINER Jacob Burley <j.burley@vu.nl>
+
+# Import init script
+ADD mongo-init-opendc-db.sh /docker-entrypoint-initdb.d \ No newline at end of file
diff --git a/mongodb/mongo-init-opendc-db.sh b/mongodb/mongo-init-opendc-db.sh
new file mode 100644
index 00000000..ed33e955
--- /dev/null
+++ b/mongodb/mongo-init-opendc-db.sh
@@ -0,0 +1,54 @@
+#!/bin/bash
+
+echo 'Creating opendc user and db'
+
+mongo opendc --host localhost \
+ --port 27017 \
+ -u $MONGO_INITDB_ROOT_USERNAME \
+ -p $MONGO_INITDB_ROOT_PASSWORD \
+ --authenticationDatabase admin \
+ --eval "db.createUser({user: '$OPENDC_DB_USERNAME', pwd: '$OPENDC_DB_PASSWORD', roles:[{role:'dbOwner', db: '$OPENDC_DB'}]});"
+MONGO_ROOT_CMD="mongo $OPENDC_DB --host localhost --port 27017 -u $MONGO_INITDB_ROOT_USERNAME -p $MONGO_INITDB_ROOT_PASSWORD --authenticationDatabase admin"
+
+#echo 'Creating opendc db schema...'
+MONGO_CMD="mongo $OPENDC_DB -u $OPENDC_DB_USERNAME -p $OPENDC_DB_PASSWORD --authenticationDatabase $OPENDC_DB"
+$MONGO_CMD --eval 'db.createCollection("environments", {
+ validator: {
+ $jsonSchema: {
+ bsonType: "object",
+ required: ["name"],
+ properties: {
+ name: {
+ bsonType: "string",
+ description: "The name of the environment i.e. Production, or Compute Cluster"
+ },
+ datacenters: {
+ bsonType: "object",
+ required: ["name, location, length, width, height"],
+ properties: {
+ name: {
+ bsonType: "string",
+ description: "The name of the datacenter i.e. eu-west-1, or Science Building"
+ },
+ location: {
+ bsonType: "string",
+ description: "The location of the datacenter i.e. Frankfurt, or De Boelelaan 1105"
+ },
+ length: {
+ bsonType: "double",
+ description: "The physical length of the datacenter, in centimetres"
+ },
+ width: {
+ bsonType: "double",
+ description: "The physical width of the datacenter, in centimetres"
+ },
+ height: {
+ bsonType: "double",
+ description: "The physical height of the datacenter, in centimetres"
+ }
+ }
+ }
+ }
+ }
+ }
+});' \ No newline at end of file
diff --git a/mongodb/mongo-init.js b/mongodb/mongo-init.js
new file mode 100644
index 00000000..562bda6f
--- /dev/null
+++ b/mongodb/mongo-init.js
@@ -0,0 +1,67 @@
+db.auth('root', 'rootpassword')
+
+let error = true
+
+db.createUser(
+ {
+ user: "admin",
+ pwd: "adminpassword",
+ roles: [
+ {
+ role: "readWrite",
+ db: "admin"
+ }
+ ]
+ }
+)
+
+db = db.getSiblingDB('opendc')
+
+db.createUser(
+ {
+ user: "opendc",
+ pwd: "opendcpassword",
+ roles: [
+ {
+ role: "readWrite",
+ db: "opendc"
+ }
+ ]
+ }
+);
+
+db.createCollection(users)
+db.createCollection(authorizations)
+db.createCollection(authorization_levels)
+db.createCollection(simulations)
+db.createCollection(experiments)
+db.createCollection(paths)
+db.createCollection(sections)
+db.createCollection(schedulers)
+db.createCollection(traces)
+db.createCollection(jobs)
+db.createCollection(tasks)
+db.createCollection(task_dependencies)
+db.createCollection(task_states)
+db.createCollection(machine_states)
+db.createCollection(datacenters)
+db.createCollection(rooms)
+db.createCollection(room_types)
+db.createCollection(tiles)
+db.createCollection(objects)
+db.createCollection(object_types)
+db.createCollection(allowed_objects)
+db.createCollection(psus)
+db.createCollection(cooling_items)
+db.createCollection(racks)
+db.createCollection(machines)
+db.createCollection(machine_tags)
+db.createCollection(failure_models)
+db.createCollection(cpus)
+db.createCollection(machine_cpus)
+db.createCollection(gpus)
+db.createCollection(machine_gpus)
+db.createCollection(memories)
+db.createCollection(machine_memories)
+db.createCollection(storages)
+db.createCollection(machine_storages) \ No newline at end of file