#!/usr/bin/make

SHELL = /bin/sh

USER_UID := $(shell id -u)
USER_UNAME := $(shell id -un)
USER_GID := $(shell id -g)
USER_GNAME := $(shell id -gn)

DATE_NOW := $(shell date '+%Y-%m-%d_%H%M%S')

export USER_UID
export USER_UNAME
export USER_GID
export USER_GNAME

build:
		docker-compose build --build-arg USER_UID=$(USER_UID) --build-arg USER_UNAME=$(USER_UNAME) --build-arg USER_GID=$(USER_GID) --build-arg USER_GNAME=$(USER_GNAME)

buildnc:
		docker-compose build --no-cache --build-arg USER_UID=$(USER_UID) --build-arg USER_UNAME=$(USER_UNAME) --build-arg USER_GID=$(USER_GID) --build-arg USER_GNAME=$(USER_GNAME)

buildsolrnc:
		docker-compose build --no-cache --build-arg USER_UID=$(USER_UID) --build-arg USER_UNAME=$(USER_UNAME) --build-arg USER_GID=$(USER_GID) --build-arg USER_GNAME=$(USER_GNAME) solr-new

buildphp:
		docker-compose build --build-arg USER_UID=$(USER_UID) --build-arg USER_UNAME=$(USER_UNAME) --build-arg USER_GID=$(USER_GID) --build-arg USER_GNAME=$(USER_GNAME) php

buildphpnc:
		docker-compose build --no-cache --build-arg USER_UID=$(USER_UID) --build-arg USER_UNAME=$(USER_UNAME) --build-arg USER_GID=$(USER_GID) --build-arg USER_GNAME=$(USER_GNAME) php

buildnginx:
		docker-compose build --build-arg USER_UID=$(USER_UID) --build-arg USER_UNAME=$(USER_UNAME) --build-arg USER_GID=$(USER_GID) --build-arg USER_GNAME=$(USER_GNAME) nginx

buildnginxnc:
		docker-compose build --no-cache --build-arg USER_UID=$(USER_UID) --build-arg USER_UNAME=$(USER_UNAME) --build-arg USER_GID=$(USER_GID) --build-arg USER_GNAME=$(USER_GNAME) nginx

buildnpm:
		docker-compose build --build-arg USER_UID=$(USER_UID) --build-arg USER_UNAME=$(USER_UNAME) --build-arg USER_GID=$(USER_GID) --build-arg USER_GNAME=$(USER_GNAME) npm

buildnpmnc:
		docker-compose build --no-cache --build-arg USER_UID=$(USER_UID) --build-arg USER_UNAME=$(USER_UNAME) --build-arg USER_GID=$(USER_GID) --build-arg USER_GNAME=$(USER_GNAME) npm

buildmysql:
		docker-compose build --build-arg USER_UID=$(USER_UID) --build-arg USER_UNAME=$(USER_UNAME) --build-arg USER_GID=$(USER_GID) --build-arg USER_GNAME=$(USER_GNAME) mysql

buildmysqlnc:
		docker-compose build --no-cache --build-arg USER_UID=$(USER_UID) --build-arg USER_UNAME=$(USER_UNAME) --build-arg USER_GID=$(USER_GID) --build-arg USER_GNAME=$(USER_GNAME) mysql


up:
		docker-compose up -d

upbuild:
		docker-compose up -d --build

ps:
		docker-compose ps

logs:
		docker-compose logs -f

logs_redis:
		docker-compose logs -f redis

down:
		docker-compose down

restart_solr:
		docker-compose restart solr-new

restart_redis:
		docker-compose restart redis

restart_php:
		docker-compose restart php

restart_npm	:
		docker-compose restart npm

restart_mysql	:
		docker-compose restart mysql

exec_php:
		docker exec -it materiod8-php-1 bash

exec_nginx:
		docker exec -it materiod8-nginx-1 bash

exec_npm:
		docker exec -it materiod8-npm-1 sh

exec_mysql:
		docker exec -it materiod8-mysql-1 bash

exec_solr:
		docker exec -it materiod8-solr-new-1 bash

exec_solrlegacy:
		docker exec -it materiod8-solr-legacy-1 bash

phplegacy:
		docker exec -it materiod8-php-legacy-1 bash

redis:
		docker exec -it materiod8-redis-1 bash

update_solr_conf:
		bin/update_solr_config.sh

dump_d8_db:
	docker exec materiod8-mysql-1 sh -c 'exec mysqldump -uroot -pmaterio materio_d8' > ./ressources/materio-d8-$(DATE_NOW)-local.sql

sish:
	ssh -p 2222 -R materio:80:dev:8890 CT-sish.me