DOCKER_COMPOSE=docker compose -f docker-compose-local.yml
DOCKER_ALL_PROFILES=--profile docpress --profile tibi-dev --profile tibi --profile chisel

.DEFAULT_GOAL := help

.PHONY: docker-up docker-up-tibi-dev docker-up-chisel docker-up-docpress docker-start docker-start-tibi-dev docker-down docker-ps docker-logs docker-pull yarn-upgrade fix-permissions

include ./.env

help: ## show this help
	@echo MAKE TARGETS
	@grep -h -E '^[a-zA-Z_-]+:.*?## .*$$' $(MAKEFILE_LIST) | awk 'BEGIN {FS = ":.*?## "}; {printf "\033[36m%-30s\033[0m %s\n", $$1, $$2}'

docker-up: ## bring docker compose stack up in background
	$(DOCKER_COMPOSE) --profile tibi up -d

docker-up-tibi-dev: ## bring docker compose stack up in background with tibi-dev
	$(DOCKER_COMPOSE) --profile tibi-dev up -d

docker-up-chisel: ## bring up chisel tunnel
	$(DOCKER_COMPOSE) --profile chisel up -d

docker-down: ## take docker compose stack down
	$(DOCKER_COMPOSE) $(DOCKER_ALL_PROFILES) down

docker-start: ## start docker compose stack in foreground and take it down after CTRL-C
	$(DOCKER_COMPOSE) --profile tibi up; $(DOCKER_COMPOSE) $(DOCKER_ALL_PROFILES) down

docker-start-tibi-dev: ## start docker compose stack in foreground and take it down after CTRL-C (with tibi-dev)
	$(DOCKER_COMPOSE) --profile tibi-dev up; $(DOCKER_COMPOSE) $(DOCKER_ALL_PROFILES) down

docker-ps: ## show container state
	$(DOCKER_COMPOSE) $(DOCKER_ALL_PROFILES) ps

docker-logs: ## show docker logs and follow
	$(DOCKER_COMPOSE) $(DOCKER_ALL_PROFILES) logs -f || true

docker-pull: ## pull docker images
	$(DOCKER_COMPOSE) $(DOCKER_ALL_PROFILES) pull

docker-%:
	$(DOCKER_COMPOSE) $(DOCKER_ALL_PROFILES) $*

yarn-upgrade: # interactive yarn upgrade
	$(DOCKER_COMPOSE) run --rm yarnstart yarn upgrade-interactive
	$(DOCKER_COMPOSE) restart yarnstart

fix-permissions: # set files/directories owner to UID:GID from .env
	sudo chown -R $(UID):$(GID) ./
