From 3aff9941c93e7eb2420991ad456fe211b178ca11 Mon Sep 17 00:00:00 2001 From: Cyril Dubuisson Date: Mon, 12 Aug 2019 17:19:18 +0200 Subject: [PATCH] :whale: : add scripts to initiate mongo database --- Dockerfile-db | 3 ++ README.md | 8 ++++- docker-compose.yml | 13 +++++--- src/test/resources/db/00_team.js | 10 ++++++ src/test/resources/db/10_user.js | 12 +++++++ src/test/resources/db/20_module.js | 43 ++++++++++++++++++++++++ src/test/resources/db/30_stack.js | 52 ++++++++++++++++++++++++++++++ 7 files changed, 136 insertions(+), 5 deletions(-) create mode 100644 Dockerfile-db create mode 100644 src/test/resources/db/00_team.js create mode 100644 src/test/resources/db/10_user.js create mode 100644 src/test/resources/db/20_module.js create mode 100644 src/test/resources/db/30_stack.js diff --git a/Dockerfile-db b/Dockerfile-db new file mode 100644 index 000000000..a3ecb50ee --- /dev/null +++ b/Dockerfile-db @@ -0,0 +1,3 @@ +FROM mongo + +COPY /src/test/resources/db/*.js /docker-entrypoint-initdb.d/ \ No newline at end of file diff --git a/README.md b/README.md index a18ae2f39..0590f7bcf 100644 --- a/README.md +++ b/README.md @@ -41,7 +41,13 @@ Building Gaia with docker is simple : docker build -t gaia . ``` -We provide a simple `docker-compose.yml` to allow you to start gaia with a mongo database. +To build mongo database with initiated data : + +```bash +docker build -f Dockerfile-db -t gaia-db . +``` + +Either, we provide a simple `docker-compose.yml` to allow you to start gaia with the mongo database. Just run `docker-compose up -d` diff --git a/docker-compose.yml b/docker-compose.yml index 1f6e798a2..b5fd7545d 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -1,10 +1,15 @@ version: "3" services: gaia: - image: gaia + build: . + image: gaia ports: - - '8080:8080' + - '8080:8080' environment: - - "GAIA_MONGODB_URI=mongodb://mongo/gaia" + - "GAIA_MONGODB_URI=mongodb://mongo/gaia" + mongo: - image: mongo + build: + context: . + dockerfile: ./Dockerfile-db + image: gaia-db \ No newline at end of file diff --git a/src/test/resources/db/00_team.js b/src/test/resources/db/00_team.js new file mode 100644 index 000000000..4f95c042b --- /dev/null +++ b/src/test/resources/db/00_team.js @@ -0,0 +1,10 @@ +let gaia = db.getSiblingDB('gaia'); +gaia.team.drop(); +gaia.team.insert([ + { + "_id": "Ze Team" + }, + { + "_id": "Not Ze Team" + } +]); \ No newline at end of file diff --git a/src/test/resources/db/10_user.js b/src/test/resources/db/10_user.js new file mode 100644 index 000000000..8a5f1d5f1 --- /dev/null +++ b/src/test/resources/db/10_user.js @@ -0,0 +1,12 @@ +gaia = db.getSiblingDB('gaia'); +gaia.user.drop(); +gaia.user.insert([ + { + "_id": "admin", + "team": {"$ref": "team", "$id": "Ze Team"} + }, + { + "_id": "Mary J", + "team": {"$ref": "team", "$id": "Not Ze Team"} + } +]); \ No newline at end of file diff --git a/src/test/resources/db/20_module.js b/src/test/resources/db/20_module.js new file mode 100644 index 000000000..62408d73f --- /dev/null +++ b/src/test/resources/db/20_module.js @@ -0,0 +1,43 @@ +gaia = db.getSiblingDB('gaia'); +gaia.terraformModule.drop(); +gaia.terraformModule.insert([ + { + "_id": "e01f9925-a559-45a2-8a55-f93dc434c676", + "name": "terraform-docker-mongo", + "description": "A sample terraform 🌍 module for running a mongodb 🍃 database inside a docker 🐳 container", + "gitRepositoryUrl": "https://github.com/juwit/terraform-docker-mongo.git", + "directory": null, + "gitBranch": "master", + "cliVersion": "0.11.14", + "authorizedTeams": [{"$ref": "team", "$id": "Ze Team"}], + "estimatedMonthlyCost": 0.99, + "estimatedMonthlyCostDescription": "Kamoulox", + "variables": [ + { + "name": "mongo_container_name", + "description": "the name of the docker container", + "defaultValue": null, + "editable": true + }, + { + "name": "mongo_exposed_port", + "description": "the exposed port of the mongo container", + "defaultValue": null, + "editable": true + } + ] + }, + { + "_id": "845543d0-20a5-466c-8978-33c9a4661606", + "name": "terraform-docker-mongo-limited", + "description": "A module only visible by admin and team Not Ze Team", + "gitRepositoryUrl": "https://github.com/juwit/terraform-docker-mongo.git", + "directory": null, + "gitBranch": "master", + "cliVersion": "0.11.14", + "authorizedTeams": [{"$ref": "team", "$id": "Not Ze Team"}], + "estimatedMonthlyCost": 9.99, + "estimatedMonthlyCostDescription": "Not Ze Team! Not Ze Team!", + "variables": [] + }, +]); \ No newline at end of file diff --git a/src/test/resources/db/30_stack.js b/src/test/resources/db/30_stack.js new file mode 100644 index 000000000..481cebfd0 --- /dev/null +++ b/src/test/resources/db/30_stack.js @@ -0,0 +1,52 @@ +gaia = db.getSiblingDB('gaia'); +gaia.stack.drop(); +gaia.stack.insert([ + { + "_id": "5a215b6b-fe53-4afa-85f0-a10175a7f264", + "moduleId": "e01f9925-a559-45a2-8a55-f93dc434c676", + "name": "mongo-instance-1", + "description": "first instance of mongo module", + "variableValues": { + "mongo_container_name": "test", + "mongo_exposed_port": "27117" + }, + "providerSpec": "provider \"docker\" {\n host = \"unix:///var/run/docker.sock\"\n}", + "state": "NEW", + "ownerTeam": {"$ref": "team", "$id": "Ze Team"}, + "estimatedRunningCost": null, + "createdBy": {"$ref": "user", "$id": "admin"}, + "createdAt": new Date(), + "updatedBy": null, + "updatedAt": null + }, + { + "_id": "143773fa-4c2e-4baf-a7fb-79d23e01c5ca", + "moduleId": "e01f9925-a559-45a2-8a55-f93dc434c676", + "name": "mongo-instance-2", + "description": "second instance of mongo module", + "variablesValues": {}, + "providerSpec": null, + "state": "NEW", + "ownerTeam": {"$ref": "team", "$id": "Ze Team"}, + "estimatedRunningCost": null, + "createdBy": {"$ref": "user", "$id": "admin"}, + "createdAt": new Date(), + "updatedBy": null, + "updatedAt": null + }, + { + "_id": "845543d0-20a5-466c-8978-33c9a4661606", + "moduleId": "845543d0-20a5-466c-8978-33c9a4661606", + "name": "mongo-instance-limited", + "description": "instance of mongo module for team Not Ze Team", + "variablesValues": {}, + "providerSpec": null, + "state": "NEW", + "ownerTeam": {"$ref": "team", "$id": "Not Ze Team"}, + "estimatedRunningCost": null, + "createdBy": {"$ref": "user", "$id": "Mary J"}, + "createdAt": new Date(), + "updatedBy": null, + "updatedAt": null + } +]); \ No newline at end of file