Files
nextcloud/Makefile
T
2017-12-19 16:33:48 +01:00

56 lines
1.7 KiB
Makefile

CLIENT=tt-nextcloud
DOCKERCOMPOSE := $(shell command -v docker-compose 2> /dev/null)
USAGE := Usage: make ENV={prod|preprod|dev} {docker-build|docker-start|docker-stop|docker-restart}
ifndef DOCKERCOMPOSE
$(error docker-compose is not available)
endif
ifndef ENV
$(info Environment variable is not set)
$(info $(USAGE))
$(error Exiting)
endif
DC_OVERRIDE := $(shell test -e conf/docker-compose.override.yml && echo "--file conf/docker-compose.override.yml")
DC_OVERRIDE_ENV := $(shell test -e conf/docker-compose.$(ENV).yml && echo "--file conf/docker-compose.$(ENV).yml")
DC=ENV=$(ENV) CLIENT=$(CLIENT) $(DOCKERCOMPOSE) --project-name "$(CLIENT)_$(ENV)" --file conf/docker-compose.yml $(DC_OVERRIDE) $(DC_OVERRIDE_ENV)
default:
$(info $(USAGE))
$(error Exiting)
docker-build:
$(DC) build
$(DC) up -d
docker-start:
$(DC) start
docker-stop:
$(DC) stop
docker-restart: docker-stop docker-start
docker-rm: docker-stop
$(DC) rm
config:
@echo "Configuring docker for environment '$(ENV)'"
@echo " --> Generating mysql auth file"
@cat conf/env/nextcloud-mysql.env | python -c "import sys; import string; v=sys.stdin.readline().split('MYSQL_ROOT_PASSWORD=')[1]; print(string.Template(open('conf/build/mysql/my.cnf').read()).substitute({'PASSWORD':v}))" | docker exec -i $(CLIENT).nextcloud-mysql.$(ENV) sh -c 'cat > /root/.my.cnf'
db-backup:
@echo "Backing up database"
@mkdir -p backup/database/mysql
@docker exec --tty --interactive $(CLIENT).nextcloud-mysql.$(ENV) mysqldump -uroot database > backup/database/mysql/dump_`date +%d-%m-%Y"_"%H_%M_%S`.sql
db-restore:
@echo "Restoring db_restore.sql file to database"
@docker exec -i $(CLIENT).nextcloud-mysql.$(ENV) mysql -uroot database < database.sql