
CLIENT=tt-app

DOCKERCOMPOSE := $(shell command -v docker-compose 2> /dev/null)
USAGE := Usage: make ENV={prod|preprod|dev} {SYS=windows|linux}  {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

SYS=linux

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")

ifeq ($(SYS),linux)
DC=ENV=$(ENV) CLIENT=$(CLIENT) "$(DOCKERCOMPOSE)" --project-name "$(CLIENT)_$(ENV)" --file conf/docker-compose.yml $(DC_OVERRIDE) $(DC_OVERRIDE_ENV)
else
DC=ENV=$(ENV) CLIENT=$(CLIENT) "$(DOCKERCOMPOSE)" --project-name "$(CLIENT)_$(ENV)" --file conf/docker-compose.yml $(DC_OVERRIDE) $(DC_OVERRIDE_ENV)
endif


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

sys:
	@echo $(SYS)
	@echo $(DC)