From 4f8612501ed5cf9653aa6ab14c8455605f56464b Mon Sep 17 00:00:00 2001 From: jc0b Date: Mon, 11 May 2020 20:43:03 +0200 Subject: Added mongodb dockerfile, removed tests being added to sql db --- mongodb/Dockerfile | 3 +-- mongodb/mongo-init-opendc-db.sh | 50 +++++++++++++++++++++++++++++++++++++---- mongodb/mongo-opendc-schema.sh | 7 ------ 3 files changed, 47 insertions(+), 13 deletions(-) delete mode 100644 mongodb/mongo-opendc-schema.sh (limited to 'mongodb') 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 # 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 -- cgit v1.2.3