cjvt-valency/dockerfiles/database/Makefile

24 lines
602 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')"
.PHONY: start_db
STACKNAME = dbstack
all: run_stack create_users
run_stack:
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
docker exec $(shell ./get_container_name.sh) mongo admin < create.js
# rm create.js