cjvt-valency/dockerfiles/database/Makefile

64 lines
2.6 KiB
Makefile
Raw Permalink Normal View History

2019-03-14 18:49:01 +00:00
# db names: nameDB
# collection names: lower case, plural
# user names?
2020-11-23 10:20:47 +00:00
all: build_run create_users
2019-03-14 18:49:01 +00:00
2020-11-23 10:20:47 +00:00
build_run: build_mongo run_docker_compose
postgres_create_roles:
echo 'psql -v ON_ERROR_STOP=OFF --username $(DB_ADM_USER) <<-EOSQL' > create_postgres.js
echo "create user $(DB_USR_USER) with encrypted password '$(DB_USR_PASS)';" >> create_postgres.js
echo "create database superdb_small;" >> create_postgres.js
echo "grant all privileges on database superdb_small to $(DB_USR_USER);" >> create_postgres.js
echo "grant usage on schema public to $(DB_USR_USER);" >> create_postgres.js
echo "grant select on all tables in schema public to $(DB_USR_USER);" >> create_postgres.js
echo "EOSQL" >> create_postgres.js
chmod +x create_postgres.js
mongo_create_roles:
echo 'db.auth("$(DB_ADM_USER)", "$(DB_ADM_PASS)")' > create_mongo.js
echo 'use valdb' >> create_mongo.js
echo 'db.createUser({user: "$(DB_USR_USER)", pwd: "$(DB_USR_PASS)", roles: ["readWrite"]})' >> create_mongo.js
echo 'db.grantRolesToUser("$(DB_USR_USER)", [{ role: "readWrite", db: "extvaldb"}])' >> create_mongo.js
build_mongo: mongo_create_roles
docker build . -t my-mongo --no-cache
2019-03-14 23:03:10 +00:00
2020-11-23 10:20:47 +00:00
# build_postgres: postgres_create_roles
# docker build . -t my-mongo --no-cache
2020-11-23 10:20:47 +00:00
run_docker_compose:
mkdir -p ${HOME}/valency_data/mongo_container/data/
#docker kill $(shell ./get_mongo_container_name.sh)
#docker kill $(shell ./get_postgres_container_name.sh)
#docker-compose stop
docker-compose -f valency-stack.yml up -d --force-recreate
# docker stack deploy --compose-file mongodb-stack.yml $(STACKNAME)
2020-11-23 10:20:47 +00:00
create_users: create_mongo_users create_postgres_users
2020-11-23 10:20:47 +00:00
create_mongo_users: mongo_create_roles
docker exec $(shell ./get_mongo_container_name.sh) /init_inside_mongo_container.sh
# rm create.js
2020-11-23 10:20:47 +00:00
create_postgres_users: postgres_create_roles
docker exec $(shell ./get_postgres_container_name.sh) /scripts/init_inside_postgres_container.sh
2020-11-23 10:20:47 +00:00
restore_db: restore_mongo_db restore_postgres_db
2019-03-14 18:49:01 +00:00
2020-11-23 10:20:47 +00:00
restore_mongo_db:
ifeq (,$(wildcard ./mongo_db.gz))
$(error "mongo_db.gz does not exists. Make sure to have dump of mongo db in 'dockerfiles/database/mongo_db.gz'")
else
docker exec $(shell ./get_mongo_container_name.sh) sh -c 'mongorestore --gzip --archive=/scripts/mongo_db.gz --db valdb --username $(DB_USR_USER) --password $(DB_USR_PASS) --authenticationDatabase valdb'
endif
2019-03-14 23:03:10 +00:00
2020-11-23 10:20:47 +00:00
restore_postgres_db:
ifeq (,$(wildcard ./postgres_db.tar))
$(error "postgres_db.tar does not exists. Make sure to have dump of postgres db in 'dockerfiles/database/postgres_db.tar'")
else
docker exec $(shell ./get_postgres_container_name.sh) sh -c 'pg_restore -U $(DB_ADM_USER) --dbname=superdb_small --create --verbose /scripts/postgres_db.tar'
endif