Skip to content
This repository was archived by the owner on Nov 27, 2024. It is now read-only.

Commit 421a23f

Browse files
Naba DasNaba Das
Naba Das
authored and
Naba Das
committed
User create
1 parent 43e3c99 commit 421a23f

34 files changed

+111
-15
lines changed

.env

+8-2
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,8 @@
1-
DATA_PATH_HOST=/tmp
2-
MONGODB_PORT=45369
1+
DATA_PATH_HOST=/tmp/mongo
2+
MONGODB_PORT=45369
3+
DB_NAME=deck
4+
DB_USER=deck
5+
DB_PASSWORD=deck
6+
DB_ROOT_PASSWORD=example
7+
DB_ROOT_USERNAME=root
8+
MONGODB_CLIENT_PORT=12345

README.md

+19
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
## MongoDB
2+
MongoDB(R) is a relational open source NoSQL database. Easy to use, it stores data in JSON-like documents. Automated scalability and high-performance. Ideal for developing cloud native applications.
3+
4+
## Install
5+
### Using DECK
6+
Install MongoDB from the DECK marketplace and follow the instructions on the GUI
7+
### From terminal with Docker
8+
```console
9+
$ git clone https://github.com/deck-app/mongodb.git
10+
$ cd mongodb
11+
$ docker-compose up -d
12+
```
13+
### Modifying project settings
14+
From the DECK app, go to stack list and click on project's `More > configure > Advanced configuration` Follow the instructions below and restart your stack from the GUI
15+
### Rebuilding from terminal
16+
You have to rebuild the docker image after you make any changes to the project configuration, use the snippet below to rebuild and restart the stack
17+
```
18+
docker-compose stop && docker-compose up --build -d
19+
```

data/mongo/WiredTiger

+2
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
WiredTiger
2+
WiredTiger 10.0.2: (November 30, 2021)

data/mongo/WiredTiger.lock

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
WiredTiger lock file

data/mongo/WiredTiger.turtle

+6
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
WiredTiger version string
2+
WiredTiger 10.0.2: (November 30, 2021)
3+
WiredTiger version
4+
major=10,minor=0,patch=2
5+
file:WiredTiger.wt
6+
access_pattern_hint=none,allocation_size=4KB,app_metadata=,assert=(commit_timestamp=none,durable_timestamp=none,read_timestamp=none,write_timestamp=off),block_allocation=best,block_compressor=,cache_resident=false,checksum=on,collator=,columns=,dictionary=0,encryption=(keyid=,name=),format=btree,huffman_key=,huffman_value=,id=0,ignore_in_memory_cache_size=false,internal_item_max=0,internal_key_max=0,internal_key_truncate=true,internal_page_max=4KB,key_format=S,key_gap=10,leaf_item_max=0,leaf_key_max=0,leaf_page_max=32KB,leaf_value_max=0,log=(enabled=true),memory_page_image_max=0,memory_page_max=5MB,os_cache_dirty_max=0,os_cache_max=0,prefix_compression=false,prefix_compression_min=4,readonly=false,split_deepen_min_child=0,split_deepen_per_child=0,split_pct=90,tiered_object=false,tiered_storage=(auth_token=,bucket=,bucket_prefix=,cache_directory=,local_retention=300,name=,object_target_size=10M),value_format=S,verbose=[],version=(major=1,minor=1),write_timestamp_usage=none,checkpoint=(WiredTigerCheckpoint.11=(addr="018681e4081e03228781e4c454b3428881e4c9046ea9808080e3010fc0e23fc0",order=11,time=1646221450,size=28672,newest_start_durable_ts=0,oldest_start_ts=0,newest_txn=18,newest_stop_durable_ts=0,newest_stop_ts=-1,newest_stop_txn=-11,prepare=0,write_gen=32,run_write_gen=9)),checkpoint_backup_info=,checkpoint_lsn=(2,9472)

data/mongo/WiredTiger.wt

76 KB
Binary file not shown.

data/mongo/WiredTigerHS.wt

4 KB
Binary file not shown.

data/mongo/_mdb_catalog.wt

20 KB
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
18.5 KB
Binary file not shown.
20 KB
Binary file not shown.
36 KB
Binary file not shown.
4 KB
Binary file not shown.
4 KB
Binary file not shown.
20 KB
Binary file not shown.
20 KB
Binary file not shown.
100 MB
Binary file not shown.
Binary file not shown.
Binary file not shown.

data/mongo/mongod.lock

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
1

data/mongo/sizeStorer.wt

36 KB
Binary file not shown.

data/mongo/storage.bson

114 Bytes
Binary file not shown.

docker-compose.yml

+15-1
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,24 @@
11
version: '3'
22
services:
33
mongo:
4-
build: './mongo'
4+
build:
5+
context: './mongo'
6+
args:
7+
- 'MONGO_INITDB_USERNAME=${DB_USER}'
8+
- 'MONGO_INITDB_PASSWORD=${DB_PASSWORD}'
9+
- 'MONGO_INITDB_DATABASE=${DB_NAME}'
10+
environment:
11+
- 'MONGO_INITDB_ROOT_USERNAME=${DB_ROOT_USERNAME}'
12+
- 'MONGO_INITDB_ROOT_PASSWORD=${DB_ROOT_PASSWORD}'
513
ports:
614
- '${MONGODB_PORT}:27017'
15+
command: [--auth]
716
volumes:
817
- '${DATA_PATH_HOST}/mongo:/data/db'
918
- '${DATA_PATH_HOST}/mongo_config:/data/configdb'
19+
mongo-client:
20+
build:
21+
context: './mongo-client'
22+
ports:
23+
- '${MONGODB_CLIENT_PORT}:8000'
1024
volumes: {}

