.PHONY: up
up:	## Start all the services
	docker-compose up -d --remove-orphans

.PHONY: start
start: up install-deps 	## Start openpod application
	docker-compose exec open-pod iex -S mix phx.server

.PHONY: install-deps
install-deps: container/open-pod	## Install open-pod dependencies
	docker-compose exec open-pod mix deps.get

.PHONY: stop
stop:	## Shoutdown services
	docker-compose down -v

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

container/%:
	@docker ps -q --no-trunc --filter status=running | grep $$(docker-compose ps -q $*) >/dev/null 2>&1 || docker-compose up -d $*

.PHONY: build
build: check-version
	@docker build -t openpod/open-pod:latest .
	@docker push openpod/open-pod:latest
	@docker build -t openpod/open-pod:${VERSION} .

.PHONY: publish
publish: check-version
	@docker push openpod/open-pod:${VERSION}

.PHONY: build-publish
build-publish: check-version build publish

check-version:
ifndef VERSION
	$(error VERSION is undefined)
endif
