forked from kristjan/cjvt-valency
automated mongodb + mongo-express deployment with user creation
This commit is contained in:
parent
49e45900c4
commit
d8fd3ad30b
6
Makefile
6
Makefile
|
@ -15,8 +15,10 @@ OUTPUT = "file"
|
||||||
OUTDIR = "/home/voje/workdir/test_out"
|
OUTDIR = "/home/voje/workdir/test_out"
|
||||||
DBADDR = ""
|
DBADDR = ""
|
||||||
|
|
||||||
DB_ADM_USER = testuser
|
DB_ADM_USER = testadmin
|
||||||
DB_ADM_PASS = testpass
|
DB_ADM_PASS = testadminpass
|
||||||
|
DB_USR_USER = testuser
|
||||||
|
DB_USR_PASS = testuserpass
|
||||||
export
|
export
|
||||||
|
|
||||||
.PHONY: dev-env preflight
|
.PHONY: dev-env preflight
|
||||||
|
|
5
dockerfiles/database/Dockerfile
Normal file
5
dockerfiles/database/Dockerfile
Normal file
|
@ -0,0 +1,5 @@
|
||||||
|
FROM mongo:latest
|
||||||
|
|
||||||
|
WORKDIR /
|
||||||
|
COPY init_inside_container.sh /.
|
||||||
|
COPY create.js /.
|
|
@ -4,20 +4,31 @@
|
||||||
|
|
||||||
# mongo admin -u root -p password --eval "db.getSiblingDB('vlDB').addUser('vluser', 'password')"
|
# mongo admin -u root -p password --eval "db.getSiblingDB('vlDB').addUser('vluser', 'password')"
|
||||||
|
|
||||||
.PHONY: start_db
|
|
||||||
|
|
||||||
STACKNAME = dbstack
|
STACKNAME = dbstack
|
||||||
|
|
||||||
all: run_stack create_users
|
.PHONY: start_db FORCE
|
||||||
|
|
||||||
|
all: build_mongo run_stack create_users
|
||||||
|
|
||||||
|
info:
|
||||||
|
echo "[*] RUN THIS A FEW TIMES (THE STACK NEEDS TIME TO CLEAN UP AND TO SPIN UP THE NODES)"
|
||||||
|
|
||||||
|
create.js: FORCE
|
||||||
|
|
||||||
|
FORCE:
|
||||||
|
echo 'db.auth("$(DB_ADM_USER)", "$(DB_ADM_PASS)")' > create.js
|
||||||
|
echo 'use valdb' >> create.js
|
||||||
|
echo 'db.createUser({user: "$(DB_USR_USER)", pwd: "$(DB_USR_PASS)", roles: ["readWrite"]})' >> create.js
|
||||||
|
|
||||||
|
build_mongo: create.js
|
||||||
|
docker build . -t my-mongo --no-cache
|
||||||
|
|
||||||
|
clean_stack:
|
||||||
|
docker stack rm $(STACKNAME)
|
||||||
|
|
||||||
run_stack:
|
run_stack:
|
||||||
docker stack deploy --compose-file mongodb-stack.yml $(STACKNAME)
|
docker stack deploy --compose-file mongodb-stack.yml $(STACKNAME)
|
||||||
|
|
||||||
create.js:
|
|
||||||
echo -e 'db.auth("$(DB_ADM_USER)", "$(DB_ADM_PASS)")\n \
|
|
||||||
use valdb\n \
|
|
||||||
db.createUser({user: "kristjan", pwd: "password", roles: ["readWrite"]})' > create.js
|
|
||||||
|
|
||||||
create_users: create.js
|
create_users: create.js
|
||||||
docker exec $(shell ./get_container_name.sh) mongo admin < create.js
|
docker exec $(shell ./get_container_name.sh) /init_inside_container.sh
|
||||||
# rm create.js
|
# rm create.js
|
||||||
|
|
3
dockerfiles/database/README.md
Normal file
3
dockerfiles/database/README.md
Normal file
|
@ -0,0 +1,3 @@
|
||||||
|
# Some caveats
|
||||||
|
* Access mongo-express using `0.0.0.0:8087` instead of `localhost:...`.
|
||||||
|
* Run make from the root Makefile `make database`. You might need to run it several times (wait for conatiners to come up, etc.).
|
|
@ -1,5 +1,3 @@
|
||||||
db.auth("testuser", "testpass")
|
db.auth("testadmin", "testadminpass")
|
||||||
\
|
use valdb
|
||||||
use valdb
|
db.createUser({user: "testuser", pwd: "testuserpass", roles: ["readWrite"]})
|
||||||
\
|
|
||||||
db.createUser({user: "kristjan", pwd: "password", roles: ["readWrite"]})
|
|
||||||
|
|
|
@ -1,2 +1,2 @@
|
||||||
#!/bin/bash
|
#!/bin/bash
|
||||||
docker ps | grep mongo:latest | awk '{print $1}'
|
docker ps | grep my-mongo | awk '{print $1}'
|
||||||
|
|
3
dockerfiles/database/init_inside_container.sh
Executable file
3
dockerfiles/database/init_inside_container.sh
Executable file
|
@ -0,0 +1,3 @@
|
||||||
|
#!/bin/bash
|
||||||
|
|
||||||
|
mongo admin < /create.js
|
|
@ -2,8 +2,8 @@ version: '3.1'
|
||||||
|
|
||||||
services:
|
services:
|
||||||
|
|
||||||
mongo:
|
my-mongo:
|
||||||
image: mongo
|
image: my-mongo
|
||||||
restart: always
|
restart: always
|
||||||
environment:
|
environment:
|
||||||
MONGO_INITDB_ROOT_USERNAME: ${DB_ADM_USER}
|
MONGO_INITDB_ROOT_USERNAME: ${DB_ADM_USER}
|
||||||
|
@ -13,7 +13,8 @@ services:
|
||||||
image: mongo-express
|
image: mongo-express
|
||||||
restart: always
|
restart: always
|
||||||
ports:
|
ports:
|
||||||
- 8081:8081
|
- 8087:8081
|
||||||
environment:
|
environment:
|
||||||
ME_CONFIG_MONGODB_ADMINUSERNAME: ${DB_ADM_USER}
|
ME_CONFIG_MONGODB_ADMINUSERNAME: ${DB_ADM_USER}
|
||||||
ME_CONFIG_MONGODB_ADMINPASSWORD: ${DB_ADM_PASS}
|
ME_CONFIG_MONGODB_ADMINPASSWORD: ${DB_ADM_PASS}
|
||||||
|
ME_CONFIG_MONGODB_SERVER: my-mongo
|
||||||
|
|
Loading…
Reference in New Issue
Block a user