summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorjc0b <j.burley@vu.nl>2020-05-11 20:43:03 +0200
committerjc0b <j.burley@vu.nl>2020-05-11 20:43:03 +0200
commit9663374aa7f086b8a0aa9e0f254f0487f5ce09b4 (patch)
treee29a6b0f5c42824a0ede7d532797a9ab9c6453a6
parent4c347eb501a16eaa2a54933ed1ec8fa26521cc88 (diff)
Added mongodb dockerfile, removed tests being added to sql db
-rw-r--r--database/Dockerfile2
-rw-r--r--docker-compose.yml8
-rw-r--r--mongodb/Dockerfile3
-rw-r--r--mongodb/mongo-init-opendc-db.sh50
-rw-r--r--mongodb/mongo-opendc-schema.sh7
5 files changed, 55 insertions, 15 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 2bbc0d9e..4331a5a8 100644
--- a/docker-compose.yml
+++ b/docker-compose.yml
@@ -56,6 +56,8 @@ services:
OPENDC_DB_PASSWORD: opendcpassword
ports:
- 27017:27017
+ #volumes:
+ # - mongo-volume:/data/db
mongo-express:
image: mongo-express
@@ -64,4 +66,8 @@ services:
- 8082:8081
environment:
ME_CONFIG_MONGODB_ADMINUSERNAME: root
- ME_CONFIG_MONGODB_ADMINPASSWORD: rootpassword \ No newline at end of file
+ ME_CONFIG_MONGODB_ADMINPASSWORD: rootpassword
+
+volumes:
+ mongo-volume:
+ external: false \ No newline at end of file
diff --git a/mongodb/Dockerfile b/mongodb/Dockerfile
index e8dd98bc..b4eb9dd1 100644
--- a/mongodb/Dockerfile
+++ b/mongodb/Dockerfile
@@ -2,5 +2,4 @@ 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
-ADD mongo-opendc-schema.sh /docker-entrypoint-initdb.d \ No newline at end of file
+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
index 55e9ec68..ed33e955 100644
--- a/mongodb/mongo-init-opendc-db.sh
+++ b/mongodb/mongo-init-opendc-db.sh
@@ -2,11 +2,53 @@
echo 'Creating opendc user and db'
-mongo opendc \
- --host localhost \
+mongo opendc --host localhost \
--port 27017 \
-u $MONGO_INITDB_ROOT_USERNAME \
-p $MONGO_INITDB_ROOT_PASSWORD \
--authenticationDatabase admin \
- --eval "db.createUser({user: 'opendc', pwd: 'opendcpassword', roles:[{role:'dbOwner', db: 'opendc'}]});"
-$MONGO_CMD = "mongo opendc --host localhost --port 27017 -u $MONGO_INITDB_ROOT_USERNAME -p $MONGO_INITDB_ROOT_PASSWORD --authenticationDatabase admin" \ No newline at end of file
+ --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-opendc-schema.sh b/mongodb/mongo-opendc-schema.sh
deleted file mode 100644
index 7fd9d10f..00000000
--- a/mongodb/mongo-opendc-schema.sh
+++ /dev/null
@@ -1,7 +0,0 @@
-#!/bin/bash
-
-echo 'Creating opendc db schema...'
-
-$MONGO_CMD = "mongo opendc --host localhost --port 27017 -u $OPENDC_DB_USERNAME -p $OPENDC_DB_PASSWORD --authenticationDatabase opendc"
-
-eval $MONGO_COMMAND --eval "db.createCollection('environments'); db.createCollection('rooms'); db.createCollection('datacenters');" \ No newline at end of file