forked from kristjan/cjvt-valency
Makefile changes and added options
This commit is contained in:
@@ -1,5 +1,5 @@
|
||||
FROM mongo:4.2.9
|
||||
|
||||
WORKDIR /
|
||||
COPY init_inside_container.sh /.
|
||||
COPY create.js /.
|
||||
COPY init_inside_mongo_container.sh /.
|
||||
COPY create_mongo.js /.
|
||||
|
||||
@@ -2,33 +2,62 @@
|
||||
# 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
|
||||
build_run: build_mongo run_docker_compose
|
||||
|
||||
create.js: FORCE
|
||||
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
|
||||
|
||||
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
|
||||
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: create.js
|
||||
build_mongo: mongo_create_roles
|
||||
docker build . -t my-mongo --no-cache
|
||||
|
||||
clean_stack:
|
||||
docker stack rm $(STACKNAME)
|
||||
# build_postgres: postgres_create_roles
|
||||
# docker build . -t my-mongo --no-cache
|
||||
|
||||
run_stack:
|
||||
mkdir -p ${HOME}/mongo_container/data/
|
||||
docker stack deploy --compose-file mongodb-stack.yml $(STACKNAME)
|
||||
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)
|
||||
|
||||
create_users: create.js
|
||||
docker exec $(shell ./get_container_name.sh) /init_inside_container.sh
|
||||
create_users: create_mongo_users create_postgres_users
|
||||
|
||||
|
||||
create_mongo_users: mongo_create_roles
|
||||
docker exec $(shell ./get_mongo_container_name.sh) /init_inside_mongo_container.sh
|
||||
# rm create.js
|
||||
|
||||
create_postgres_users: postgres_create_roles
|
||||
docker exec $(shell ./get_postgres_container_name.sh) /scripts/init_inside_postgres_container.sh
|
||||
|
||||
restore_db: restore_mongo_db restore_postgres_db
|
||||
|
||||
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
|
||||
|
||||
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
|
||||
|
||||
2
dockerfiles/database/get_postgres_container_name.sh
Executable file
2
dockerfiles/database/get_postgres_container_name.sh
Executable file
@@ -0,0 +1,2 @@
|
||||
#!/bin/bash
|
||||
docker ps | grep postgres | awk '{print $1}'
|
||||
@@ -1,3 +0,0 @@
|
||||
#!/bin/bash
|
||||
|
||||
mongo admin < /create.js
|
||||
3
dockerfiles/database/init_inside_mongo_container.sh
Executable file
3
dockerfiles/database/init_inside_mongo_container.sh
Executable file
@@ -0,0 +1,3 @@
|
||||
#!/bin/bash
|
||||
|
||||
mongo admin < /create_mongo.js
|
||||
3
dockerfiles/database/init_inside_postgres_container.sh
Executable file
3
dockerfiles/database/init_inside_postgres_container.sh
Executable file
@@ -0,0 +1,3 @@
|
||||
#!/bin/bash
|
||||
|
||||
/scripts/create_postgres.js
|
||||
@@ -1,26 +0,0 @@
|
||||
version: '3.1'
|
||||
|
||||
services:
|
||||
|
||||
my_mongo:
|
||||
image: my-mongo
|
||||
restart: always
|
||||
ports:
|
||||
- 27017:27017
|
||||
environment:
|
||||
MONGO_INITDB_ROOT_USERNAME: ${DB_ADM_USER}
|
||||
MONGO_INITDB_ROOT_PASSWORD: ${DB_ADM_PASS}
|
||||
volumes:
|
||||
- ${HOME}/mongo_container/data/:/data/db
|
||||
|
||||
mongo_express:
|
||||
image: mongo-express
|
||||
restart: always
|
||||
ports:
|
||||
- 8087:8081
|
||||
environment:
|
||||
ME_CONFIG_BASICAUTH_USERNAME: ${MONGOEXPRESS_USER}
|
||||
ME_CONFIG_BASICAUTH_PASSWORD: ${MONGOEXPRESS_PASS}
|
||||
ME_CONFIG_MONGODB_ADMINUSERNAME: ${DB_ADM_USER}
|
||||
ME_CONFIG_MONGODB_ADMINPASSWORD: ${DB_ADM_PASS}
|
||||
ME_CONFIG_MONGODB_SERVER: my_mongo
|
||||
27
dockerfiles/database/valency-stack.yml
Normal file
27
dockerfiles/database/valency-stack.yml
Normal file
@@ -0,0 +1,27 @@
|
||||
version: '3.1'
|
||||
|
||||
services:
|
||||
|
||||
my_mongo:
|
||||
image: my-mongo
|
||||
restart: always
|
||||
ports:
|
||||
- 127.0.0.1:27017:27017
|
||||
environment:
|
||||
MONGO_INITDB_ROOT_USERNAME: ${DB_ADM_USER}
|
||||
MONGO_INITDB_ROOT_PASSWORD: ${DB_ADM_PASS}
|
||||
volumes:
|
||||
- ${HOME}/valency_data/mongo_container/data/:/data/db
|
||||
- ./:/scripts
|
||||
|
||||
my_postgres:
|
||||
image: postgres
|
||||
restart: always
|
||||
ports:
|
||||
- 127.0.0.1:5432:5432
|
||||
environment:
|
||||
POSTGRES_USER: ${DB_ADM_USER}
|
||||
POSTGRES_PASSWORD: ${DB_ADM_PASS}
|
||||
volumes:
|
||||
- ${HOME}/valency_data/postgres_container/data/:/var/lib/postgresql/data
|
||||
- ./:/scripts
|
||||
Reference in New Issue
Block a user