mongo-client

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Subproject commit 9bb469013196d2986d5f7259be9c0f3423c78001

mongo/Dockerfile

+15-10
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,17 @@
11
FROM mongo:latest
22

3-
LABEL maintainer="Mahmoud Zalt <[email protected]>"
4-
5-
#COPY mongo.conf /usr/local/etc/mongo/mongo.conf
6-
7-
VOLUME /data/db /data/configdb
8-
9-
CMD ["mongod"]
10-
11-
EXPOSE 27017
12-
3+
COPY root-create.js /docker-entrypoint-initdb.d/root-create.js
4+
COPY user-create.js /docker-entrypoint-initdb.d/user-create.js
5+
ARG MONGO_INITDB_ROOT_USERNAME
6+
ARG MONGO_INITDB_ROOT_PASSWORD
7+
ARG MONGO_INITDB_USERNAME
8+
ARG MONGO_INITDB_PASSWORD
9+
ARG MONGO_INITDB_DATABASE
10+
RUN sed -i "s#{MONGO_INITDB_ROOT_USERNAME}#${MONGO_INITDB_ROOT_USERNAME}#g" /docker-entrypoint-initdb.d/root-create.js
11+
RUN sed -i "s#{MONGO_INITDB_ROOT_PASSWORD}#${MONGO_INITDB_ROOT_PASSWORD}#g" /docker-entrypoint-initdb.d/root-create.js
12+
RUN sed -i "s#{MONGO_INITDB_ROOT_USERNAME}#${MONGO_INITDB_ROOT_USERNAME}#g" /docker-entrypoint-initdb.d/user-create.js
13+
RUN sed -i "s#{MONGO_INITDB_ROOT_PASSWORD}#${MONGO_INITDB_ROOT_PASSWORD}#g" /docker-entrypoint-initdb.d/user-create.js
14+
RUN sed -i "s#{MONGO_INITDB_USERNAME}#${MONGO_INITDB_USERNAME}#g" /docker-entrypoint-initdb.d/user-create.js
15+
RUN sed -i "s#{MONGO_INITDB_PASSWORD}#${MONGO_INITDB_PASSWORD}#g" /docker-entrypoint-initdb.d/user-create.js
16+
RUN sed -i "s#{MONGO_INITDB_DATABASE}#${MONGO_INITDB_DATABASE}#g" /docker-entrypoint-initdb.d/user-create.js
17+
CMD [ "mongod" ]

mongo/init-mongo.sh

+15
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
#!bin/bash
2+
set -e
3+
echo ">>>>>>> trying to create database and users"
4+
mongo -u $MONGO_INITDB_ROOT_USERNAME -p $MONGO_INITDB_ROOT_PASSWORD<<EOF
5+
db=db.getSiblingDB('${MONGO_INITDB_DATABASE}');
6+
use ${MONGO_INITDB_DATABASE};
7+
db.createUser({
8+
user: '$MONGO_INITDB_USERNAME',
9+
pwd: '$MONGO_INITDB_PASSWORD',
10+
roles: [{
11+
role: 'readWrite',
12+
db: '${MONGO_INITDB_DATABASE}'
13+
}]
14+
});
15+
EOF

mongo/root-create.js

+9
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
var db = connect("mongodb://localhost:27017/admin");
2+
3+
db.createUser(
4+
{
5+
user: "{DB_ROOT_USERNAME}",
6+
pwd: "{DB_ROOT_PASSWORD}",
7+
roles: ['dbAdminAnyDatabase', 'readWriteAnyDatabase', 'clusterAdmin', 'restore', 'backup']
8+
}
9+
)

mongo/user-create.js

+15
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
var db = connect("mongodb://{MONGO_INITDB_ROOT_USERNAME}:{MONGO_INITDB_ROOT_PASSWORD}@localhost:27017/?authSource=admin");
2+
3+
db = db.getSiblingDB('{MONGO_INITDB_DATABASE}');
4+
db.createUser(
5+
{
6+
user: "{MONGO_INITDB_USERNAME}",
7+
pwd: "{MONGO_INITDB_PASSWORD}",
8+
roles:[
9+
{
10+
role: "readWrite",
11+
db: "{MONGO_INITDB_DATABASE}"
12+
}
13+
]
14+
}
15+
)

settings.yml

+4-2
Original file line numberDiff line numberDiff line change
@@ -57,9 +57,11 @@ system:
5757
# true
5858
#For collecting and storing DB in .env
5959
#db/user/password
60-
# db_credentials:
61-
# true
60+
db_credentials:
61+
true
6262
#Generate public ports for the docker image
6363
ports:
64+
http:
65+
MONGODB_CLIENT_PORT
6466
others:
6567
- MONGODB_PORT

0 commit comments

Comments
 (0)