PARTS := $(patsubst %/Makefile,%,$(wildcard */Makefile))
SERVICES := docker compose --profile services
EXTERNAL := docker compose --profile external

.PHONY: env external recreate rebuild restart logs down fmt check build

env:
	@test -f .env || cat .env.example $(addsuffix /.env.example,$(PARTS)) > .env

external:
	$(EXTERNAL) up -d

recreate: external
	$(SERVICES) up -d --force-recreate

rebuild: build recreate

restart:
	$(SERVICES) restart

logs:
	$(SERVICES) logs -f --tail=100

down:
	$(EXTERNAL) --profile services down

fmt check build:
	@for part in $(PARTS); do $(MAKE) -C $$part $@ || exit 1; done
