35 lines
844 B
Makefile
35 lines
844 B
Makefile
# db names: nameDB
|
|
# collection names: lower case, plural
|
|
# user names?
|
|
|
|
# mongo admin -u root -p password --eval "db.getSiblingDB('vlDB').addUser('vluser', 'password')"
|
|
|
|
STACKNAME = dbstack
|
|
|
|
.PHONY: start_db FORCE
|
|
|
|
all: build_run create_users
|
|
|
|
build_run: build_mongo run_stack
|
|
|
|
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:
|
|
mkdir -p ${HOME}/mongo_container/data/
|
|
docker stack deploy --compose-file mongodb-stack.yml $(STACKNAME)
|
|
|
|
create_users: create.js
|
|
docker exec $(shell ./get_container_name.sh) /init_inside_container.sh
|
|
# rm create.js
|