.PHONY = build-git-tag, build, test, test-api, test-ui, test-style, demo, stop

# Creates a git tag to track the version of the API used.
build-git-tag:
	scripts/gen_git_info.sh

# Build the API image
build: build-git-tag
	docker build \
		--pull \
		--cache-from=dorianpula/rookeries:latest \
		--tag dorianpula/rookeries:latest .

# Runs all the tests
test: build test-style test-api test-ui

# Run code linter tests
test-style: stop build
	docker-compose run --no-deps rookeries \
		inv test.lint

# Runs API tests
test-api: stop build
	docker-compose up -d db rookeries
	docker-compose exec rookeries \
		inv db.wait db.init db.sample_site
	docker-compose exec rookeries \
		inv server.wait --timeout 100
	docker-compose exec rookeries \
		inv test.server --verbosity=1

# Runs UI tests
test-ui: stop build
	docker-compose run --no-deps rookeries \
		inv test.js
	docker-compose up -d
	docker-compose exec rookeries \
		inv db.wait
	docker-compose exec rookeries \
		inv server.wait --timeout 100
	docker-compose exec rookeries \
		inv test.ui --server-host=rookeries:5000 --verbosity=1

# Demos Rookeries in a browser
demo: build
	docker-compose up -d --remove-orphans
	python -m webbrowser -n http://localhost:5000/

# Shuts down Rookeries
stop:
	docker-compose down --remove-orphans --volumes
